Bläddra i källkod

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.
Nicolas Goaziou 8 år sedan
förälder
incheckning
79ac71d175
2 ändrade filer med 12 tillägg och 3 borttagningar
  1. 3 2
      lisp/org.el
  2. 9 1
      testing/lisp/test-org.el

+ 3 - 2
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.

+ 9 - 1
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."