org-insert-heading: Fix when folded text is kept right at the new heading
* lisp/org.el (org-insert-heading): Do not slurp blank lines after previous heading into the contents of the newly added one. These blank lines might be folded and we end up with point before folded spaces * <point>... * testing/lisp/test-org.el (test-org/insert-heading): Add test. (test-org/insert-todo-heading-respect-content): Do not expect trailing newline after the newly added heading. The test did not intentionally test this particular behavior (other tests do not expect trailing newlines to be _always_ added). Reported-by: Max Nikulin <manikulin@gmail.com> Link: https://orgmode.org/list/ubpcoi$f7n$1@ciao.gmane.io
This commit is contained in:
parent
a25d00d5df
commit
52bc95676c
|
@ -6323,7 +6323,10 @@ unconditionally."
|
||||||
(if (not level) (outline-next-heading) ;before first headline
|
(if (not level) (outline-next-heading) ;before first headline
|
||||||
(org-back-to-heading invisible-ok)
|
(org-back-to-heading invisible-ok)
|
||||||
(when (equal arg '(16)) (org-up-heading-safe))
|
(when (equal arg '(16)) (org-up-heading-safe))
|
||||||
(org-end-of-subtree)))
|
(org-end-of-subtree invisible-ok 'to-heading)))
|
||||||
|
;; At `point-max', if the file does not have ending newline,
|
||||||
|
;; create one, so that we are not appending stars at non-empty
|
||||||
|
;; line.
|
||||||
(unless (bolp) (insert "\n"))
|
(unless (bolp) (insert "\n"))
|
||||||
(when (and blank? (save-excursion
|
(when (and blank? (save-excursion
|
||||||
(backward-char)
|
(backward-char)
|
||||||
|
|
|
@ -1965,7 +1965,21 @@ CLOCK: [2022-09-17 sam. 11:00]--[2022-09-17 sam. 11:46] => 0:46"
|
||||||
(org-test-with-temp-text "* H1\n\n* H<point>"
|
(org-test-with-temp-text "* H1\n\n* H<point>"
|
||||||
(let ((org-blank-before-new-entry '((heading . t))))
|
(let ((org-blank-before-new-entry '((heading . t))))
|
||||||
(org-insert-heading '(4))
|
(org-insert-heading '(4))
|
||||||
(buffer-string))))))
|
(buffer-string)))))
|
||||||
|
;; Do not include potentially folded empty lines.
|
||||||
|
(org-test-with-temp-text "
|
||||||
|
<point>* Sec1
|
||||||
|
** SubSec1
|
||||||
|
|
||||||
|
text
|
||||||
|
|
||||||
|
** SubSec2
|
||||||
|
|
||||||
|
text
|
||||||
|
"
|
||||||
|
(org-content)
|
||||||
|
(org-insert-heading '(4))
|
||||||
|
(should-not (org-fold-folded-p))))
|
||||||
|
|
||||||
(ert-deftest test-org/insert-todo-heading-respect-content ()
|
(ert-deftest test-org/insert-todo-heading-respect-content ()
|
||||||
"Test `org-insert-todo-heading-respect-content' specifications."
|
"Test `org-insert-todo-heading-respect-content' specifications."
|
||||||
|
@ -1992,7 +2006,7 @@ CLOCK: [2022-09-17 sam. 11:00]--[2022-09-17 sam. 11:46] => 0:46"
|
||||||
;; Use the same TODO keyword as current heading.
|
;; Use the same TODO keyword as current heading.
|
||||||
(should
|
(should
|
||||||
(equal
|
(equal
|
||||||
"* TODO \n"
|
"* TODO "
|
||||||
(org-test-with-temp-text "* TODO\n** WAITING\n"
|
(org-test-with-temp-text "* TODO\n** WAITING\n"
|
||||||
(org-insert-todo-heading-respect-content)
|
(org-insert-todo-heading-respect-content)
|
||||||
(buffer-substring-no-properties (line-beginning-position) (point-max))))))
|
(buffer-substring-no-properties (line-beginning-position) (point-max))))))
|
||||||
|
|
Loading…
Reference in New Issue