emacs-orgmode
[Top][All Lists]
Advanced

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

`org-fill-paragraph' (`M-q') in Org Mode source blocks


From: Fabio Natali
Subject: `org-fill-paragraph' (`M-q') in Org Mode source blocks
Date: Sun, 9 Jan 2022 17:03:47 +0000

Hello,

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
source block.

┌────
│ #+BEGIN_SRC elisp
│ ;; A comment
│ (+ 2 2)
│ #+END_SRC
└────

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)
│ #+END_SRC
└────

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.


[source code]
<https://git.savannah.gnu.org/cgit/emacs/org-mode.git/tree/lisp/org.el#n19850>

[here]
<https://git.savannah.gnu.org/cgit/emacs/org-mode.git/tree/lisp/org.el#n19757>



reply via email to

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