branch: externals/org
commit 54f8b0bfd08645db7e2393d0c1eb287969b181d9
Merge: 928f2d7fb0 52bc95676c
Author: Ihor Radchenko <yanta...@posteo.net>
Commit: Ihor Radchenko <yanta...@posteo.net>

    Merge branch 'bugfix'
---
 lisp/org.el              |  5 ++++-
 testing/lisp/test-org.el | 18 ++++++++++++++++--
 2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index 6abb2db958..8511304857 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -6372,7 +6372,10 @@ unconditionally."
        (if (not level) (outline-next-heading) ;before first headline
         (org-back-to-heading invisible-ok)
         (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"))
       (when (and blank? (save-excursion
                           (backward-char)
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index 1b00f6c455..3f38a560ea 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -2035,7 +2035,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>"
            (let ((org-blank-before-new-entry '((heading . t))))
              (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 ()
   "Test `org-insert-todo-heading-respect-content' specifications."
@@ -2062,7 +2076,7 @@ CLOCK: [2022-09-17 sam. 11:00]--[2022-09-17 sam. 11:46] 
=>  0:46"
   ;; Use the same TODO keyword as current heading.
   (should
    (equal
-    "* TODO \n"
+    "* TODO "
     (org-test-with-temp-text "* TODO\n** WAITING\n"
       (org-insert-todo-heading-respect-content)
       (buffer-substring-no-properties (line-beginning-position) (point-max)))))

Reply via email to