emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Context sensitive M-q
@ 2010-09-07 18:34 Thomas S. Dye
  2010-09-07 19:11 ` Dan Davison
  0 siblings, 1 reply; 6+ messages in thread
From: Thomas S. Dye @ 2010-09-07 18:34 UTC (permalink / raw)
  To: emacs-orgmode Mailinglist

Aloha all,

I can't break myself of the M-q habit and often call fill-paragraph  
inside a source code block while the buffer is in Org-mode.   
Typically, this rearranges the source code in an undesirable way.  Is  
there some way (other than breaking the M-q habit) that I can protect  
source code blocks from Org-mode's fill-paragraph?

All the best,
Tom 

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

* Re: Context sensitive M-q
  2010-09-07 18:34 Context sensitive M-q Thomas S. Dye
@ 2010-09-07 19:11 ` Dan Davison
  2010-09-07 19:30   ` org-babel-where-is-src-block-head Jambunathan K
  2010-09-07 20:28   ` Context sensitive M-q Thomas S. Dye
  0 siblings, 2 replies; 6+ messages in thread
From: Dan Davison @ 2010-09-07 19:11 UTC (permalink / raw)
  To: Thomas S. Dye; +Cc: emacs-orgmode Mailinglist

"Thomas S. Dye" <tsd@tsdye.com> writes:

> Aloha all,
>
> I can't break myself of the M-q habit and often call fill-paragraph
> inside a source code block while the buffer is in Org-mode.
> Typically, this rearranges the source code in an undesirable way.  Is
> there some way (other than breaking the M-q habit) that I can protect
> source code blocks from Org-mode's fill-paragraph?

Hi Tom,

Two quick hacks[1] below. It seems that some major modes (e.g. C) use
M-q for something sensible, whereas others (e.g. R) don't. I'm also an
M-q addict, but I guess I don't use it much in language major modes, so
I'll try using (1). With (2), you have to be happy with the (invisible)
excursion to the edit buffer and back, and any consequent changes to
your indentation, etc.

