summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <n.goaziou@gmail.com>2012-07-30 15:23:22 +0200
committerNicolas Goaziou <n.goaziou@gmail.com>2012-07-30 15:25:13 +0200
commit5cb9beea9b722143ffeaa2c90fd7af075e7d499f (patch)
tree34511805b13cfc5b07ef3fe64acbe25ec2102d18
parent4c2c6dba7bacfcf3b08c3b990663352d8b7a2e70 (diff)
downloadorg-mode-5cb9beea9b722143ffeaa2c90fd7af075e7d499f.tar.gz
Add tests about filling and auto-filling
* lisp/org.el (org-fill-context-prefix): Small refactoring. (org-fill-paragraph): Add code comments. * testing/lisp/test-org.el: Add tests
-rw-r--r--lisp/org.el21
-rw-r--r--testing/lisp/test-org.el88
2 files changed, 99 insertions, 10 deletions
diff --git a/lisp/org.el b/lisp/org.el
index a564291..1de386b 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -20820,8 +20820,9 @@ If point is in an inline task, mark that task instead."
Return fill prefix, as a string, or nil if current line isn't
meant to be filled."
(save-excursion
- (let* ((elements (org-element-at-point t))
- (element (car elements))
+ (goto-char p)
+ (beginning-of-line)
+ (let* ((element (org-element-at-point))
(type (org-element-type element))
(post-affiliated
(progn
@@ -20829,8 +20830,6 @@ meant to be filled."
(while (looking-at org-element--affiliated-re) (forward-line))
(point))))
(unless (< p post-affiliated)
- (goto-char p)
- (beginning-of-line)
(case type
(comment (looking-at "[ \t]*#\\+? ?") (match-string 0))
((item plain-list)
@@ -20840,12 +20839,13 @@ meant to be filled."
(paragraph
;; Fill prefix is usually the same as the current line,
;; except if the paragraph is at the beginning of an item.
- (let ((parent (cadr elements)))
- (if (eq (org-element-type parent) 'item)
- (make-string (org-list-item-body-column
- (org-element-property :begin parent))
- ? )
- (if (looking-at "\\s-+") (match-string 0) ""))))
+ (let ((parent (org-element-property :parent element)))
+ (cond ((eq (org-element-type parent) 'item)
+ (make-string (org-list-item-body-column
+ (org-element-property :begin parent))
+ ? ))
+ ((looking-at "\\s-+") (match-string 0))
+ (t ""))))
((comment-block verse-block)
;; Only fill contents if P is within block boundaries.
(let* ((cbeg (save-excursion (goto-char post-affiliated)
@@ -20939,6 +20939,7 @@ width for filling."
(skip-chars-backward " \r\t\n")
(line-beginning-position))
justify))) t)
+ ;; Fill comments, indented or not.
(comment
(let ((fill-prefix (org-fill-context-prefix (point))))
(save-excursion
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index 1f120d9..53b35cf 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -166,12 +166,100 @@ http://article.gmane.org/gmane.emacs.orgmode/21459/"
(org-fill-paragraph)
(buffer-string)))
"#+BEGIN_COMMENT\nSome text\n#+END_COMMENT"))
+ ;; Fill `comment' elements, indented or not.
+ (should
+ (equal "# A B"
+ (org-test-with-temp-text "# A\n#B"
+ (let ((fill-column 20))
+ (org-fill-paragraph)
+ (buffer-string)))))
+ (should
+ (equal " #+ A B"
+ (org-test-with-temp-text " #+ A\n #+ B"
+ (let ((fill-column 20))
+ (org-fill-paragraph)
+ (buffer-string)))))
;; Do nothing at affiliated keywords.
(org-test-with-temp-text "#+NAME: para\nSome\ntext."
(let ((fill-column 20))
(org-fill-paragraph)
(should (equal (buffer-string) "#+NAME: para\nSome\ntext.")))))
+(ert-deftest test-org/auto-fill-function ()
+ "Test auto-filling features."
+ ;; Auto fill paragraph.
+ (should
+ (equal "12345\n7890"
+ (org-test-with-temp-text "12345 7890"
+ (let ((fill-column 5))
+ (end-of-line)
+ (org-auto-fill-function)
+ (buffer-string)))))
+ ;; Auto fill first paragraph in an item.
+ (should
+ (equal "- 12345\n 7890"
+ (org-test-with-temp-text "- 12345 7890"
+ (let ((fill-column 7))
+ (end-of-line)
+ (org-auto-fill-function)
+ (buffer-string)))))
+ ;; Auto fill comments, indented or not.
+ (should
+ (equal "# 12345\n# 7890"
+ (org-test-with-temp-text "# 12345 7890"
+ (let ((fill-column 7))
+ (end-of-line)
+ (org-auto-fill-function)
+ (buffer-string)))))
+ (should
+ (equal " #+ 12345\n #+ 7890"
+ (org-test-with-temp-text " #+ 12345 7890"
+ (let ((fill-column 10))
+ (end-of-line)
+ (org-auto-fill-function)
+ (buffer-string)))))
+ ;; Verse and comment block: auto fill contents.
+ (should
+ (equal "#+BEGIN_VERSE\n12345\n7890\n#+END_VERSE"
+ (org-test-with-temp-text "#+BEGIN_VERSE\n12345 7890\n#+END_VERSE"
+ (let ((fill-column 5))
+ (forward-line)
+ (end-of-line)
+ (org-auto-fill-function)
+ (buffer-string)))))
+ (should
+ (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
+ (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
+ (let ((fill-column 5))
+ (forward-line)
+ (end-of-line)
+ (org-auto-fill-function)
+ (buffer-string)))))
+ ;; Do not fill if a new item could be created.
+ (should-not
+ (equal "12345\n- 90"
+ (org-test-with-temp-text "12345 - 90"
+ (let ((fill-column 5))
+ (end-of-line)
+ (org-auto-fill-function)
+ (buffer-string)))))
+ ;; Do not fill if a line break could be introduced.
+ (should-not
+ (equal "123\\\\\n7890"
+ (org-test-with-temp-text "123\\\\ 7890"
+ (let ((fill-column 6))
+ (end-of-line)
+ (org-auto-fill-function)
+ (buffer-string)))))
+ ;; Do not fill affiliated keywords.
+ (should-not
+ (equal "#+ATTR_LATEX: ABC\nDEFGHIJKL"
+ (org-test-with-temp-text "#+ATTR_LATEX: ABC DEFGHIJKL"
+ (let ((fill-column 20))
+ (end-of-line)
+ (org-auto-fill-function)
+ (buffer-string))))))
+
(provide 'test-org)