Jelajahi Sumber

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/
Marco Wahl 4 tahun lalu
induk
melakukan
069bcba529
2 mengubah file dengan 18 tambahan dan 1 penghapusan
  1. 3 1
      lisp/org.el
  2. 15 0
      testing/lisp/test-org.el

+ 3 - 1
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 " ")

+ 15 - 0
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* "