Hi,
Axel Svensson writes:
Steps to reproduce:
1) In an empty org-mode buffer, type a * SPC a C-b C-b C-b <RET>.
2) The buffer now has two lines, the first one "a" and the second "* a".
Expected:
3) The second line is formatted as a first-level heading.
Actual:
3) The second line is formatted as normal text.
Thanks for the report, I can confirm this bug with latest org.
Here's a patch that fixes this.
Regards,
--
Sébastien Miquel
>From c598f705bf1d8003514751fffc07fd64620a7e42 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Miquel?= <sebastien.miq...@posteo.eu>
Date: Fri, 28 May 2021 21:14:22 +0200
Subject: [PATCH] org.el (org-fontify-extend-region): Fix headline
fontification in edge case
* lisp/org.el (org-fontify-extend-region): Fix fontification of
headline or meta line created by inserting a newline.
Unrelated to the fix: `org-fontify-extend-region' is added to
`font-lock-extend-after-change-region-function' and doesn't need to
use `save-excursion'.
---
lisp/org.el | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
diff --git a/lisp/org.el b/lisp/org.el
index 1bd9e02eb..b7b1416bd 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -5427,7 +5427,9 @@ by a #."
t)))))
(defun org-fontify-extend-region (beg end _old-len)
- (let ((begin-re "\\(\\\\\\[\\|\\(#\\+begin_\\|\\\\begin{\\)\\S-+\\)")
+ (let ((end (if (progn (goto-char end) (looking-at-p "^[*#]"))
+ (1+ end) end))
+ (begin-re "\\(\\\\\\[\\|\\(#\\+begin_\\|\\\\begin{\\)\\S-+\\)")
(end-re "\\(\\\\\\]\\|\\(#\\+end_\\|\\\\end{\\)\\S-+\\)")
(extend
(lambda (r1 r2 dir)
@@ -5437,15 +5439,14 @@ by a #."
"[][]" r2
(match-string-no-properties 0)))))
(re-search-forward (regexp-quote re) nil t dir)))))
+ (goto-char beg)
+ (back-to-indentation)
(save-match-data
- (save-excursion
- (goto-char beg)
- (back-to-indentation)
- (cond ((looking-at end-re)
- (cons (or (funcall extend "begin" "[" -1) beg) end))
- ((looking-at begin-re)
- (cons beg (or (funcall extend "end" "]" 1) end)))
- (t (cons beg end)))))))
+ (cond ((looking-at end-re)
+ (cons (or (funcall extend "begin" "[" -1) beg) end))
+ ((looking-at begin-re)
+ (cons beg (or (funcall extend "end" "]" 1) end)))
+ (t (cons beg end))))))
(defun org-activate-footnote-links (limit)
"Add text properties for footnotes."
--
2.31.1