all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* xref call project-current in correct buffer
@ 2022-11-15 18:49 Stephen Leake
  2022-11-15 20:10 ` Eli Zaretskii
  2022-11-15 21:37 ` Stephen Leake
  0 siblings, 2 replies; 5+ messages in thread
From: Stephen Leake @ 2022-11-15 18:49 UTC (permalink / raw)
  To: emacs-devel

I ran into a situation where xref failed because
xref-show-definitions-buffer-at-bottom calls project-current in the
*xref* buffer, not the original source buffer, and the project in that
buffer is different from the one in the *xref* buffer.

The attached patch fixes it, but there are other possible ways to do it;
pass the project to xref--analyze, or set a local variable containing
the project.

In addition, refresh-buffer in the *xref* buffer will have the same
problem, so setting the original project in a local variable might be
the best way.

-- 
-- Stephe



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

* Re: xref call project-current in correct buffer
  2022-11-15 18:49 xref call project-current in correct buffer Stephen Leake
@ 2022-11-15 20:10 ` Eli Zaretskii
  2022-11-15 21:37 ` Stephen Leake
  1 sibling, 0 replies; 5+ messages in thread
From: Eli Zaretskii @ 2022-11-15 20:10 UTC (permalink / raw)
  To: Stephen Leake; +Cc: emacs-devel

> From: Stephen Leake <stephen_leake@stephe-leake.org>
> Date: Tue, 15 Nov 2022 10:49:53 -0800
> 
> I ran into a situation where xref failed because
> xref-show-definitions-buffer-at-bottom calls project-current in the
> *xref* buffer, not the original source buffer, and the project in that
> buffer is different from the one in the *xref* buffer.
> 
> The attached patch fixes it

ENOPATCH



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

* Re: xref call project-current in correct buffer
  2022-11-15 18:49 xref call project-current in correct buffer Stephen Leake
  2022-11-15 20:10 ` Eli Zaretskii
@ 2022-11-15 21:37 ` Stephen Leake
  2022-11-15 21:48   ` Dmitry Gutov
  1 sibling, 1 reply; 5+ messages in thread
From: Stephen Leake @ 2022-11-15 21:37 UTC (permalink / raw)
  To: emacs-devel

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

Actually attach the patch

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: xref.diff --]
[-- Type: text/x-patch, Size: 990 bytes --]

diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el
index bb36688ef8..2d73ab82b8 100644
--- a/lisp/progmodes/xref.el
+++ b/lisp/progmodes/xref.el
@@ -1243,10 +1243,14 @@ xref-show-definitions-buffer-at-bottom
       (xref-pop-to-location (car xrefs)
                             (assoc-default 'display-action alist)))
      (t
+      ;; xref--analyze uses (project-current), so it must be done in
+      ;; the original buffer.
+      (setq xrefs (xref--analyze xrefs))
+
       (with-current-buffer (get-buffer-create xref-buffer-name)
         (xref--ensure-default-directory dd (current-buffer))
         (xref--transient-buffer-mode)
-        (xref--show-common-initialize (xref--analyze xrefs) fetcher alist)
+        (xref--show-common-initialize xrefs fetcher alist)
         (pop-to-buffer (current-buffer)
                        `(display-buffer-in-direction . ((direction . below)
                                                         (window-height . ,size-fun))))

[-- Attachment #3: Type: text/plain, Size: 647 bytes --]


Stephen Leake <stephen_leake@stephe-leake.org> writes:

> I ran into a situation where xref failed because
> xref-show-definitions-buffer-at-bottom calls project-current in the
> *xref* buffer, not the original source buffer, and the project in that
> buffer is different from the one in the *xref* buffer.
>
> The attached patch fixes it, but there are other possible ways to do it;
> pass the project to xref--analyze, or set a local variable containing
> the project.
>
> In addition, refresh-buffer in the *xref* buffer will have the same
> problem, so setting the original project in a local variable might be
> the best way.

-- 
-- Stephe

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

* Re: xref call project-current in correct buffer
  2022-11-15 21:37 ` Stephen Leake
@ 2022-11-15 21:48   ` Dmitry Gutov
  2022-11-15 21:55     ` Dmitry Gutov
  0 siblings, 1 reply; 5+ messages in thread
From: Dmitry Gutov @ 2022-11-15 21:48 UTC (permalink / raw)
  To: Stephen Leake, emacs-devel

On 15.11.2022 23:37, Stephen Leake wrote:
> +      ;; xref--analyze uses (project-current), so it must be done in
> +      ;; the original buffer.
> +      (setq xrefs (xref--analyze xrefs))

LGTM, thanks!

Maybe change the comment from "uses" to "can use" (or "might"), because 
that only happens with the currently default value of 
xref-file-name-display. Or not. That's a very minor detail.



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

* Re: xref call project-current in correct buffer
  2022-11-15 21:48   ` Dmitry Gutov
@ 2022-11-15 21:55     ` Dmitry Gutov
  0 siblings, 0 replies; 5+ messages in thread
From: Dmitry Gutov @ 2022-11-15 21:55 UTC (permalink / raw)
  To: Stephen Leake, emacs-devel

On 15.11.2022 23:48, Dmitry Gutov wrote:
> On 15.11.2022 23:37, Stephen Leake wrote:
>> +      ;; xref--analyze uses (project-current), so it must be done in
>> +      ;; the original buffer.
>> +      (setq xrefs (xref--analyze xrefs))
> 
> LGTM, thanks!
> 
> Maybe change the comment from "uses" to "can use" (or "might"), because 
> that only happens with the currently default value of 
> xref-file-name-display. Or not. That's a very minor detail.

Actually, how about this one?

The difference is slight, but we don't reuse a variable for a value with 
different structure, and it mirrors the same variable in related/similar 
functions in this package.

diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el
index 0213ab3cc5..3e04291bc3 100644
--- a/lisp/progmodes/xref.el
+++ b/lisp/progmodes/xref.el
@@ -1230,16 +1230,20 @@ xref-show-definitions-buffer-at-bottom
           (max-height (/ (window-height) 2))
           (size-fun (lambda (window)
                       (fit-window-to-buffer window max-height)))
+         xref-alist
           buf)
      (cond
       ((not (cdr xrefs))
        (xref-pop-to-location (car xrefs)
                              (assoc-default 'display-action alist)))
       (t
+      ;; Call it here because it can call (project-current), and that
+      ;; might depend on individual buffer, not just directory.
+      (setq xref-alist (xref--analyze xrefs))
        (with-current-buffer (get-buffer-create xref-buffer-name)
          (xref--ensure-default-directory dd (current-buffer))
          (xref--transient-buffer-mode)
-        (xref--show-common-initialize (xref--analyze xrefs) fetcher alist)
+        (xref--show-common-initialize xref-alist fetcher alist)
          (pop-to-buffer (current-buffer)
                         `(display-buffer-in-direction . ((direction . 
below)
                                                          (window-height 
. ,size-fun))))




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

end of thread, other threads:[~2022-11-15 21:55 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-15 18:49 xref call project-current in correct buffer Stephen Leake
2022-11-15 20:10 ` Eli Zaretskii
2022-11-15 21:37 ` Stephen Leake
2022-11-15 21:48   ` Dmitry Gutov
2022-11-15 21:55     ` Dmitry Gutov

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.