瀏覽代碼

Merge branch 'maint'

Conflicts:
	lisp/org.el
	testing/lisp/test-org.el
Nicolas Goaziou 10 年之前
父節點
當前提交
5cca90edf8
共有 2 個文件被更改,包括 41 次插入13 次删除
  1. 10 6
      lisp/org.el
  2. 31 7
      testing/lisp/test-org.el

+ 10 - 6
lisp/org.el

@@ -7731,12 +7731,16 @@ command."
 	       (or arg (not itemp))))
       ;; At beginning of buffer or so high up that only a heading
       ;; makes sense.
-      (when (and (org-before-first-heading-p) (not (bolp)))
-	(re-search-forward org-outline-regexp-bol)
-	(beginning-of-line 0))
-      (insert
-       (if (or (bobp) (org-previous-line-empty-p)) "" "\n")
-       (if (org-in-src-block-p) ",* " "* "))
+      (cond ((bolp) (insert "* "))
+	    ((not respect-content)
+	     (unless may-split (end-of-line))
+	     (insert "\n* "))
+	    ((re-search-forward org-outline-regexp-bol nil t)
+	     (beginning-of-line)
+	     (insert "* \n")
+	     (backward-char))
+	    (t (goto-char (point-max))
+	       (insert "\n* ")))
       (run-hooks 'org-insert-heading-hook))
 
      ((and itemp (not (member arg '((4) (16)))))

+ 31 - 7
testing/lisp/test-org.el

@@ -694,13 +694,6 @@
      (org-meta-return)
      (beginning-of-line)
      (looking-at "- $")))
-  ;; In a drawer and paragraph insert an empty line, in this case above.
-  (should
-   (org-test-with-temp-text ":MYDRAWER:\na\n:END:"
-     (forward-line)
-     (org-meta-return)
-     (forward-line -1)
-     (looking-at "$")))
   ;; In a drawer and item insert an item, in this case above.
   (should
    (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
@@ -709,6 +702,37 @@
      (beginning-of-line)
      (looking-at "- $"))))
 
+(ert-deftest test-org/insert-heading ()
+  "Test `org-insert-heading' specifications."
+  ;; FIXME: Test coverage is incomplete yet.
+  ;;
+  ;; In an empty buffer, insert a new headline.
+  (should
+   (equal "* "
+	  (org-test-with-temp-text ""
+	    (org-insert-heading)
+	    (buffer-string))))
+  ;; At the beginning of a line, turn it into a headline
+  (should
+   (equal "* P"
+	  (org-test-with-temp-text "<point>P"
+	    (org-insert-heading)
+	    (buffer-string))))
+  ;; In the middle of a line, split the line if allowed, otherwise,
+  ;; insert the headline at its end.
+  (should
+   (equal "Para\n* graph"
+	  (org-test-with-temp-text "Para<point>graph"
+	    (let ((org-M-RET-may-split-line '((default . t))))
+	      (org-insert-heading))
+	    (buffer-string))))
+  (should
+   (equal "Paragraph\n* "
+	  (org-test-with-temp-text "Para<point>graph"
+	    (let ((org-M-RET-may-split-line '((default . nil))))
+	      (org-insert-heading))
+	    (buffer-string)))))
+
 (ert-deftest test-org/insert-todo-heading-respect-content ()
   "Test `org-insert-todo-heading-respect-content' specifications."
   ;; Create a TODO heading.