diff options
author | Nicolas Goaziou <n.goaziou@gmail.com> | 2013-07-09 13:49:17 +0200 |
---|---|---|
committer | Nicolas Goaziou <n.goaziou@gmail.com> | 2013-07-09 13:52:00 +0200 |
commit | c78fa35252762f3b085fd987d5e8c161546c82ee (patch) | |
tree | 2e35243c4e5561369d3d3ca5ccb735cf65964247 | |
parent | eb37142b14fba90e492ef910026bcadfa5b0aa9b (diff) | |
download | org-mode-c78fa35252762f3b085fd987d5e8c161546c82ee.tar.gz |
Fix error when filling consecutive comments
* lisp/org.el (org-fill-paragraph): Do not mix consecutive comments
when filling any of them.
* testing/lisp/test-org.el: Add test.
Thanks to Samuel Wales for reporting it.
-rw-r--r-- | lisp/org.el | 16 | ||||
-rw-r--r-- | testing/lisp/test-org.el | 7 |
2 files changed, 22 insertions, 1 deletions
diff --git a/lisp/org.el b/lisp/org.el index 331365a..5be295d 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -22287,7 +22287,21 @@ a footnote definition, try to fill the first paragraph within." justify))) t) ;; Fill comments. - (comment (fill-comment-paragraph justify)) + (comment + (let ((begin (org-element-property :post-affiliated element)) + (end (save-excursion + (goto-char (org-element-property :end element)) + (skip-chars-backward " \r\t\n") + (line-end-position)))) + ;; Do not fill comments when at a blank line or at + ;; affiliated keywords. + (when (and (>= (point) begin) (<= (point) end)) + (let ((fill-prefix (save-excursion + (beginning-of-line) + (looking-at "[ \t]*#") + (concat (match-string 0) " ")))) + (save-excursion + (fill-region-as-paragraph begin end justify)))))) ;; Ignore every other element. (otherwise t)))))) diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el index 259dc04..b7a6009 100644 --- a/testing/lisp/test-org.el +++ b/testing/lisp/test-org.el @@ -199,6 +199,13 @@ (let ((fill-column 20)) (org-fill-paragraph) (buffer-string))))) + ;; Do not mix consecutive comments when filling one of them. + (should + (equal "# A B\n\n# C" + (org-test-with-temp-text "# A\n# B\n\n# C" + (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)) |