From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dan Davison Subject: Re: Context sensitive M-q Date: Tue, 07 Sep 2010 15:11:18 -0400 Message-ID: <87fwxlweqx.fsf@stats.ox.ac.uk> References: <38B5DC68-38DC-4F36-8D26-F050D4F42036@tsdye.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from [140.186.70.92] (port=45308 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ot3Zk-0003a9-03 for emacs-orgmode@gnu.org; Tue, 07 Sep 2010 15:11:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1Ot3Zi-0006BX-N0 for emacs-orgmode@gnu.org; Tue, 07 Sep 2010 15:11:23 -0400 Received: from markov.stats.ox.ac.uk ([163.1.210.1]:43030) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Ot3Zi-0006BS-Ee for emacs-orgmode@gnu.org; Tue, 07 Sep 2010 15:11:22 -0400 In-Reply-To: <38B5DC68-38DC-4F36-8D26-F050D4F42036@tsdye.com> (Thomas S. Dye's message of "Tue, 7 Sep 2010 08:34:29 -1000") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: "Thomas S. Dye" Cc: emacs-orgmode Mailinglist "Thomas S. Dye" 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