浏览代码

Fix display bug when inserting a heading

* lisp/org.el (org-N-empty-lines-before-current): Do not hide newline
  character before current headline.

* testing/lisp/test-org.el (test-org/insert-heading): Add test.

Reported-by: Rick Frankel <rick@rickster.com>
<http://permalink.gmane.org/gmane.emacs.orgmode/112751>
Nicolas Goaziou 8 年之前
父节点
当前提交
f2e5920f41
共有 2 个文件被更改,包括 17 次插入9 次删除
  1. 7 8
      lisp/org.el
  2. 10 1
      testing/lisp/test-org.el

+ 7 - 8
lisp/org.el

@@ -7881,15 +7881,14 @@ 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."
-  (let ((column (current-column))
-	(empty-lines (make-string n ?\n)))
+  (save-excursion
     (beginning-of-line)
-    (let ((p (point)))
-      (skip-chars-backward " \r\t\n")
-      (unless (bolp) (forward-line))
-      (delete-region (point) p))
-    (insert empty-lines)
-    (move-to-column column)))
+    (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))))
 
 (defun org-get-heading (&optional no-tags no-todo no-priority no-comment)
   "Return the heading of the current entry, without the stars.

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

@@ -1342,7 +1342,16 @@
    (equal "* H1\n* H2\n* \n"
 	  (org-test-with-temp-text "* H1\n* H2<point>\n"
 	    (org-insert-heading)
-	    (buffer-string)))))
+	    (buffer-string))))
+  ;; Preserve visibility at beginning of line.  In particular, when
+  ;; removing spurious blank lines, do not visually merge heading with
+  ;; the line visible above.
+  (should-not
+   (org-test-with-temp-text "* H1<point>\nContents\n\n* H2\n"
+     (org-overview)
+     (let ((org-blank-before-new-entry '((heading . nil))))
+       (org-insert-heading '(4)))
+     (invisible-p (line-end-position 0)))))
 
 (ert-deftest test-org/insert-todo-heading-respect-content ()
   "Test `org-insert-todo-heading-respect-content' specifications."