From: Fabio Natali <firstname.lastname@example.org>
Subject: `org-fill-paragraph' (`M-q') in Org Mode source blocks
Date: Sun, 9 Jan 2022 17:03:47 +0000 [thread overview]
Message-ID: <YdsVc5ReHWxo3Zx+@localhost> (raw)
I'm having some issues with `M-q' (`org-fill-paragraph') within a Org
Mode source block.
Consider, for instance, a Org Mode file that contains the following
│ #+BEGIN_SRC elisp
│ ;; A comment
│ (+ 2 2)
What happens: when calling `M-q' from within the block, the content is
handled like generic text and transformed as follows.
│ #+BEGIN_SRC elisp
│ ;; A comment (+ 2 2)
What I'd be ideally expecting: the code to be potentially transformed
the same way it'd be in Emacs Lisp major mode.
What I'm actually expecting: the above might be too much of a high
expectation (i.e. for Org Mode to be aware of different `fill-paragraph'
mechanisms for different languages). As a second best, I'd be expecting
Org Mode to simply ignore my `M-q' command.
Here are some further considerations:
• Things work as expected when editing the block with the relevant major
mode, e.g. Emacs Lisp; I know that this can be easily activated with
`org-edit-special' (`C-c '').
• This can be replicated over different languages, i.e. it doesn't seem
to be related to Emacs Lisp code in any way.
• I was able to reproduce this with a minimal `init.el' that only
contains `(org-babel-do-load-languages 'org-babel-load-languages
'((emacs-lisp . t)))'.
• I've been testing this with GNU Emacs 27.2 and Org Mode 9.5.1.
Also, I can see `M-q' is bound to `org-fill-paragraph'. The [source
code] for that function says:
This function only applies to comment blocks, comments,
example blocks and paragraphs.
This would seem to confirm my expectation, i.e. that the command
shouldn't be doing anything within a source block. Instead,
`org-fill-paragraph' seems to be calling `org-fill-element' and then
ultimately `fill-paragraph', [here].
This might be a relevant section:
│ (cl-case (org-element-type element)
│ ;; Use major mode filling function is source blocks.
│ (src-block (org-babel-do-in-edit-buffer
│ (push-mark (point-min))
│ (goto-char (point-max))
│ (setq mark-active t)
│ (funcall-interactively #'fill-paragraph justify 'region)))
In order to honour its promise of only applying "to comment blocks,
comments, example blocks and paragraphs", shouldn't rather the function
do nothing in this case?
Is there anything obvious that you think I'm missing here? Is anyone
able to replicate the above behaviour and, if so, do you also find it
slightly problematic? Any thoughts and feedback on the above will be
greatly appreciated. :)
Thanks, best, F.
next reply other threads:[~2022-01-09 17:09 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-09 17:03 Fabio Natali [this message]
2022-01-10 19:50 ` `org-fill-paragraph' (`M-q') in Org Mode source blocks Sébastien Miquel
2022-01-11 13:30 ` Fabio Natali
2022-01-11 19:32 ` Rudolf Adamkovič
2022-01-11 20:09 ` Sébastien Miquel
2022-10-03 6:51 ` Ihor Radchenko
2022-10-03 7:18 ` Sébastien Miquel
2022-10-03 9:23 ` Ihor Radchenko
2022-10-04 16:36 ` Sébastien Miquel
2022-10-05 5:22 ` Ihor Radchenko
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:
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
* 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
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).