Prevent filling before a "n" macro where it could create list items

* lisp/org.el (org-fill-n-macro-as-item-nobreak-p): New function.
(org-setup-filling): Use new function.

* testing/lisp/test-org.el (test-org/fill-element): Add tests.

Reported-by: Kaushal Modi <kaushal.modi@gmail.com>
<http://permalink.gmane.org/gmane.emacs.orgmode/113587>
This commit is contained in:
Nicolas Goaziou 2017-05-22 15:36:28 +02:00
parent ad89390219
commit 957850043a
2 changed files with 41 additions and 5 deletions

View File

@ -22905,6 +22905,7 @@ assumed to be significant there."
(org-uniquify
(append fill-nobreak-predicate
'(org-fill-line-break-nobreak-p
org-fill-n-macro-as-item-nobreak-p
org-fill-paragraph-with-timestamp-nobreak-p)))))
(let ((paragraph-ending (substring org-element-paragraph-separate 1)))
(setq-local paragraph-start paragraph-ending)
@ -22927,6 +22928,12 @@ assumed to be significant there."
(and (org-at-timestamp-p 'lax)
(not (looking-at org-ts-regexp-both))))
(defun org-fill-n-macro-as-item-nobreak-p ()
"Non-nil when a new line at point would create a new list."
;; During export, a "n" macro followed by a dot or a closing
;; parenthesis can end up being parsed as a new list item.
(looking-at-p "[ \t]*{{{n\\(?:([^\n)]*)\\)?}}}[.)]\\(?:$\\| \\)"))
(declare-function message-in-body-p "message" ())
(defvar orgtbl-line-start-regexp) ; From org-table.el
(defun org-adaptive-fill-function ()

View File

@ -565,16 +565,45 @@
(org-fill-element)
(buffer-string)))))
;; Do nothing at affiliated keywords.
(org-test-with-temp-text "#+NAME: para\nSome\ntext."
(let ((fill-column 20))
(org-fill-element)
(should (equal (buffer-string) "#+NAME: para\nSome\ntext."))))
(should
(equal "#+NAME: para\nSome\ntext."
(org-test-with-temp-text "#+NAME: para\nSome\ntext."
(let ((fill-column 20))
(org-fill-element)
(buffer-string)))))
;; Do not move point after table when filling a table.
(should-not
(org-test-with-temp-text "| a | b |\n| c | d |\n"
(forward-char)
(org-fill-element)
(eobp))))
(eobp)))
;; Do not fill "n" macro, with or without arguments, followed by
;; a dot or a closing parenthesis since it could be confused with
;; a numbered bullet.
(should-not
(equal "123456789\n{{{n}}}."
(org-test-with-temp-text "123456789 {{{n}}}."
(let ((fill-column 10))
(org-fill-element)
(buffer-string)))))
(should-not
(equal "123456789\n{{{n}}}\)"
(org-test-with-temp-text "123456789 {{{n}}}\)"
(let ((fill-column 10))
(org-fill-element)
(buffer-string)))))
(should-not
(equal "123456789\n{{{n()}}}."
(org-test-with-temp-text "123456789 {{{n()}}}."
(let ((fill-column 10))
(org-fill-element)
(buffer-string)))))
(should-not
(equal "123456789\n{{{n(counter)}}}."
(org-test-with-temp-text "123456789 {{{n(counter)}}}."
(let ((fill-column 10))
(org-fill-element)
(buffer-string))))))
(ert-deftest test-org/auto-fill-function ()
"Test auto-filling features."