bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#46268: 27.1.91; Error in occur-rename-buffer


From: Juri Linkov
Subject: bug#46268: 27.1.91; Error in occur-rename-buffer
Date: Wed, 03 Feb 2021 10:54:24 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (x86_64-pc-linux-gnu)

Tags: patch
X-Debbugs-Cc: Stefan Monnier <monnier@iro.umontreal.ca>

After evaluating (add-hook 'occur-hook 'occur-rename-buffer)
then selecting a region, and running 'M-x occur' with any string
in the active region, signals the error:

  (wrong-type-argument bufferp #<overlay from 1 to 72 in *scratch*>)

It seems the attached patch is the right way to fix this.

Also Cc:ing Stefan with a question about occur--garbage-collect-revert-args:
trying to revert the Occur buffer created from an active region
removes the source buffer name from the Occur buffer name.
For example, (after applying the attached patch) 'M-x occur'
on the active region in *scratch* creates the buffer *Occur: *scratch**.

But reverting the Occur buffer with 'g' removes the *scratch* buffer name,
and renames the Occur buffer to *Occur: *.

This is because of two lines in occur-1:

          (occur--garbage-collect-revert-args)
          (setq occur-revert-arguments (list regexp nlines bufs))

where occur--garbage-collect-revert-args deletes the overlay
with the buffer name *scratch*, and later occur-rename-buffer
can't get the original buffer name from occur-revert-arguments.
And I don't know how to fix this.

diff --git a/lisp/replace.el b/lisp/replace.el
index f13d27aff8..c4c80118b4 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -1544,11 +1544,17 @@ occur-rename-buffer
   (interactive "P\np")
   (with-current-buffer
       (if (eq major-mode 'occur-mode) (current-buffer) (get-buffer "*Occur*"))
-    (rename-buffer (concat "*Occur: "
-                           (mapconcat #'buffer-name
-                                      (car (cddr occur-revert-arguments)) "/")
-                           "*")
-                   (or unique-p (not interactive-p)))))
+    (rename-buffer
+     (concat "*Occur: "
+             (mapconcat (lambda (boo)
+                          (or (and (buffer-live-p boo)
+                                   (buffer-name boo))
+                              (and (overlayp boo)
+                                   (buffer-live-p (overlay-buffer boo))
+                                   (buffer-name (overlay-buffer boo)))))
+                        (car (cddr occur-revert-arguments)) "/")
+             "*")
+     (or unique-p (not interactive-p)))))
 
 ;; Region limits when `occur' applies on a region.
 (defvar occur--final-pos nil)

reply via email to

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