emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Orgmode] Re: Context sensitive M-q


From: Thomas S. Dye
Subject: [Orgmode] Re: Context sensitive M-q
Date: Tue, 7 Sep 2010 10:28:47 -1000

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" <address@hidden> 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.
address@hidden
http://lists.gnu.org/mailman/listinfo/emacs-orgmode





reply via email to

[Prev in Thread] Current Thread [Next in Thread]