Browse Source

org-list-struct-apply-struct: Do not rely on `match-data' after edits

* lisp/org-list.el (org-list-struct-apply-struct): Refresh
`org-list-full-item-re' match data if we edit the bullet.  Fixes
https://orgmode.org/list/62cbc0f3.1c69fb81.13d5e.e250SMTPIN_ADDED_BROKEN@mx.google.com
* testing/lisp/test-org-list.el (test-org-list/indent-item): Add test
checking for the reported bug.
Ihor Radchenko 2 years ago
parent
commit
654005394b
2 changed files with 13 additions and 0 deletions
  1. 3 0
      lisp/org-list.el
  2. 10 0
      testing/lisp/test-org-list.el

+ 3 - 0
lisp/org-list.el

@@ -1953,6 +1953,9 @@ Initial position of cursor is restored after the changes."
                     (goto-char (match-end 1))
                     (insert-before-markers new-bul)
                     (insert keep-space))))
+              ;; Refresh potentially shifted match markers.
+              (goto-char item)
+              (looking-at org-list-full-item-re)
 	      ;; b.  Replace checkbox.
 	      (cond
 	       ((equal (match-string 3) new-box))

+ 10 - 0
testing/lisp/test-org-list.el

@@ -309,6 +309,16 @@
 	    (buffer-string))))
   (should
    (equal "
+- [ ] list item 1
+  + [ ] list item 2"
+          (org-test-with-temp-text "
+- [ ] list item 1
+- [ ] list item 2<point>"
+            (let ((org-list-demote-modify-bullet '(("-" . "+"))))
+              (org-indent-item)
+              (buffer-string)))))
+  (should
+   (equal "
 1. Item 1
    + Item 2"
 	  (org-test-with-temp-text "