summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <n.goaziou@gmail.com>2013-10-29 09:55:01 +0100
committerNicolas Goaziou <n.goaziou@gmail.com>2013-10-29 09:55:01 +0100
commita7e5a74e2ce41819a342a282f62541d6e9d61c47 (patch)
tree2475cefc50bfc038714a44fe6e88ef7e64e369ef
parent8eadca98a638c00114898da6306a3d9699121f4e (diff)
downloadorg-mode-a7e5a74e2ce41819a342a282f62541d6e9d61c47.tar.gz
Fix `org-insert-heading' at buffer boundaries
* lisp/org.el (org-insert-heading): Do not error out when inserting is to be done at one of the buffer's boundaries. * testing/lisp/test-org.el: Add tests.
-rw-r--r--lisp/org.el7
-rw-r--r--testing/lisp/test-org.el22
2 files changed, 26 insertions, 3 deletions
diff --git a/lisp/org.el b/lisp/org.el
index ddf8354..8da6f7d 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -7569,7 +7569,8 @@ This is important for non-interactive uses of the command."
(and (ignore-errors (org-back-to-heading invisible-ok))
(org-at-heading-p))))
(or arg (not itemp))))
- ;; At beginning of buffer or so hight up that only a heading makes sense.
+ ;; At beginning of buffer or so high up that only a heading
+ ;; makes sense.
(insert
(if (or (bobp) (org-previous-line-empty-p)) "" "\n")
(if (org-in-src-block-p) ",* " "* "))
@@ -7631,9 +7632,9 @@ This is important for non-interactive uses of the command."
(org-end-of-subtree nil t)
(skip-chars-backward " \r\n")
(and (looking-at "[ \t]+") (replace-match ""))
- (forward-char 1)
+ (unless (eobp) (forward-char 1))
(when (looking-at "^\\*")
- (backward-char 1)
+ (unless (bobp) (backward-char 1))
(insert "\n")))
;; If we are splitting, grab the text that should be moved to the new headline
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index b6c5558..1540b8e 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -407,6 +407,28 @@
(beginning-of-line)
(looking-at "- $")))))
+(ert-deftest test-org/insert-todo-heading-respect-content ()
+ "Test `org-insert-todo-heading-respect-content' specifications."
+ ;; Create a TODO heading.
+ (should
+ (org-test-with-temp-text "* H1\n Body"
+ (org-insert-todo-heading-respect-content)
+ (nth 2 (org-heading-components))))
+ ;; Add headline after body of current subtree.
+ (should
+ (org-test-with-temp-text "* H1\nBody"
+ (org-insert-todo-heading-respect-content)
+ (eobp)))
+ (should
+ (org-test-with-temp-text "* H1\n** H2\nBody"
+ (org-insert-todo-heading-respect-content)
+ (eobp)))
+ ;; In a list, do not create a new item.
+ (should
+ (org-test-with-temp-text "* H\n- an item\n- another one"
+ (search-forward "an ")
+ (org-insert-todo-heading-respect-content)
+ (and (eobp) (org-at-heading-p)))))