]> git.eshelyaron.com Git - emacs.git/commitdiff
Unbreak 'revert-buffer' in Occur buffers
authorEli Zaretskii <eliz@gnu.org>
Tue, 9 Oct 2018 14:46:31 +0000 (17:46 +0300)
committerEli Zaretskii <eliz@gnu.org>
Tue, 9 Oct 2018 14:46:31 +0000 (17:46 +0300)
* lisp/replace.el (occur-revert-function): Use the value of
occur-revert-function from the correct buffer.  (Bug#32987)

* test/lisp/replace-tests.el (replace-occur-revert-bug32543)
(replace-occur-revert-bug32987): New tests.

lisp/replace.el
test/lisp/replace-tests.el

index 00b2ceee356a757054538cc24fa6eab096fd0be6..04e5d4273e03239267facc53401b471de2a9014f 100644 (file)
@@ -1226,14 +1226,14 @@ the user called `occur'."
     (pcase-let ((`(,region-start ,region-end ,orig-line ,buffer)
                  (occur--parse-occur-buffer))
                 (regexp (car occur-revert-arguments)))
-      (with-current-buffer buffer
-        (when (wholenump orig-line)
-          (goto-char (point-min))
-          (forward-line (1- orig-line)))
-        (save-excursion
-          (if (or region-start region-end)
-              (occur regexp nil (list (cons region-start region-end)))
-            (apply 'occur-1 (append occur-revert-arguments (list (buffer-name))))))))))
+      (if (not (or region-start region-end))
+          (apply 'occur-1 (append occur-revert-arguments (list (buffer-name))))
+        (with-current-buffer buffer
+          (when (wholenump orig-line)
+            (goto-char (point-min))
+            (forward-line (1- orig-line)))
+          (save-excursion
+            (occur regexp nil (list (cons region-start region-end)))))))))
 
 (defun occur-mode-find-occurrence ()
   (let ((pos (get-text-property (point) 'occur-target)))
index 3fcdce6704fdaa9e75e483cdc70f5111cfd568ff..5a91a2cc7f68d852e69ae066ba37308bae72040b 100644 (file)
@@ -359,6 +359,52 @@ Each element has the format:
 (dotimes (i (length replace-occur-tests))
   (replace-occur-test-create i))
 
+(ert-deftest replace-occur-revert-bug32543 ()
+  "Test `occur-revert' with non-nil `list-matching-lines-jump-to-current-line'."
+  (let ((temp-buffer (get-buffer-create " *test-occur*")))
+    (unwind-protect
+        (save-window-excursion
+          (with-current-buffer temp-buffer
+            (erase-buffer)
+            (setq list-matching-lines-jump-to-current-line t)
+            (insert
+";; This buffer is for text that is not saved, and for Lisp evaluation.
+;; To create a file, visit it with C-x C-f and enter text in its buffer.
+
+")
+            (occur "and")
+            (with-current-buffer "*Occur*"
+              (revert-buffer)
+              (goto-char (point-min))
+              (should (string-match "\\`2 matches for \"and\" in buffer: "
+                                    (buffer-substring-no-properties
+                                     (point) (line-end-position)))))))
+      (and (buffer-name temp-buffer)
+           (kill-buffer temp-buffer)))))
+
+(ert-deftest replace-occur-revert-bug32987 ()
+  "Test `occur-revert' with non-nil `list-matching-lines-jump-to-current-line'."
+  (let ((temp-buffer (get-buffer-create " *test-occur*")))
+    (unwind-protect
+        (save-window-excursion
+          (with-current-buffer temp-buffer
+            (erase-buffer)
+            (setq list-matching-lines-jump-to-current-line nil)
+            (insert
+";; This buffer is for text that is not saved, and for Lisp evaluation.
+;; To create a file, visit it with C-x C-f and enter text in its buffer.
+
+")
+            (occur "and")
+            (with-current-buffer "*Occur*"
+              (revert-buffer)
+              (goto-char (point-min))
+              (should (string-match "\\`2 matches for \"and\" in buffer: "
+                                    (buffer-substring-no-properties
+                                     (point) (line-end-position)))))))
+      (and (buffer-name temp-buffer)
+           (kill-buffer temp-buffer)))))
+
 \f
 ;;; Tests for `query-replace' undo feature.
 
@@ -454,5 +500,4 @@ Return the last evalled form in BODY."
       input "a" "B" ((?\s . (1 2 3)) (?E . (4)) (?U . (5))) ?q
       (string= input (buffer-string))))))
 
-
 ;;; replace-tests.el ends here