emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/org 4e42500613: org.el: Fix the filling of regions cont


From: ELPA Syncer
Subject: [elpa] externals/org 4e42500613: org.el: Fix the filling of regions containing lists
Date: Mon, 4 Jul 2022 07:57:46 -0400 (EDT)

branch: externals/org
commit 4e425006130af1841b110a981c6e60f572311642
Author: Sébastien Miquel <sebastien.miquel@posteo.eu>
Commit: Sébastien Miquel <sebastien.miquel@posteo.eu>

    org.el: Fix the filling of regions containing lists
    
    * lisp/org.el (org-setup-filling): Set fill-forward-paragraph-function.
    (org--single-lines-list-is-paragraph): New internal variable.  Whether
    a list with single lines items should be considered a single
    paragraph.
    (org--paragraph-at-point): use org--single-lines-list-is-paragraph.
    (org-fill-paragraph): When an active region contains a list ensure
    every item get filled.
    * testing/lisp/test-org.el (test-org/fill-paragraph):
    (test-org/fill-region): Test behaviour of fill-paragraph and
    fill-region with an active region containing a list.
    
    When filling paragraphs in a region, do not treat a list with single
    lines items as a single paragraph.
---
 lisp/org.el              | 19 +++++++++++++++----
 testing/lisp/test-org.el | 41 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+), 4 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index 5b2b21f2db..38a50d2312 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -18709,6 +18709,8 @@ assumed to be significant there."
 ;; `org-setup-filling' installs filling and auto-filling related
 ;; variables during `org-mode' initialization.
 
+(defvar org--single-lines-list-is-paragraph) ; defined later
+
 (defun org-setup-filling ()
   (require 'org-element)
   ;; Prevent auto-fill from inserting unwanted new items.
@@ -18722,6 +18724,10 @@ assumed to be significant there."
     (setq-local paragraph-start paragraph-ending)
     (setq-local paragraph-separate paragraph-ending))
   (setq-local fill-paragraph-function 'org-fill-paragraph)
+  (setq-local fill-forward-paragraph-function
+              (lambda (&optional arg)
+                (let ((org--single-lines-list-is-paragraph nil))
+                  (org-forward-paragraph arg))))
   (setq-local auto-fill-inhibit-regexp nil)
   (setq-local adaptive-fill-function 'org-adaptive-fill-function)
   (setq-local normal-auto-fill-function 'org-auto-fill-function)
@@ -18951,9 +18957,11 @@ filling the current element."
            (progn
              (goto-char (region-end))
              (skip-chars-backward " \t\n")
-             (while (> (point) start)
-               (org-fill-element justify)
-               (org-backward-paragraph)))
+             (let ((org--single-lines-list-is-paragraph nil))
+                (while (> (point) start)
+                 (org-fill-element justify)
+                 (org-backward-paragraph)
+                  (skip-chars-backward " \t\n"))))
          (goto-char origin)
          (set-marker origin nil))))
      (t
@@ -20301,6 +20309,9 @@ It also provides the following special moves for 
convenience:
     ;; Return moves left.
     arg))
 
+(defvar org--single-lines-list-is-paragraph t
+  "Treat plain lists with single line items as a whole paragraph")
+
 (defun org--paragraph-at-point ()
   "Return paragraph, or equivalent, element at point.
 
@@ -20362,7 +20373,7 @@ Function may return a real element, or a pseudo-element 
with type
              (while (memq (org-element-type (org-element-property :parent l))
                           '(item plain-list))
                (setq l (org-element-property :parent l)))
-             (and l
+             (and l org--single-lines-list-is-paragraph
                   (org-with-point-at (org-element-property :post-affiliated l)
                     (forward-line (length (org-element-property :structure l)))
                     (= (point) (org-element-property :contents-end l)))
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index be8c896530..fcf2d0b5f9 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -765,8 +765,49 @@
              (push-mark (point) t t)
              (goto-char (point-max))
              (call-interactively #'org-fill-paragraph)
+             (buffer-string)))))
+  ;; Fill every list item in a region
+  (should
+   (equal "\n- 2345678\n  9\n- 2345678\n  9"
+         (org-test-with-temp-text "\n- 2345678 9\n- 2345678 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 "\n- 2345678\n  9\n- 2345678"
+         (org-test-with-temp-text "\n- 2345678 9\n- 2345678"
+           (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))))))
 
+(ert-deftest test-org/fill-region ()
+  "Test `fill-region' behaviour."
+  ;; fill-region should fill every item of a list
+  (should
+   (equal "\n- 2345678\n  9\n- 2345678\n  9"
+         (org-test-with-temp-text "\n- 2345678 9\n- 2345678 9"
+                                  (let ((fill-column 10))
+                                    (transient-mark-mode 1)
+                                    (push-mark (point-min) t t)
+                                    (goto-char (point-max))
+                                    (call-interactively #'fill-region)
+                                    (buffer-string)))))
+  (should
+   (equal "\n- 1 2\n- 1 2"
+         (org-test-with-temp-text "\n- 1\n  2\n- 1\n  2"
+                                  (let ((fill-column 10))
+                                    (transient-mark-mode 1)
+                                    (push-mark (point-min) t t)
+                                    (goto-char (point-max))
+                                    (call-interactively #'fill-region)
+                                    (buffer-string)))))  )
+
 (ert-deftest test-org/auto-fill-function ()
   "Test auto-filling features."
   ;; Auto fill paragraph.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]