summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <n.goaziou@gmail.com>2012-11-13 14:45:09 (GMT)
committer Nicolas Goaziou <n.goaziou@gmail.com>2012-11-13 14:45:09 (GMT)
commit5dbccdb432a6cae66f0866a30379a352873ed15e (patch)
tree58469a6bbdd1ce264497a0cbebcb717f1b926c4a
parent2aeb28d2af6050ef9ef5130b28697fdabe8bf04b (diff)
downloadorg-mode-5dbccdb432a6cae66f0866a30379a352873ed15e.zip
org-mode-5dbccdb432a6cae66f0866a30379a352873ed15e.tar.gz
org-list: Fix infloop when inserting an item
* lisp/org-list.el (org-list-separating-blank-lines-number): When computing number of blank lines separating items, also count those in unparsed blocks, like example blocks. * testing/lisp/test-org-list.el: Add tests. In the following situation, with `org-blank-before-new-entry' set to `auto' for `plain-list-item, a blank line should be inserted when inserting the following item: - item1 #+BEGIN_EXAMPLE contents #+END_EXAMPLE
-rw-r--r--lisp/org-list.el4
-rw-r--r--testing/lisp/test-org-list.el87
2 files changed, 90 insertions, 1 deletions
diff --git a/lisp/org-list.el b/lisp/org-list.el
index 10f5e6e..993272a 100644
--- a/lisp/org-list.el
+++ b/lisp/org-list.el
@@ -1230,7 +1230,9 @@ some heuristics to guess the result."
;; Are there blank lines inside the list so far?
((save-excursion
(goto-char (org-list-get-top-point struct))
- (org-list-search-forward
+ ;; Do not use `org-list-search-forward' so blank lines
+ ;; in blocks can be counted in.
+ (re-search-forward
"^[ \t]*$" (org-list-get-item-end-before-blank item struct) t))
1)
;; Default choice: no blank line.
diff --git a/testing/lisp/test-org-list.el b/testing/lisp/test-org-list.el
index d57ebc9..5e9cab0 100644
--- a/testing/lisp/test-org-list.el
+++ b/testing/lisp/test-org-list.el
@@ -626,6 +626,93 @@
(search-forward "Text1")
(should (org-invisible-p2))))
+(ert-deftest test-org-list/insert-item ()
+ "Test item insertion."
+ ;; Blank lines specifications.
+ ;;
+ ;; Non-nil `org-blank-before-new-entry': insert a blank line, unless
+ ;; `org-empty-line-terminates-plain-lists' is non-nil.
+ (should
+ (org-test-with-temp-text "- a"
+ (let ((org-empty-line-terminates-plain-lists nil)
+ (org-blank-before-new-entry '((plain-list-item . t))))
+ (end-of-line)
+ (org-insert-item)
+ (forward-line -1)
+ (looking-at "$"))))
+ (should-not
+ (org-test-with-temp-text "- a"
+ (let ((org-empty-line-terminates-plain-lists t)
+ (org-blank-before-new-entry '((plain-list-item . t))))
+ (end-of-line)
+ (org-insert-item)
+ (forward-line -1)
+ (looking-at "$"))))
+ ;; Nil `org-blank-before-new-entry': do not insert a blank line.
+ (should-not
+ (org-test-with-temp-text "- a"
+ (let ((org-empty-line-terminates-plain-lists nil)
+ (org-blank-before-new-entry '((plain-list-item . nil))))
+ (end-of-line)
+ (org-insert-item)
+ (forward-line -1)
+ (looking-at "$"))))
+ ;; `org-blank-before-new-entry' set to auto: if there's no blank
+ ;; line already in the sole item, do not insert one.
+ (should-not
+ (org-test-with-temp-text "- a"
+ (let ((org-empty-line-terminates-plain-lists nil)
+ (org-blank-before-new-entry '((plain-list-item . auto))))
+ (end-of-line)
+ (org-insert-item)
+ (forward-line -1)
+ (looking-at "$"))))
+ ;; `org-blank-before-new-entry' set to `auto': if there's a blank
+ ;; line in the sole item, insert another one.
+ (should
+ (org-test-with-temp-text "- a\n\n b"
+ (let ((org-empty-line-terminates-plain-lists nil)
+ (org-blank-before-new-entry '((plain-list-item . auto))))
+ (goto-char (point-max))
+ (org-insert-item)
+ (forward-line -1)
+ (looking-at "$"))))
+ ;; `org-blank-before-new-entry' set to `auto': if the user specified
+ ;; a blank line, preserve it.
+ (should
+ (org-test-with-temp-text "- a\n\n"
+ (let ((org-empty-line-terminates-plain-lists nil)
+ (org-blank-before-new-entry '((plain-list-item . auto))))
+ (goto-char (point-max))
+ (org-insert-item)
+ (forward-line -1)
+ (looking-at "$"))))
+ ;; `org-blank-before-new-entry' set to `auto': if some items in list
+ ;; are already separated by blank lines, insert one.
+ (should
+ (org-test-with-temp-text "- a\n\n- b"
+ (let ((org-empty-line-terminates-plain-lists nil)
+ (org-blank-before-new-entry '((plain-list-item . auto))))
+ (goto-char (point-max))
+ (org-insert-item)
+ (forward-line -1)
+ (looking-at "$"))))
+ (should
+ (org-test-with-temp-text "- a\n\n- b"
+ (let ((org-empty-line-terminates-plain-lists nil)
+ (org-blank-before-new-entry '((plain-list-item . auto))))
+ (org-insert-item)
+ (forward-line)
+ (looking-at "$"))))
+ (should
+ (org-test-with-temp-text "- a\n #+BEGIN_EXAMPLE\n\n x\n #+END_EXAMPLE"
+ (let ((org-empty-line-terminates-plain-lists nil)
+ (org-blank-before-new-entry '((plain-list-item . auto))))
+ (goto-char (point-max))
+ (org-insert-item)
+ (forward-line -1)
+ (looking-at "$")))))
+
(provide 'test-org-list)
;;; test-org-list.el ends here