emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* `org-fill-paragraph' (`M-q') in Org Mode source blocks
@ 2022-01-09 17:03 Fabio Natali
  2022-01-10 19:50 ` Sébastien Miquel
  0 siblings, 1 reply; 10+ messages in thread
From: Fabio Natali @ 2022-01-09 17:03 UTC (permalink / raw)
  To: emacs-orgmode

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>


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2022-10-05  5:24 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-09 17:03 `org-fill-paragraph' (`M-q') in Org Mode source blocks Fabio Natali
2022-01-10 19:50 ` 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

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).