Przeglądaj źródła

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 lat temu
rodzic
commit
f2e5920f41
2 zmienionych plików z 17 dodań i 9 usunięć
  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)
 (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."
-  (let ((column (current-column))
-	(empty-lines (make-string n ?\n)))
+  (save-excursion
     (beginning-of-line)
     (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)
 (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.

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

@@ -1342,7 +1342,16 @@
    (equal "* H1\n* H2\n* \n"
    (equal "* H1\n* H2\n* \n"
 	  (org-test-with-temp-text "* H1\n* H2<point>\n"
 	  (org-test-with-temp-text "* H1\n* H2<point>\n"
 	    (org-insert-heading)
 	    (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 ()
 (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."