Przeglądaj źródła

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 lat temu
rodzic
commit
79ac71d175
2 zmienionych plików z 12 dodań i 3 usunięć
  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)
 (defun org-N-empty-lines-before-current (n)
   "Make the number of empty lines before current exactly N.
   "Make the number of empty lines before current exactly N.
 So this will delete or add empty lines."
 So this will delete or add empty lines."
-  (save-excursion
+  (let ((column (current-column)))
     (beginning-of-line)
     (beginning-of-line)
     (unless (bobp)
     (unless (bobp)
       (let ((start (save-excursion
       (let ((start (save-excursion
 		     (skip-chars-backward " \r\t\n")
 		     (skip-chars-backward " \r\t\n")
 		     (line-end-position))))
 		     (line-end-position))))
 	(delete-region start (line-end-position 0))))
 	(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)
 (defun org-get-heading (&optional no-tags no-todo no-priority no-comment)
   "Return the heading of the current entry, without the stars.
   "Return the heading of the current entry, without the stars.

+ 9 - 1
testing/lisp/test-org.el

@@ -1354,7 +1354,15 @@
      (org-overview)
      (org-overview)
      (let ((org-blank-before-new-entry '((heading . nil))))
      (let ((org-blank-before-new-entry '((heading . nil))))
        (org-insert-heading '(4)))
        (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 ()
 (ert-deftest test-org/insert-todo-heading-respect-content ()
   "Test `org-insert-todo-heading-respect-content' specifications."
   "Test `org-insert-todo-heading-respect-content' specifications."