From 79ac71d175aa0492cc7a58c05ed23539ca8959bc Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Fri, 12 May 2017 17:45:46 +0200 Subject: [PATCH] Tiny fix * lisp/org.el (org-N-empty-lines-before-current): Insert empty lines before point, not after. * testing/lisp/test-org.el (test-org/insert-heading): Add test. --- lisp/org.el | 5 +++-- testing/lisp/test-org.el | 10 +++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index cf30b2177..c46c3c134 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -7884,14 +7884,15 @@ 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." - (save-excursion + (let ((column (current-column))) (beginning-of-line) (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)))) + (insert (make-string n ?\n)) + (move-to-column column))) (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 d2576ebc9..f92ce9547 100644 --- a/testing/lisp/test-org.el +++ b/testing/lisp/test-org.el @@ -1354,7 +1354,15 @@ (org-overview) (let ((org-blank-before-new-entry '((heading . nil)))) (org-insert-heading '(4))) - (invisible-p (line-end-position 0))))) + (invisible-p (line-end-position 0)))) + ;; Properly handle empty lines when forcing a headline below current + ;; one. + (should + (equal "* H1\n\n* H\n\n* \n" + (org-test-with-temp-text "* H1\n\n* H" + (let ((org-blank-before-new-entry '((heading . t)))) + (org-insert-heading '(4)) + (buffer-string)))))) (ert-deftest test-org/insert-todo-heading-respect-content () "Test `org-insert-todo-heading-respect-content' specifications."