1. Do nothing on M-q in code block
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  (defun dan/org-fill-paragraph-no-op-maybe ()
    (interactive)
    (if (org-babel-where-is-src-block-head)
        (message "In code block: doing nothing")
      (call-interactively 'fill-paragraph)))
  
  (define-key org-mode-map "\M-q" 'dan/org-fill-paragraph-no-op-maybe)

2. Call native M-q
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  (defun dan/org-fill-paragraph-natively-maybe ()
    (interactive)
    (or (org-babel-do-key-sequence-in-edit-buffer "\M-q")
      (call-interactively 'fill-paragraph)))
  
  (define-key org-mode-map "\M-q" 'dan/org-fill-paragraph-natively-maybe)


Dan

Footnotes:

[1] E.g. `org-babel-where-is-src-block-head' may not be the "proper" way
    to detect if we're in a src block.



>
> All the best,
> Tom
>
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

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

* org-babel-where-is-src-block-head
  2010-09-07 19:11 ` Dan Davison
@ 2010-09-07 19:30   ` Jambunathan K
  2010-09-07 20:40     ` org-babel-where-is-src-block-head Nicolas Goaziou
  2010-09-07 20:46     ` org-babel-where-is-src-block-head Dan Davison
  2010-09-07 20:28   ` Context sensitive M-q Thomas S. Dye
  1 sibling, 2 replies; 6+ messages in thread
From: Jambunathan K @ 2010-09-07 19:30 UTC (permalink / raw)
  To: Dan Davison; +Cc: emacs-orgmode Mailinglist


> [1] E.g. `org-babel-where-is-src-block-head' may not be the "proper" way
>     to detect if we're in a src block.
>

I wonder what the proper way is ...

At different points in the past, I had looked for org-at-babel-p or
something similar. I invariably wound up using
org-babel-where-is-src-block-head ...

Jambunathan K.

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

* Re: Context sensitive M-q
  2010-09-07 19:11 ` Dan Davison
  2010-09-07 19:30   ` org-babel-where-is-src-block-head Jambunathan K
@ 2010-09-07 20:28   ` Thomas S. Dye
  1 sibling, 0 replies; 6+ messages in thread
From: Thomas S. Dye @ 2010-09-07 20:28 UTC (permalink / raw)
  To: Dan Davison; +Cc: emacs-orgmode Mailinglist

Thanks Dan,

Quick hack 2 does exactly what I want for the simple and (for me)  
frequent use case of issuing M-q in a source block while in Org-mode.

I think it might be useful to have this functionality in Org-mode, if  
it could be implemented without too much difficulty.

All the best,
Tom

On Sep 7, 2010, at 9:11 AM, Dan Davison wrote:

> "Thomas S. Dye" <tsd@tsdye.com> writes:
>
>> Aloha all,
>>
>> I can't break myself of the M-q habit and often call fill-paragraph
>> inside a source code block while the buffer is in Org-mode.
>> Typically, this rearranges the source code in an undesirable way.  Is
>> there some way (other than breaking the M-q habit) that I can protect
>> source code blocks from Org-mode's fill-paragraph?
>
> Hi Tom,
>
> Two quick hacks[1] below. It seems that some major modes (e.g. C) use
> M-q for something sensible, whereas others (e.g. R) don't. I'm also an
> M-q addict, but I guess I don't use it much in language major modes,  
> so
> I'll try using (1). With (2), you have to be happy with the  
> (invisible)
> excursion to the edit buffer and back, and any consequent changes to
> your indentation, etc.
>
> 1. Do nothing on M-q in code block
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
>  (defun dan/org-fill-paragraph-no-op-maybe ()
>    (interactive)
>    (if (org-babel-where-is-src-block-head)
>        (message "In code block: doing nothing")
>      (call-interactively 'fill-paragraph)))
>
>  (define-key org-mode-map "\M-q" 'dan/org-fill-paragraph-no-op-maybe)
>
> 2. Call native M-q
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>  (defun dan/org-fill-paragraph-natively-maybe ()
>    (interactive)
>    (or (org-babel-do-key-sequence-in-edit-buffer "\M-q")
>      (call-interactively 'fill-paragraph)))
>
>  (define-key org-mode-map "\M-q" 'dan/org-fill-paragraph-natively- 
> maybe)
>
>
> Dan
>
> Footnotes:
>
> [1] E.g. `org-babel-where-is-src-block-head' may not be the "proper"  
> way
>    to detect if we're in a src block.
>
>
>
>>
>> All the best,
>> Tom
>>
>> _______________________________________________
>> Emacs-orgmode mailing list
>> Please use `Reply All' to send replies to the list.
>> Emacs-orgmode@gnu.org
>> http://lists.gnu.org/mailman/listinfo/emacs-orgmode
>

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

* Re: org-babel-where-is-src-block-head
  2010-09-07 19:30   ` org-babel-where-is-src-block-head Jambunathan K
@ 2010-09-07 20:40     ` Nicolas Goaziou
  2010-09-07 20:46     ` org-babel-where-is-src-block-head Dan Davison
  1 sibling, 0 replies; 6+ messages in thread
From: Nicolas Goaziou @ 2010-09-07 20:40 UTC (permalink / raw)
  To: Jambunathan K; +Cc: Dan Davison, emacs-orgmode Mailinglist

Hello,

>>>>> Jambunathan K writes:

>> [1] E.g. `org-babel-where-is-src-block-head' may not be the
>> "proper" way to detect if we're in a src block.
>> 

> I wonder what the proper way is ...

> At different points in the past, I had looked for org-at-babel-p or
> something similar. I invariably wound up using
> org-babel-where-is-src-block-head ...

I don't know it either but there is `org-in-regexps-block-p' for
general use, and in org-list, I used something in the lines of this:

(defun in-src-block-p ()
  (save-excursion
    (let ((case-fold-search t))
      (end-of-line)
      (and (re-search-backward "^[ \t]*#\\+\\(begin\\|end\\)_src" nil t)
           (= (length (match-string 1)) 5)))))

Regards,
           
-- Nicolas

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

* Re: org-babel-where-is-src-block-head
  2010-09-07 19:30   ` org-babel-where-is-src-block-head Jambunathan K
  2010-09-07 20:40     ` org-babel-where-is-src-block-head Nicolas Goaziou
@ 2010-09-07 20:46     ` Dan Davison
  1 sibling, 0 replies; 6+ messages in thread
From: Dan Davison @ 2010-09-07 20:46 UTC (permalink / raw)
  To: Jambunathan K; +Cc: emacs-orgmode Mailinglist

Jambunathan K <kjambunathan@gmail.com> writes:

>> [1] E.g. `org-babel-where-is-src-block-head' may not be the "proper" way
>>     to detect if we're in a src block.
>>
>
> I wonder what the proper way is ...
>
> At different points in the past, I had looked for org-at-babel-p or
> something similar. I invariably wound up using
> org-babel-where-is-src-block-head ...

I notice Carsten has the utility function `org-in-regexps-block-p'. I
don't think it is used in babel so far.

Dan



>
> Jambunathan K.
>
>
>
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

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

end of thread, other threads:[~2010-09-07 20:46 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-07 18:34 Context sensitive M-q Thomas S. Dye
2010-09-07 19:11 ` Dan Davison
2010-09-07 19:30   ` org-babel-where-is-src-block-head Jambunathan K
2010-09-07 20:40     ` org-babel-where-is-src-block-head Nicolas Goaziou
2010-09-07 20:46     ` org-babel-where-is-src-block-head Dan Davison
2010-09-07 20:28   ` Context sensitive M-q Thomas S. Dye

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).