emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Disable typo-mode in org source code blocks
@ 2019-09-02  7:01 garjola
  2019-09-02  8:02 ` Fraga, Eric
  0 siblings, 1 reply; 7+ messages in thread
From: garjola @ 2019-09-02  7:01 UTC (permalink / raw)
  To: emacs-orgmode@gnu.org

Hi,

I am using typo-mode (https://github.com/jorgenschaefer/typoel) in my
org buffers (actually with a hook for text-mode), but I would like to
disable it in source code blocks.

I have been unable to find a hook to do so (I understand that
org-src-mode-hook is used when editing with ‘C-c '’ but not in the org
buffer).

Can you help me with this?

Thanks.

G.
-- 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Disable typo-mode in org source code blocks
  2019-09-02  7:01 Disable typo-mode in org source code blocks garjola
@ 2019-09-02  8:02 ` Fraga, Eric
  2019-09-02  8:35   ` Tim Cross
  0 siblings, 1 reply; 7+ messages in thread
From: Fraga, Eric @ 2019-09-02  8:02 UTC (permalink / raw)
  To: garjola@garjola.net; +Cc: emacs-orgmode@gnu.org

On Monday,  2 Sep 2019 at 09:01, garjola@garjola.net wrote:
> I am using typo-mode (https://github.com/jorgenschaefer/typoel) in my
> org buffers (actually with a hook for text-mode), but I would like to
> disable it in source code blocks.
>
> I have been unable to find a hook to do so (I understand that
> org-src-mode-hook is used when editing with ‘C-c '’ but not in the org
> buffer).

I am not entirely sure what you want here.  If it is that you want to
turn off typo-mode when point moves into a src block but while still in
the whole org buffer, then you cannot do this AFAIK.  The best approach
is to always edit src blocks using C-c ' (org-edit-special) and then you
can use org-src-mode-hook to do what you want.

-- 
Eric S Fraga via Emacs 27.0.50, Org release_9.2.4-401-gfabd6d

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Disable typo-mode in org source code blocks
  2019-09-02  8:02 ` Fraga, Eric
@ 2019-09-02  8:35   ` Tim Cross
  2019-09-02 12:21     ` garjola
  0 siblings, 1 reply; 7+ messages in thread
From: Tim Cross @ 2019-09-02  8:35 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: garjola@garjola.net


I think Eric is correct. There is also another reason. If you edit the
source blocks with C-', then any escaping needed (such as putting a ','
before '*') will also be automatically handled, plus of course you get
all the programing mode goodness.

Fraga, Eric <e.fraga@ucl.ac.uk> writes:

