emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Dan Davison <davison@stats.ox.ac.uk>
To: "Thomas S. Dye" <tsd@tsdye.com>
Cc: emacs-orgmode Mailinglist <emacs-orgmode@gnu.org>
Subject: Re: Context sensitive M-q
Date: Tue, 07 Sep 2010 15:11:18 -0400	[thread overview]
Message-ID: <87fwxlweqx.fsf@stats.ox.ac.uk> (raw)
In-Reply-To: <38B5DC68-38DC-4F36-8D26-F050D4F42036@tsdye.com> (Thomas S. Dye's message of "Tue, 7 Sep 2010 08:34:29 -1000")

"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

  reply	other threads:[~2010-09-07 19:11 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-07 18:34 Context sensitive M-q Thomas S. Dye
2010-09-07 19:11 ` Dan Davison [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87fwxlweqx.fsf@stats.ox.ac.uk \
    --to=davison@stats.ox.ac.uk \
    --cc=emacs-orgmode@gnu.org \
    --cc=tsd@tsdye.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).