master ea6e7a01f97: Fix bug when looping over intervals in another buffer (Bug#81652)

Philipp Stephani <[email protected]>
Newsgroups gmane.emacs.diffs
Message-ID <[email protected]>
branch: master
commit ea6e7a01f978979cd2040b66c4f2868542f327f3
Author: Philipp Stephani <[email protected]>
Commit: Philipp Stephani <[email protected]>

    Fix bug when looping over intervals in another buffer (Bug#81652)
    
    * lisp/emacs-lisp/cl-extra.el (cl--map-intervals): Add missing
    BUFFER argument to 'set-marker' calls (Bug#81652).
    
    * test/lisp/emacs-lisp/cl-macs-tests.el
    (cl-macs-loop-being-intervals/current-buffer)
    (cl-macs-loop-being-intervals/new-buffer): New regression tests.
---
 lisp/emacs-lisp/cl-extra.el           |  5 +++--
 test/lisp/emacs-lisp/cl-macs-tests.el | 17 ++++++++++++++++-
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/lisp/emacs-lisp/cl-extra.el b/lisp/emacs-lisp/cl-extra.el
index 25c5eaa1204..2a3e2ffe16d 100644
--- a/lisp/emacs-lisp/cl-extra.el
+++ b/lisp/emacs-lisp/cl-extra.el
@@ -281,9 +281,10 @@ non-nil value.
                 next2 (or next (with-current-buffer what
                                  (point-max))))
           (funcall func (prog1 (marker-position mark)
-                          (set-marker mark next2))
+                          (set-marker mark next2 what))
                    (if mark2 (min next2 mark2) next2)))
-        (set-marker mark nil) (if mark2 (set-marker mark2 nil)))
+        (set-marker mark nil what)
+        (if mark2 (set-marker mark2 nil what)))
     (or start (setq start 0))
     (or end (setq end (length what)))
     (while (< start end)
diff --git a/test/lisp/emacs-lisp/cl-macs-tests.el b/test/lisp/emacs-lisp/cl-macs-tests.el
index 9c152a2fef5..2d764f800ed 100644
--- a/test/lisp/emacs-lisp/cl-macs-tests.el
+++ b/test/lisp/emacs-lisp/cl-macs-tests.el
@@ -482,11 +482,26 @@ collection clause."
                               return (overlay-get o 'prop)))
                  "test")))
 
+(ert-deftest cl-macs-loop-being-intervals/current-buffer ()
+  (should (equal (with-temp-buffer
+                   (insert "foo" (propertize "bar" 'prop t))
+                   (cl-loop for i being the intervals collect i))
+                 '((1 . 4) (4 . 7)))))
+
+(ert-deftest cl-macs-loop-being-intervals/new-buffer ()
+  (should (equal (with-temp-buffer
+                   (insert "foo" (propertize "bar" 'prop t))
+                   (let ((buffer (current-buffer)))
+                     (with-temp-buffer
+                       (cl-loop for i being the intervals of buffer
+                                collect i))))
+                 '((1 . 4) (4 . 7)))))
+
 (ert-deftest cl-macs-loop-being-frames ()
   (should (eq (cl-loop with selected = (selected-frame)
                        for frame being the frames
                        when (eq frame selected)
-                         return frame)
+                       return frame)
               (selected-frame))))
 
 (ert-deftest cl-macs-loop-being-windows ()
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.