diff options
author | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2020-07-07 10:37:35 +0200 |
---|---|---|
committer | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2020-07-07 10:37:35 +0200 |
commit | 353e8cc2b721c720d283a5dae0078fc27893d349 (patch) | |
tree | c657e786b0862d1da1c0119611b9499ebbf75ade | |
parent | ab864a29bea00d54ece19d4095de58fc0c6f6724 (diff) | |
download | org-mode-353e8cc2b721c720d283a5dae0078fc27893d349.tar.gz |
Fix paragraph filling
* lisp/org.el (org-fill-paragraph): Fix regression introduced in
e2b62b4da8839106bbfedeb778e4ad4b40164964.
* 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>
-rw-r--r-- | lisp/org.el | 12 | ||||
-rw-r--r-- | testing/lisp/test-org.el | 57 |
2 files changed, 66 insertions, 3 deletions
diff --git a/lisp/org.el b/lisp/org.el index 748c058..4a1a83d 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -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". diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el index 3c563f3..30a8067 100644 --- a/testing/lisp/test-org.el +++ b/testing/lisp/test-org.el @@ -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. |