Fix paragraph filling

* lisp/org.el (org-fill-paragraph): Fix regression introduced in
e2b62b4da8.
* testing/lisp/test-org.el (test-org/fill-paragraph): New test.

Reported-by: stardiviner <numbchild@gmail.com>
<http://lists.gnu.org/r/emacs-orgmode/2020-07/msg00065.html>
This commit is contained in:
Nicolas Goaziou 2020-07-07 10:37:35 +02:00
parent ab864a29be
commit 353e8cc2b7
2 changed files with 66 additions and 3 deletions

View File

@ -19361,12 +19361,18 @@ filling the current element."
(unwind-protect
(progn
(goto-char (region-end))
(skip-chars-backward " \t\n")
(while (> (point) start)
(org-backward-paragraph)
(org-fill-element justify)))
(org-fill-element justify)
(org-backward-paragraph))
(org-fill-element justify))
(goto-char origin)
(set-marker origin nil))))
(t (org-fill-element justify)))
(t
(save-excursion
(when (org-match-line "[ \t]*$")
(skip-chars-forward " \t\n"))
(org-fill-element justify))))
;; If we didn't change anything in the buffer (and the buffer was
;; previously unmodified), then flip the modification status back
;; to "unchanged".

View File

@ -697,6 +697,63 @@
(org-fill-element)
(buffer-string))))))
(ert-deftest test-org/fill-paragraph ()
"Test `org-fill-paragraph' specifications."
;; Regular test.
(should
(equal "012345678\n9"
(org-test-with-temp-text "012345678 9"
(let ((fill-column 10))
(org-fill-paragraph)
(buffer-string)))))
;; Fill paragraph even at end of buffer.
(should
(equal "012345678\n9\n"
(org-test-with-temp-text "012345678 9\n<point>"
(let ((fill-column 10))
(org-fill-paragraph)
(buffer-string)))))
;; Between two paragraphs, fill the next one.
(should
(equal "012345678 9\n\n012345678\n9"
(org-test-with-temp-text "012345678 9\n<point>\n012345678 9"
(let ((fill-column 10))
(org-fill-paragraph)
(buffer-string)))))
(should
(equal "012345678\n9\n\n012345678 9"
(org-test-with-temp-text "012345678 9<point>\n\n012345678 9"
(let ((fill-column 10))
(org-fill-paragraph)
(buffer-string)))))
;; Fill paragraph in a comment block.
(should
(equal "#+begin_comment\n012345678\n9\n#+end_comment"
(org-test-with-temp-text
"#+begin_comment\n<point>012345678 9\n#+end_comment"
(let ((fill-column 10))
(org-fill-paragraph)
(buffer-string)))))
;; When a region is selected, fill every paragraph in the region.
(should
(equal "012345678\n9\n\n012345678\n9"
(org-test-with-temp-text "012345678 9\n\n012345678 9"
(let ((fill-column 10))
(transient-mark-mode 1)
(push-mark (point-min) t t)
(goto-char (point-max))
(call-interactively #'org-fill-paragraph)
(buffer-string)))))
(should
(equal "012345678\n9\n\n012345678 9"
(org-test-with-temp-text "012345678 9\n<point>\n012345678 9"
(let ((fill-column 10))
(transient-mark-mode 1)
(push-mark (point) t t)
(goto-char (point-min))
(call-interactively #'org-fill-paragraph)
(buffer-string))))))
(ert-deftest test-org/auto-fill-function ()
"Test auto-filling features."
;; Auto fill paragraph.