emacs-orgmode
[Top][All Lists]
Advanced

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

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


From: Sébastien Miquel
Subject: Re: `org-fill-paragraph' (`M-q') in Org Mode source blocks
Date: Mon, 10 Jan 2022 19:50:59 +0000

Hi,

Fabio Natali writes:
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.:)

It's not just you. I think org-fill-paragraph should try to act
natively if called from inside a src block.

As it happens, I've recently added the following advice to my init
file.

(defun my-org-fill-paragraph-natively-maybe ()
  (let* ((element (save-excursion (beginning-of-line) (org-element-at-point-no-context)))
         (type (org-element-type element)))
    (if (and (eq type 'src-block)
             (> (line-beginning-position)
                (org-element-property :post-affiliated element))
             (< (line-beginning-position)
                (org-with-point-at (org-element-property :end element)
                  (skip-chars-backward " \t\n")
                  (line-beginning-position))))
        (progn
          (org-babel-do-in-edit-buffer (fill-paragraph))
          nil) t)))
(advice-add 'org-fill-paragraph :before-while #'my-org-fill-paragraph-natively-maybe)

Regards,

--
Sébastien Miquel




reply via email to

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