浏览代码

Merge branch 'maint'

Nicolas Goaziou 10 年之前
父节点
当前提交
0620fe98cb
共有 2 个文件被更改,包括 12 次插入7 次删除
  1. 6 7
      lisp/org.el
  2. 6 0
      testing/lisp/test-org.el

+ 6 - 7
lisp/org.el

@@ -7881,13 +7881,12 @@ command."
   "Make the number of empty lines before current exactly N.
 So this will delete or add empty lines."
   (save-excursion
-    (goto-char (point-at-bol))
-    (if (looking-back "\\s-+" nil 'greedy)
-	(replace-match ""))
-    (or (bobp) (insert "\n"))
-    (while (> N 0)
-      (insert "\n")
-      (setq N (1- 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)))))
 
 (defun org-get-heading (&optional no-tags no-todo)
   "Return the heading of the current entry, without the stars.

+ 6 - 0
testing/lisp/test-org.el

@@ -731,6 +731,12 @@
 	  (org-test-with-temp-text "Para<point>graph"
 	    (let ((org-M-RET-may-split-line '((default . nil))))
 	      (org-insert-heading))
+	    (buffer-string))))
+  ;; Corner case: correctly insert a headline after an empty one.
+  (should
+   (equal "* \n* "
+	  (org-test-with-temp-text "* <point>"
+	    (org-insert-heading)
 	    (buffer-string)))))
 
 (ert-deftest test-org/insert-todo-heading-respect-content ()