> On Monday,  2 Sep 2019 at 09:01, garjola@garjola.net wrote:
>> I am using typo-mode (https://github.com/jorgenschaefer/typoel) in my
>> org buffers (actually with a hook for text-mode), but I would like to
>> disable it in source code blocks.
>>
>> I have been unable to find a hook to do so (I understand that
>> org-src-mode-hook is used when editing with ‘C-c '’ but not in the org
>> buffer).
>
> I am not entirely sure what you want here.  If it is that you want to
> turn off typo-mode when point moves into a src block but while still in
> the whole org buffer, then you cannot do this AFAIK.  The best approach
> is to always edit src blocks using C-c ' (org-edit-special) and then you
> can use org-src-mode-hook to do what you want.


-- 
Tim Cross

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Disable typo-mode in org source code blocks
  2019-09-02  8:35   ` Tim Cross
@ 2019-09-02 12:21     ` garjola
  2019-09-02 18:26       ` John Kitchin
  0 siblings, 1 reply; 7+ messages in thread
From: garjola @ 2019-09-02 12:21 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: Tim Cross

On Mon 02-Sep-2019 at 10:35:02 +02, Tim Cross <theophilusx@gmail.com>
wrote: 
> I think Eric is correct. There is also another reason. If you edit the
> source blocks with C-', then any escaping needed (such as putting a ','
> before '*') will also be automatically handled, plus of course you get
> all the programing mode goodness.
>
> Fraga, Eric <e.fraga@ucl.ac.uk> writes:
>
>> On Monday,  2 Sep 2019 at 09:01, garjola@garjola.net wrote:
>>> I am using typo-mode (https://github.com/jorgenschaefer/typoel) in my
>>> org buffers (actually with a hook for text-mode), but I would like to
>>> disable it in source code blocks.
>>>
>>> I have been unable to find a hook to do so (I understand that
>>> org-src-mode-hook is used when editing with ‘C-c '’ but not in the org
>>> buffer).
>>
>> I am not entirely sure what you want here.  If it is that you want to
>> turn off typo-mode when point moves into a src block but while still in
>> the whole org buffer, then you cannot do this AFAIK.  The best approach
>> is to always edit src blocks using C-c ' (org-edit-special) and then you
>> can use org-src-mode-hook to do what you want.

Thanks to both of you. I usually edit in the separate buffer, but I
don’t for one liners. It’s a pity that this is not possible, but I can
live with that!

Thanks again!
-- 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Disable typo-mode in org source code blocks
  2019-09-02 12:21     ` garjola
@ 2019-09-02 18:26       ` John Kitchin
  2019-09-03  0:13         ` Tim Cross
  2019-09-03  6:16         ` garjola
  0 siblings, 2 replies; 7+ messages in thread
From: John Kitchin @ 2019-09-02 18:26 UTC (permalink / raw)
  To: garjola; +Cc: Tim Cross, org-mode-email

[-- Attachment #1: Type: text/plain, Size: 3968 bytes --]

You can use cursor-sensor mode for this if you have emacs 26ish. The idea
is you set cursor-sensor functions on a region that do something depending
on whether you enter or leave the region. Below, I tie into the org font
lock mechanisms to add these properties so that when you enter, typo mode
gets turned off, and when you leave it gets turned back on. I use a similar
approach to put src-block specific key maps on src blocks. There are two
examples of functions that are "lightly tested". I can see why you would
want this disabled in src blocks, it never puts the right quote in!

(defvar scimax-src-block-cursor-sensor-functions '()
  "List of functions to run in cursor-sensor mode. .")


(defun scimax-add-cursor-sensor-functions-to-src-blocks (limit)
  "Function used in font-lock to add cursor-sensor functions."
  (let ((case-fold-search t))
    (while (re-search-forward org-babel-src-block-regexp limit t)
      (let* ((beg (match-beginning 0))
    (end (match-end 0))
    (cursor-functions (or
(get-text-property beg 'cursor-sensor-functions)
`())))
(cl-loop for func in scimax-src-block-cursor-sensor-functions do
(when (not (memq func cursor-functions))
  (pushnew func cursor-functions)))
