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>
This commit is contained in:
Nicolas Goaziou 2017-02-17 21:51:16 +01:00
parent 82c3039ce4
commit 542890cd3f
2 changed files with 13 additions and 4 deletions

View File

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

View File

@ -1331,6 +1331,16 @@
(should
(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)))))