diff options
author | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2017-01-02 23:21:53 +0100 |
---|---|---|
committer | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2017-01-02 23:21:53 +0100 |
commit | 1fac906174e9c522c25a66f91ccd09e9e7c91973 (patch) | |
tree | 5c0923ff7694bf580d402810c9f864cf5caa2a8b | |
parent | c32db8a8dae5d5ca00fbf5d048d63c77e8dfafd3 (diff) | |
download | org-mode-1fac906174e9c522c25a66f91ccd09e9e7c91973.tar.gz |
Fix `org-N-empty-lines-before-current'
* lisp/org.el (org-N-empty-lines-before-current): Preserve point when
calling the function from the beginning of a line.
* testing/lisp/test-org.el (test-org/insert-heading): Add tests.
-rw-r--r-- | lisp/org.el | 8 | ||||
-rw-r--r-- | testing/lisp/test-org.el | 25 |
2 files changed, 30 insertions, 3 deletions
diff --git a/lisp/org.el b/lisp/org.el index c0098cf..aed4d37 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -8003,16 +8003,18 @@ unconditionally." (org-N-empty-lines-before-current (if blank? 1 0)))))) (run-hooks 'org-insert-heading-hook)) -(defun org-N-empty-lines-before-current (N) +(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)) + (empty-lines (make-string n ?\n))) (beginning-of-line) (let ((p (point))) (skip-chars-backward " \r\t\n") (unless (bolp) (forward-line)) (delete-region (point) p)) - (when (> N 0) (insert (make-string N ?\n))))) + (insert empty-lines) + (move-to-column column))) (defun org-get-heading (&optional no-tags no-todo) "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 e21502a..52f37a4 100644 --- a/testing/lisp/test-org.el +++ b/testing/lisp/test-org.el @@ -1267,6 +1267,31 @@ (org-test-with-temp-text "* H1\n- item<point>" (org-insert-heading nil nil t) (buffer-string)))) + ;; Obey `org-blank-before-new-entry'. + (should + (equal "* H1\n\n* \n" + (org-test-with-temp-text "* H1<point>" + (let ((org-blank-before-new-entry '((heading . t)))) + (org-insert-heading)) + (buffer-string)))) + (should + (equal "* H1\n* \n" + (org-test-with-temp-text "* H1<point>" + (let ((org-blank-before-new-entry '((heading . nil)))) + (org-insert-heading)) + (buffer-string)))) + (should + (equal "* H1\n* H2\n* \n" + (org-test-with-temp-text "* H1\n* H2<point>" + (let ((org-blank-before-new-entry '((heading . auto)))) + (org-insert-heading)) + (buffer-string)))) + (should + (equal "* H1\n\n* H2\n\n* \n" + (org-test-with-temp-text "* H1\n\n* H2<point>" + (let ((org-blank-before-new-entry '((heading . auto)))) + (org-insert-heading)) + (buffer-string)))) ;; Corner case: correctly insert a headline after an empty one. (should (equal "* \n* \n" |