org: Fix functionality of org-insert-heading

* lisp/org.el (org-insert-heading): Fix insertion of headings when
  point is before any heading in the case of "respect content" insertion.

Kudos to Victor Stoichita. https://orgmode.org/list/87lf4594t3.fsf@svictor.net/
This commit is contained in:
Marco Wahl 2021-09-18 14:44:17 +02:00
parent b02f1eae19
commit 069bcba529
2 changed files with 18 additions and 1 deletions

View File

@ -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 " ")

View File

@ -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* "