diff options
author | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2017-03-16 13:01:39 +0100 |
---|---|---|
committer | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2017-03-16 13:01:39 +0100 |
commit | f2e5920f4107e47b297b0c34c64369ccd9cc026f (patch) | |
tree | 3de13aa51de05ac4e63a398aea524d3c2de1ce00 | |
parent | e1cd71532f8ff1a5ac0becce29912d0770c76461 (diff) | |
download | org-mode-f2e5920f4107e47b297b0c34c64369ccd9cc026f.tar.gz |
Fix display bug when inserting a heading
* lisp/org.el (org-N-empty-lines-before-current): Do not hide newline
character before current headline.
* testing/lisp/test-org.el (test-org/insert-heading): Add test.
Reported-by: Rick Frankel <rick@rickster.com>
<http://permalink.gmane.org/gmane.emacs.orgmode/112751>
-rw-r--r-- | lisp/org.el | 15 | ||||
-rw-r--r-- | testing/lisp/test-org.el | 11 |
2 files changed, 17 insertions, 9 deletions
diff --git a/lisp/org.el b/lisp/org.el index 2263652..126318a 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -7881,15 +7881,14 @@ unconditionally." (defun org-N-empty-lines-before-current (n) "Make the number of empty lines before current exactly N. So this will delete or add empty lines." - (let ((column (current-column)) - (empty-lines (make-string n ?\n))) + (save-excursion (beginning-of-line) - (let ((p (point))) - (skip-chars-backward " \r\t\n") - (unless (bolp) (forward-line)) - (delete-region (point) p)) - (insert empty-lines) - (move-to-column column))) + (unless (bobp) + (let ((start (save-excursion + (skip-chars-backward " \r\t\n") + (line-end-position)))) + (delete-region start (line-end-position 0)))) + (insert (make-string n ?\n)))) (defun org-get-heading (&optional no-tags no-todo no-priority no-comment) "Return the heading of the current entry, without the stars. diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el index 1083d0d..1ff7c39 100644 --- a/testing/lisp/test-org.el +++ b/testing/lisp/test-org.el @@ -1342,7 +1342,16 @@ (equal "* H1\n* H2\n* \n" (org-test-with-temp-text "* H1\n* H2<point>\n" (org-insert-heading) - (buffer-string))))) + (buffer-string)))) + ;; Preserve visibility at beginning of line. In particular, when + ;; removing spurious blank lines, do not visually merge heading with + ;; the line visible above. + (should-not + (org-test-with-temp-text "* H1<point>\nContents\n\n* H2\n" + (org-overview) + (let ((org-blank-before-new-entry '((heading . nil)))) + (org-insert-heading '(4))) + (invisible-p (line-end-position 0))))) (ert-deftest test-org/insert-todo-heading-respect-content () "Test `org-insert-todo-heading-respect-content' specifications." |