unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#46268: 27.1.91; Error in occur-rename-buffer
@ 2021-02-03  8:54 Juri Linkov
  2021-02-03 15:05 ` Stefan Monnier
  2021-02-03 15:22 ` Stefan Monnier
  0 siblings, 2 replies; 7+ messages in thread
From: Juri Linkov @ 2021-02-03  8:54 UTC (permalink / raw)
  To: 46268; +Cc: stefan monnier

[-- Attachment #1: Type: text/plain, Size: 1191 bytes --]

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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: occur-rename-buffer-overlay.patch --]
[-- Type: text/x-diff, Size: 1167 bytes --]

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)

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-02-03 19:41 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-03  8:54 bug#46268: 27.1.91; Error in occur-rename-buffer Juri Linkov
2021-02-03 15:05 ` Stefan Monnier
2021-02-03 15:38   ` Stefan Monnier
2021-02-03 17:34     ` Juri Linkov
2021-02-03 15:22 ` Stefan Monnier
2021-02-03 17:36   ` Juri Linkov
2021-02-03 19:41     ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).