summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2017-05-12 17:45:46 +0200
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2017-05-12 17:45:46 +0200
commit79ac71d175aa0492cc7a58c05ed23539ca8959bc (patch)
tree61762d0145d63632d35f7c2aec210c0456271eeb
parent4f578a3f7fe193229adc239c93d6983bcc030d41 (diff)
downloadorg-mode-79ac71d175aa0492cc7a58c05ed23539ca8959bc.tar.gz
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.
-rw-r--r--lisp/org.el5
-rw-r--r--testing/lisp/test-org.el10
2 files changed, 12 insertions, 3 deletions
diff --git a/lisp/org.el b/lisp/org.el
index cf30b21..c46c3c1 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 d2576eb..f92ce95 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<point>"
+ (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."