summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarco Wahl <marcowahlsoft@gmail.com>2021-09-18 14:44:17 +0200
committerMarco Wahl <marcowahlsoft@gmail.com>2021-09-18 14:54:09 +0200
commit069bcba529142bdb91647258924513f0fb0f3fa1 (patch)
treeeff758fcc19bcd9ec2643579d30fe2297266b6b5
parentb02f1eae19049dfb3e7e3815fae98844aa008421 (diff)
downloadorg-mode-069bcba529142bdb91647258924513f0fb0f3fa1.tar.gz
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/
-rw-r--r--lisp/org.el4
-rw-r--r--testing/lisp/test-org.el15
2 files changed, 18 insertions, 1 deletions
diff --git a/lisp/org.el b/lisp/org.el
index 8b9d571..733dda4 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 de3c6f3..f3a729b 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -1604,6 +1604,21 @@
;; 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* "
(org-test-with-temp-text "* H1\n** H2"
(let ((org-insert-heading-respect-content nil))