[Top][All Lists]

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

[Orgmode] Re: Context sensitive M-q

From: Dan Davison
Subject: [Orgmode] Re: Context sensitive M-q
Date: Tue, 07 Sep 2010 15:11:18 -0400
User-agent: Gnus/5.110011 (No Gnus v0.11) Emacs/24.0.50 (gnu/linux)

"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 ()
    (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 ()
    (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)



[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]