From 7b38670e6978c32421660bc37b173e331d5561cb Mon Sep 17 00:00:00 2001 From: Ihor Radchenko Date: Sun, 20 Aug 2023 09:27:53 +0300 Subject: [PATCH] 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 Link: https://orgmode.org/list/ubrugh$be1$1@ciao.gmane.io --- lisp/org.el | 4 +++- testing/lisp/test-org.el | 34 +++++++++++++++++++++++++--------- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index 09805836d..3043988f0 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -6338,7 +6338,9 @@ unconditionally." (backward-char)) (unless (and blank? (org-previous-line-empty-p)) (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 ;; is visible. (unless invisible-ok diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el index db018b52d..0a3583fd7 100644 --- a/testing/lisp/test-org.el +++ b/testing/lisp/test-org.el @@ -1861,29 +1861,45 @@ CLOCK: [2022-09-17 sam. 11:00]--[2022-09-17 sam. 11:46] => 0:46" ;; point. (should (equal - "* " + "* \n" (org-test-with-temp-text "" (let ((org-insert-heading-respect-content nil)) (org-insert-heading '(4))) (buffer-string)))) + (should + (equal + " +* 1 +** 1.1 +** 1.2 +* +* 2" + (org-test-with-temp-text " +* 1 +** 1.1 +** 1.2 +* 2" + (let ((org-insert-heading-respect-content nil)) + (org-insert-heading '(4))) + (buffer-string)))) (should (equal "entry -* " +* \n" (org-test-with-temp-text "entry" (let ((org-insert-heading-respect-content nil)) (org-insert-heading '(4))) (buffer-string)))) (should (equal - "* H1\n** H2\n* " + "* H1\n** H2\n* \n" (org-test-with-temp-text "* H1\n** H2" (let ((org-insert-heading-respect-content nil)) (org-insert-heading '(4))) (buffer-string)))) (should (equal - "* H1\n** H2\n* " + "* H1\n** H2\n* \n" (org-test-with-temp-text "* H1\n** H2" (let ((org-insert-heading-respect-content nil)) (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 ;; at the end of the grandparent subtree. (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\n** H2" (let ((org-insert-heading-respect-content nil)) (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 ;; one. (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" (let ((org-blank-before-new-entry '((heading . t)))) (org-insert-heading '(4)) @@ -1991,14 +2007,14 @@ text ;; Add headline at the end of the first subtree (should (equal - "* TODO " + "* TODO \n" (org-test-with-temp-text "* H1\nH1Body\n** H2\nH2Body" (org-insert-todo-heading-respect-content) (buffer-substring-no-properties (line-beginning-position) (point-max))))) ;; In a list, do not create a new item. (should (equal - "* TODO " + "* TODO \n" (org-test-with-temp-text "* H\n- an item\n- another one" (search-forward "an ") (org-insert-todo-heading-respect-content) @@ -2006,7 +2022,7 @@ text ;; Use the same TODO keyword as current heading. (should (equal - "* TODO " + "* TODO \n" (org-test-with-temp-text "* TODO\n** WAITING\n" (org-insert-todo-heading-respect-content) (buffer-substring-no-properties (line-beginning-position) (point-max))))))