diff --git a/lisp/org.el b/lisp/org.el index 8b9d57157..733dda429 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -7039,7 +7039,9 @@ unconditionally." (org-before-first-heading-p))) (insert "\n") (backward-char)) - (unless level (backward-char)) + (when (and (not level) (not (eobp)) (not (bobp))) + (when (org-at-heading-p) (insert "\n")) + (backward-char)) (unless (and blank? (org-previous-line-empty-p)) (org-N-empty-lines-before-current (if blank? 1 0))) (insert stars " ") diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el index de3c6f3c9..f3a729bb2 100644 --- a/testing/lisp/test-org.el +++ b/testing/lisp/test-org.el @@ -1602,6 +1602,21 @@ ;; When called with one universal argument, insert a new headline at ;; the end of the current subtree, independently on the position of ;; point. + (should + (equal + "* " + (org-test-with-temp-text "" + (let ((org-insert-heading-respect-content nil)) + (org-insert-heading '(4))) + (buffer-string)))) + (should + (equal + "entry +* " + (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* "