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

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

[elpa] externals/org f7ef4071b2 1/3: org-list-struct-apply-struct: Fix i


From: ELPA Syncer
Subject: [elpa] externals/org f7ef4071b2 1/3: org-list-struct-apply-struct: Fix item contents breaking out of the item
Date: Wed, 10 Jul 2024 09:58:55 -0400 (EDT)

branch: externals/org
commit f7ef4071b208e20b1cc7d1ec534bac516d583930
Author: Ihor Radchenko <yantar92@posteo.net>
Commit: Ihor Radchenko <yantar92@posteo.net>

    org-list-struct-apply-struct: Fix item contents breaking out of the item
    
    * lisp/org-list.el (org-list-struct-apply-struct): Make sure that we
    never shift item contents to or before the item indentation.
    * testing/lisp/test-org-list.el (test-org-list/cycle-bullet): Add new
    test.
    
    Reported-by: vitalij@gmx.com
    Link: https://orgmode.org/list/871q42qbn7.fsf@gmx.com
---
 lisp/org-list.el              | 14 +++++++++-----
 testing/lisp/test-org-list.el |  9 ++++++++-
 2 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/lisp/org-list.el b/lisp/org-list.el
index 564bc31bc1..a3509abf96 100644
--- a/lisp/org-list.el
+++ b/lisp/org-list.el
@@ -1859,7 +1859,10 @@ Initial position of cursor is restored after the 
changes."
         (shift-body-ind
          ;; Shift the indentation between END and BEG by DELTA.
          ;; Start from the line before END.
-         (lambda (end beg delta)
+          ;; Take care not to shift to or before IND, which is the
+          ;; containg list item indentation. (otherwise, we are going
+          ;; to break the list structure)
+         (lambda (end beg delta ind)
            (goto-char end)
            (skip-chars-backward " \r\t\n")
            (forward-line 0)
@@ -1872,7 +1875,8 @@ Initial position of cursor is restored after the changes."
                (org-inlinetask-goto-beginning))
               ;; Shift only non-empty lines.
               ((looking-at-p "^[ \t]*\\S-")
-               (indent-line-to (+ (org-current-text-indentation) delta))))
+               (indent-line-to (max (+ (org-current-text-indentation) delta)
+                                     (if ind (1+ ind) -1)))))
              (forward-line -1))))
         (modify-item
          ;; Replace ITEM first line elements with new elements from
@@ -1934,7 +1938,7 @@ Initial position of cursor is restored after the changes."
               (ind-shift (- (+ ind-pos (length bul-pos))
                             (+ ind-old (length bul-old))))
               (end-pos (org-list-get-item-end pos old-struct)))
-         (push (cons pos ind-shift) itm-shift)
+         (push (list pos ind-shift ind-pos) itm-shift)
          (unless (assq end-pos old-struct)
            ;; To determine real ind of an ending position that
            ;; is not at an item, we have to find the item it
@@ -1956,7 +1960,7 @@ Initial position of cursor is restored after the changes."
               (down (car all-ends))
               (itemp (assq up struct))
               (delta
-               (if itemp (cdr (assq up itm-shift))
+               (if itemp (nth 1 (assq up itm-shift))
                  ;; If we're not at an item, there's a child of the
                  ;; item point belongs to above.  Make sure the less
                  ;; indented line in this slice has the same column
@@ -1982,7 +1986,7 @@ Initial position of cursor is restored after the changes."
                                                    down t)))))
                        (forward-line)))
                    (- ind min-ind)))))
-         (push (list down up delta) sliced-struct)))
+         (push (list down up delta (when itemp (nth 2 (assq up itm-shift)))) 
sliced-struct)))
       ;; 3. Shift each slice in buffer, provided delta isn't 0, from
       ;;    end to beginning.  Take a special action when beginning is
       ;;    at item bullet.
diff --git a/testing/lisp/test-org-list.el b/testing/lisp/test-org-list.el
index 0ee3a14c27..1eb7e02c30 100644
--- a/testing/lisp/test-org-list.el
+++ b/testing/lisp/test-org-list.el
@@ -267,7 +267,14 @@
       (should
        (if (or (< i 2) (= i 4))
            (should (= 4 (- (point) (line-beginning-position))))
-         (should (= 5 (- (point) (line-beginning-position)))))))))
+         (should (= 5 (- (point) (line-beginning-position))))))))
+  ;; Correctly handle edge case when cycling to shorter bullet may
+  ;; shift indentation to "0", breaking the item body out of the list.
+  (org-test-with-temp-text "
+1) text<point>
+ text"
+    (org-cycle-list-bullet)
+    (should (equal "\n- text\n text" (buffer-string)))))
 
 (ert-deftest test-org-list/indent-item ()
   "Test `org-indent-item' specifications."



reply via email to

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