(add-text-properties
beg end `(cursor-sensor-functions ,cursor-functions))))))


(define-minor-mode scimax-cursor-sensor-mode
  "Minor mode to turn on cursor-sensor-mode for org src-blocks."
  :init-value nil
  (if scimax-cursor-sensor-mode
      (progn
(add-hook 'org-font-lock-hook
 #'scimax-add-cursor-sensor-functions-to-src-blocks t)
(add-to-list 'font-lock-extra-managed-props 'cursor-sensor-functions)
(cursor-sensor-mode +1))
    (remove-hook 'org-font-lock-hook
#'scimax-add-cursor-sensor-functions-to-src-blocks)

    (cursor-sensor-mode -1))
  (font-lock-fontify-buffer))

(defun scimax-cs-message-1 (win prev-pos sym)
  (message "%s %s %s"
  win
  prev-pos
  sym))

(defun scimax-src-toggle-typo-mode (win prev-pos sym)
  (if (eq sym 'entered)
      (typo-mode -1)
    (typo-mode +1)))


(add-to-list 'scimax-src-block-cursor-sensor-functions
    'scimax-cs-message-1)

(add-to-list 'scimax-src-block-cursor-sensor-functions
    'scimax-src-toggle-typo-mode)




John

-----------------------------------
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu



On Mon, Sep 2, 2019 at 8:21 AM <garjola@garjola.net> wrote:

> On Mon 02-Sep-2019 at 10:35:02 +02, Tim Cross <theophilusx@gmail.com>
> wrote:
> > I think Eric is correct. There is also another reason. If you edit the
> > source blocks with C-', then any escaping needed (such as putting a ','
> > before '*') will also be automatically handled, plus of course you get
> > all the programing mode goodness.
> >
> > Fraga, Eric <e.fraga@ucl.ac.uk> writes:
> >
> >> On Monday,  2 Sep 2019 at 09:01, garjola@garjola.net wrote:
> >>> I am using typo-mode (https://github.com/jorgenschaefer/typoel) in my
> >>> org buffers (actually with a hook for text-mode), but I would like to
> >>> disable it in source code blocks.
> >>>
> >>> I have been unable to find a hook to do so (I understand that
> >>> org-src-mode-hook is used when editing with ‘C-c '’ but not in the org
> >>> buffer).
> >>
> >> I am not entirely sure what you want here.  If it is that you want to
> >> turn off typo-mode when point moves into a src block but while still in
> >> the whole org buffer, then you cannot do this AFAIK.  The best approach
> >> is to always edit src blocks using C-c ' (org-edit-special) and then you
> >> can use org-src-mode-hook to do what you want.
>
> Thanks to both of you. I usually edit in the separate buffer, but I
> don’t for one liners. It’s a pity that this is not possible, but I can
> live with that!
>
> Thanks again!
> --
>
>

[-- Attachment #2: Type: text/html, Size: 5355 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Disable typo-mode in org source code blocks
  2019-09-02 18:26       ` John Kitchin
@ 2019-09-03  0:13         ` Tim Cross
  2019-09-03  6:16         ` garjola
  1 sibling, 0 replies; 7+ messages in thread
From: Tim Cross @ 2019-09-03  0:13 UTC (permalink / raw)
  To: John Kitchin; +Cc: garjola, org-mode-email

Hi John,

this is a greet bit of info.

My first thought when the question was asked was "Hmm, what you need is
some sort of facility that could run a function when the cursor moves in
and out of a region". I then discounted the idea because of the amount
of supporting functionality which would need to be developed.  The
pointer to cursor-sensor sounds like exactly the supporting
functionality I was thinking of. Should have guessed Emacs would have
something already!

Using org's font-lock mechanism as the 'trigger' is a great idea too.

I can see some great uses for this package as I have some pretty ugly
hacks which could be simplified if cursor-sensor works reliably.

thanks for the pointer.

Tim


John Kitchin <jkitchin@andrew.cmu.edu> writes:

> You can use cursor-sensor mode for this if you have emacs 26ish. The idea
> is you set cursor-sensor functions on a region that do something depending
> on whether you enter or leave the region. Below, I tie into the org font
> lock mechanisms to add these properties so that when you enter, typo mode
> gets turned off, and when you leave it gets turned back on. I use a similar
> approach to put src-block specific key maps on src blocks. There are two
> examples of functions that are "lightly tested". I can see why you would
> want this disabled in src blocks, it never puts the right quote in!
>
> (defvar scimax-src-block-cursor-sensor-functions '()
>   "List of functions to run in cursor-sensor mode. .")
>
>
> (defun scimax-add-cursor-sensor-functions-to-src-blocks (limit)
>   "Function used in font-lock to add cursor-sensor functions."
>   (let ((case-fold-search t))
>     (while (re-search-forward org-babel-src-block-regexp limit t)
>       (let* ((beg (match-beginning 0))
>     (end (match-end 0))
>     (cursor-functions (or
> (get-text-property beg 'cursor-sensor-functions)
> `())))
> (cl-loop for func in scimax-src-block-cursor-sensor-functions do
> (when (not (memq func cursor-functions))
>   (pushnew func cursor-functions)))
> (add-text-properties
> beg end `(cursor-sensor-functions ,cursor-functions))))))
>
>
> (define-minor-mode scimax-cursor-sensor-mode
>   "Minor mode to turn on cursor-sensor-mode for org src-blocks."
>   :init-value nil
>   (if scimax-cursor-sensor-mode
>       (progn
> (add-hook 'org-font-lock-hook
>  #'scimax-add-cursor-sensor-functions-to-src-blocks t)
> (add-to-list 'font-lock-extra-managed-props 'cursor-sensor-functions)
> (cursor-sensor-mode +1))
>     (remove-hook 'org-font-lock-hook
> #'scimax-add-cursor-sensor-functions-to-src-blocks)
>
>     (cursor-sensor-mode -1))
>   (font-lock-fontify-buffer))
>
> (defun scimax-cs-message-1 (win prev-pos sym)
>   (message "%s %s %s"
>   win
>   prev-pos
>   sym))
>
> (defun scimax-src-toggle-typo-mode (win prev-pos sym)
>   (if (eq sym 'entered)
>       (typo-mode -1)
>     (typo-mode +1)))
>
>
> (add-to-list 'scimax-src-block-cursor-sensor-functions
>     'scimax-cs-message-1)
>
> (add-to-list 'scimax-src-block-cursor-sensor-functions
>     'scimax-src-toggle-typo-mode)
>
>
>
>
> John
>
> -----------------------------------
> Professor John Kitchin
> Doherty Hall A207F
> Department of Chemical Engineering
> Carnegie Mellon University
> Pittsburgh, PA 15213
> 412-268-7803
> @johnkitchin
> http://kitchingroup.cheme.cmu.edu
>
>
>
> On Mon, Sep 2, 2019 at 8:21 AM <garjola@garjola.net> wrote:
>
>> On Mon 02-Sep-2019 at 10:35:02 +02, Tim Cross <theophilusx@gmail.com>
>> wrote:
>> > I think Eric is correct. There is also another reason. If you edit the
>> > source blocks with C-', then any escaping needed (such as putting a ','
>> > before '*') will also be automatically handled, plus of course you get
>> > all the programing mode goodness.
>> >
>> > Fraga, Eric <e.fraga@ucl.ac.uk> writes:
>> >
>> >> On Monday,  2 Sep 2019 at 09:01, garjola@garjola.net wrote:
>> >>> I am using typo-mode (https://github.com/jorgenschaefer/typoel) in my
>> >>> org buffers (actually with a hook for text-mode), but I would like to
>> >>> disable it in source code blocks.
>> >>>
>> >>> I have been unable to find a hook to do so (I understand that
>> >>> org-src-mode-hook is used when editing with ‘C-c '’ but not in the org
>> >>> buffer).
>> >>
>> >> I am not entirely sure what you want here.  If it is that you want to
>> >> turn off typo-mode when point moves into a src block but while still in
>> >> the whole org buffer, then you cannot do this AFAIK.  The best approach
>> >> is to always edit src blocks using C-c ' (org-edit-special) and then you
>> >> can use org-src-mode-hook to do what you want.
>>
>> Thanks to both of you. I usually edit in the separate buffer, but I
>> don’t for one liners. It’s a pity that this is not possible, but I can
>> live with that!
>>
>> Thanks again!
>> --
>>
>>


--
Tim Cross

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Disable typo-mode in org source code blocks
  2019-09-02 18:26       ` John Kitchin
  2019-09-03  0:13         ` Tim Cross
@ 2019-09-03  6:16         ` garjola
  1 sibling, 0 replies; 7+ messages in thread
From: garjola @ 2019-09-03  6:16 UTC (permalink / raw)
  To: John Kitchin; +Cc: org-mode-email

On Mon 02-Sep-2019 at 20:26:22 +02, John Kitchin
<jkitchin@andrew.cmu.edu> wrote: 
> You can use cursor-sensor mode for this if you have emacs 26ish. The idea is you set cursor-sensor functions on a region that do something depending on whether you enter or leave the region. Below, I tie into
> the org font lock mechanisms to add these properties so that when you enter, typo mode gets turned off, and when you leave it gets turned back on. I use a similar approach to put src-block specific key maps
> on src blocks. There are two examples of functions that are "lightly tested". I can see why you would want this disabled in src blocks, it never puts the right quote in! 
>

[…]

Hi,

Thanks for this! I will have to spend some time before I understand
everything, but this is of great help.
-- 

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-09-03  6:16 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-02  7:01 Disable typo-mode in org source code blocks garjola
2019-09-02  8:02 ` Fraga, Eric
2019-09-02  8:35   ` Tim Cross
2019-09-02 12:21     ` garjola
2019-09-02 18:26       ` John Kitchin
2019-09-03  0:13         ` Tim Cross
2019-09-03  6:16         ` garjola

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).