fixup! org-insert-heading: Fix when folded text is kept right at the new heading

* lisp/org.el (org-insert-heading): Fix missing newline when inserting
before existing heading.
* testing/lisp/test-org.el (test-org/insert-heading): Add test
checking for the fixed failure.  Update tests.
(test-org/insert-todo-heading-respect-content): Update tests.

Reported-by: Max Nikulin <manikulin@gmail.com>
Link: https://orgmode.org/list/ubrugh$be1$1@ciao.gmane.io
This commit is contained in:
Ihor Radchenko 2023-08-20 09:27:53 +03:00
parent 52bc95676c
commit 7b38670e69
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
2 changed files with 28 additions and 10 deletions

View File

@ -6338,7 +6338,9 @@ unconditionally."
(backward-char)) (backward-char))
(unless (and blank? (org-previous-line-empty-p)) (unless (and blank? (org-previous-line-empty-p))
(org-N-empty-lines-before-current (if blank? 1 0))) (org-N-empty-lines-before-current (if blank? 1 0)))
(insert stars " ") (insert stars " " "\n")
;; Move point after stars.
(backward-char)
;; When INVISIBLE-OK is non-nil, ensure newly created headline ;; When INVISIBLE-OK is non-nil, ensure newly created headline
;; is visible. ;; is visible.
(unless invisible-ok (unless invisible-ok

View File

@ -1861,29 +1861,45 @@ CLOCK: [2022-09-17 sam. 11:00]--[2022-09-17 sam. 11:46] => 0:46"
;; point. ;; point.
(should (should
(equal (equal
"* " "* \n"
(org-test-with-temp-text "" (org-test-with-temp-text ""
(let ((org-insert-heading-respect-content nil)) (let ((org-insert-heading-respect-content nil))
(org-insert-heading '(4))) (org-insert-heading '(4)))
(buffer-string)))) (buffer-string))))
(should
(equal
"
* 1
** 1.1
** 1.2
*
* 2"
(org-test-with-temp-text "
<point>* 1
** 1.1
** 1.2
* 2"
(let ((org-insert-heading-respect-content nil))
(org-insert-heading '(4)))
(buffer-string))))
(should (should
(equal (equal
"entry "entry
* " * \n"
(org-test-with-temp-text "entry" (org-test-with-temp-text "entry"
(let ((org-insert-heading-respect-content nil)) (let ((org-insert-heading-respect-content nil))
(org-insert-heading '(4))) (org-insert-heading '(4)))
(buffer-string)))) (buffer-string))))
(should (should
(equal (equal
"* H1\n** H2\n* " "* H1\n** H2\n* \n"
(org-test-with-temp-text "* H1\n** H2" (org-test-with-temp-text "* H1\n** H2"
(let ((org-insert-heading-respect-content nil)) (let ((org-insert-heading-respect-content nil))
(org-insert-heading '(4))) (org-insert-heading '(4)))
(buffer-string)))) (buffer-string))))
(should (should
(equal (equal
"* H1\n** H2\n* " "* H1\n** H2\n* \n"
(org-test-with-temp-text "* H<point>1\n** H2" (org-test-with-temp-text "* H<point>1\n** H2"
(let ((org-insert-heading-respect-content nil)) (let ((org-insert-heading-respect-content nil))
(org-insert-heading '(4))) (org-insert-heading '(4)))
@ -1891,7 +1907,7 @@ CLOCK: [2022-09-17 sam. 11:00]--[2022-09-17 sam. 11:46] => 0:46"
;; When called with two universal arguments, insert a new headline ;; When called with two universal arguments, insert a new headline
;; at the end of the grandparent subtree. ;; at the end of the grandparent subtree.
(should (should
(equal "* H1\n** H3\n- item\n** H2\n** " (equal "* H1\n** H3\n- item\n** H2\n** \n"
(org-test-with-temp-text "* H1\n** H3\n- item<point>\n** H2" (org-test-with-temp-text "* H1\n** H3\n- item<point>\n** H2"
(let ((org-insert-heading-respect-content nil)) (let ((org-insert-heading-respect-content nil))
(org-insert-heading '(16))) (org-insert-heading '(16)))
@ -1961,7 +1977,7 @@ CLOCK: [2022-09-17 sam. 11:00]--[2022-09-17 sam. 11:46] => 0:46"
;; Properly handle empty lines when forcing a headline below current ;; Properly handle empty lines when forcing a headline below current
;; one. ;; one.
(should (should
(equal "* H1\n\n* H\n\n* " (equal "* H1\n\n* H\n\n* \n"
(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))
@ -1991,14 +2007,14 @@ text
;; Add headline at the end of the first subtree ;; Add headline at the end of the first subtree
(should (should
(equal (equal
"* TODO " "* TODO \n"
(org-test-with-temp-text "* H1\nH1Body<point>\n** H2\nH2Body" (org-test-with-temp-text "* H1\nH1Body<point>\n** H2\nH2Body"
(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)))))
;; In a list, do not create a new item. ;; In a list, do not create a new item.
(should (should
(equal (equal
"* TODO " "* TODO \n"
(org-test-with-temp-text "* H\n- an item\n- another one" (org-test-with-temp-text "* H\n- an item\n- another one"
(search-forward "an ") (search-forward "an ")
(org-insert-todo-heading-respect-content) (org-insert-todo-heading-respect-content)
@ -2006,7 +2022,7 @@ text
;; Use the same TODO keyword as current heading. ;; Use the same TODO keyword as current heading.
(should (should
(equal (equal
"* TODO " "* TODO \n"
(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))))))