diff options
author | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2014-06-09 18:07:07 +0200 |
---|---|---|
committer | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2014-06-09 18:07:07 +0200 |
commit | 8cc4e09950594b2abec2502e9218318570595ac5 (patch) | |
tree | f8655e37e43931ff56d54b7fb28988ac848a9a6d | |
parent | 88f2625f286b00bba7a4a2ac2ea74aa9e00cf0bb (diff) | |
download | org-mode-8cc4e09950594b2abec2502e9218318570595ac5.tar.gz |
Fix `org-insert-heading' before first headline
* lisp/org.el (org-insert-heading): Fix error when inserting
a headline before first headline, with point not at bol. Remove
source block check for consistency with behavior after first
headline. Tiny fix to docstring.
* testing/lisp/test-org.el (test-org/meta-return): Remove unnecessary
test (not testing specifications).
(test-org/insert-heading): New test.
-rw-r--r-- | lisp/org.el | 18 | ||||
-rw-r--r-- | testing/lisp/test-org.el | 39 |
2 files changed, 42 insertions, 15 deletions
diff --git a/lisp/org.el b/lisp/org.el index 7259623..6eee9c0 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -7573,7 +7573,7 @@ on how to modify this behavior). With one universal prefix argument: If point is within a list, insert a heading instead of a list item. Otherwise, set the -value of `org-insert-heading-respect-content' to `t' for the +value of `org-insert-heading-respect-content' to t for the duration of the command. With two universal prefix arguments, insert the heading at the @@ -7602,12 +7602,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))))) diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el index 6954a93..39db5bf 100644 --- a/testing/lisp/test-org.el +++ b/testing/lisp/test-org.el @@ -390,14 +390,6 @@ (org-meta-return) (beginning-of-line) (looking-at "- $"))) - ;; In a drawer and paragraph insert an empty line, in this case above. - (should - (let ((org-drawers '("MYDRAWER"))) - (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 (let ((org-drawers '("MYDRAWER"))) @@ -407,6 +399,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. |