From 05ee1e6ee06db711198b211867788c39cd08f911 Mon Sep 17 00:00:00 2001 From: Ihor Radchenko Date: Wed, 1 Sep 2021 20:42:05 +0800 Subject: [PATCH 1/2] Do not rely on M-q binding for filling src-block * lisp/org.el (org-fill-element): Use `fill-paragraph' instead of simulating "M-q" binding. (org-fill-paragraph): Return t as described in `fill-paragraph' docstring. Fixes https://orgmode.org/list/CAH7LOt0PO3js6_+Cbinm6EYNx0KFvpfiSS7Dwc1EXsfHfHkHVA@mail.gmail.com/ --- lisp/org.el | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index 44c70e9fa..be7ddcd81 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -19362,7 +19362,9 @@ a footnote definition, try to fill the first paragraph within." ;; the buffer. In that case, ignore filling. (cl-case (org-element-type element) ;; Use major mode filling function is source blocks. - (src-block (org-babel-do-key-sequence-in-edit-buffer (kbd "M-q"))) + (src-block (org-babel-do-in-edit-buffer + (mark-whole-buffer) + (funcall-interactively #'fill-paragraph justify 'region))) ;; Align Org tables, leave table.el tables as-is. (table-row (org-table-align) t) (table @@ -19497,7 +19499,9 @@ filling the current element." ;; previously unmodified), then flip the modification status back ;; to "unchanged". (when (and hash (equal hash (org-buffer-hash))) - (set-buffer-modified-p nil)))) + (set-buffer-modified-p nil)) + ;; Return non-nil. + t)) (defun org-auto-fill-function () "Auto-fill function." From 6a558fc17b42911b6d01e43fcd42754345970a60 Mon Sep 17 00:00:00 2001 From: TEC Date: Fri, 17 Sep 2021 17:23:58 +0800 Subject: [PATCH 2/2] org: Fix potential modified src match-data issue * lisp/org.el (org-fontify-meta-lines-and-blocks-1): When this is run on a src block, a "leaky" major mode called in `org-src-font-lock-fontify-block' can modify the match data. This is problematic, as the match data already set is important for font-lock. To protect ourselves from this behaviour, we can wrap `org-src-font-lock-fontify-block' in `save-match-data' to ensure that the match data for the src block is conserved. --- lisp/org.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lisp/org.el b/lisp/org.el index be7ddcd81..ae0e84cb7 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -5289,7 +5289,8 @@ by a #." (org-remove-flyspell-overlays-in nl-before-endline end-of-endline) (cond ((and lang (not (string= lang "")) org-src-fontify-natively) - (org-src-font-lock-fontify-block lang block-start block-end) + (save-match-data + (org-src-font-lock-fontify-block lang block-start block-end)) (add-text-properties bol-after-beginline block-end '(src-block t))) (quoting (add-text-properties