Subject: bug#53626: 28.0.91; project-find-regexp (C-x p g) twice results in searching different projects

From: Dmitry Gutov <[email-masked]>
Date: Fri, 4 Feb 2022 04:32:44 +0200

On 30.01.2022 08:28, Sean Whitton wrote:
> These bindings hide the
> buffer-local value for default-directory in*xref*, such that
> xref--show-xref-buffer is only able to set the binding's value, not the
> real buffer-local value, and so when the let forms unwind*xref*'s old
> default-directory is restored.

I have to say I'm surprised by this mechanic: not even setq-local helps.

Guess we could kill the xref buffer every time, instead of erasing and 
re-filling it, though. Like

diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el
index 4efa652084..bb08db726b 100644
--- a/lisp/progmodes/xref.el
+++ b/lisp/progmodes/xref.el
@@ -1111,6 +1111,7 @@ xref--show-xref-buffer
           (xref-alist (xref--analyze xrefs))
           (dd default-directory)
           buf)
+    (ignore-errors (kill-buffer xref-buffer-name))
      (with-current-buffer (get-buffer-create xref-buffer-name)
        (setq default-directory dd)
        (xref--xref-buffer-mode)

It has the unfortunate side-effect of having that buffer displayed in a 
different window, though. Or at least the possibility (though it happens 
every time here).

Maybe some kill-but-recreate-and-show-in-the-same-window-first kind of 
hack would do the trick.