diff options
author | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2017-02-17 21:51:16 +0100 |
---|---|---|
committer | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2017-02-17 21:51:16 +0100 |
commit | 542890cd3f7fc482c7a1c949de6eba46af9fb4e0 (patch) | |
tree | 6e003e63902df039d826e4f68be3f4d97ac0e2af | |
parent | 82c3039ce486322df75dbb112692986c25bdcea9 (diff) | |
download | org-mode-542890cd3f7fc482c7a1c949de6eba46af9fb4e0.tar.gz |
Fix: Prevent spurious newlines when inserting a new heading
* lisp/org.el (org-insert-heading): Do not insert spurious newline
characters when inserting a headline.
* testing/lisp/test-org.el (test-org/insert-heading): Add tests.
Reported-by: Kyle Sherman <kylewsherman@gmail.com>
<http://permalink.gmane.org/gmane.emacs.orgmode/112205>
-rw-r--r-- | lisp/org.el | 7 | ||||
-rw-r--r-- | testing/lisp/test-org.el | 10 |
2 files changed, 13 insertions, 4 deletions
diff --git a/lisp/org.el b/lisp/org.el index ed58ab7..3290a2b 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -7855,13 +7855,12 @@ unconditionally." (when blank? (insert "\n")) (insert "\n" stars " ") (when (org-string-nw-p split) (insert split)) - (insert "\n") - (forward-char -1))) + (when (eobp) (save-excursion (insert "\n"))))) (t (end-of-line) (when blank? (insert "\n")) - (insert "\n" stars " \n") - (forward-char -1)))) + (insert "\n" stars " ") + (when (eobp) (save-excursion (insert "\n")))))) ;; On regular text, turn line into a headline or split, if ;; appropriate. ((bolp) diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el index 8f5210f..1083d0d 100644 --- a/testing/lisp/test-org.el +++ b/testing/lisp/test-org.el @@ -1332,6 +1332,16 @@ (equal "* \n* \n" (org-test-with-temp-text "* <point>" (org-insert-heading) + (buffer-string)))) + (should + (org-test-with-temp-text "* <point>\n" + (org-insert-heading) + (looking-at-p "\n\\'"))) + ;; Do not insert spurious headlines when inserting a new headline. + (should + (equal "* H1\n* H2\n* \n" + (org-test-with-temp-text "* H1\n* H2<point>\n" + (org-insert-heading) (buffer-string))))) (ert-deftest test-org/insert-todo-heading-respect-content () |