GNU bug report logs - #71435
interactive xref-find-definitions-at-mouse

Previous Next

Package: emacs;

Reported by: Alan Donovan <adonovan <at> google.com>

Date: Sat, 8 Jun 2024 15:32:02 UTC

Severity: normal

Done: Stefan Kangas <stefankangas <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Philip Kaludercic <philipk <at> posteo.net>
To: Alan Donovan <adonovan <at> google.com>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 71435 <at> debbugs.gnu.org, stefankangas <at> gmail.com, juri <at> linkov.net
Subject: bug#71435: interactive xref-find-definitions-at-mouse
Date: Mon, 10 Jun 2024 17:43:38 +0000
Alan Donovan <adonovan <at> google.com> writes:

> I can reliably reproduce the problem using this script:
>
>
>
> ;; reproducer for use in emacs -Q:
> ;; invoke load-file on this file,
> ;; then follow the interactive steps at the very end.
>
> (emacs-version) ; 29.3
> (require 'eglot) ; 1.17.0
>
> ;; --- these steps are documented at
> ;;
> https://github.com/golang/tools/blob/master/gopls/doc/emacs.md#configuring-project-for-go-modules-in-emacs
>
> (require 'project) ; 0.11.0
>
> (defun project-find-go-module (dir)
>   (when-let ((root (locate-dominating-file dir "go.mod")))
>     (cons 'go-module root)))
>
> (cl-defmethod project-root ((project (head go-module)))
>   (cdr project))
>
> (add-hook 'project-find-functions #'project-find-go-module)
> ;; -----
>
> ; Use your favorite modifier; s is super, aka ⌘ key on Mac.
> (global-set-key (kbd "s-<mouse-1>") #'xref-find-definitions-at-mouse)
>
> ;; This file comes from github.com/dominikh/go-mode.el <at> master.
> (load-file "~/w/go-mode.el/go-mode.el")
>
> ;; Create a new Go buffer.
> (with-current-buffer (find-file "/tmp/a.go")
>   (eglot-ensure)
>   (insert "package main\n\nimport \"fmt\"\n\nfunc main()
> {\n\tfmt.Println()\n}\n")
>   (set-buffer (current-buffer)))
>
> ;; You should now be in a Go buffer in go-mode with eglot enabled.
> ;;
> ;; Now: position the point in "fmt", and then ⌘-click on "Println".
> ;; For me, Emacs navigates to the declaration of "fmt", not "Println".
> ;; The converse is true as well: with the point in Println,
> ;; a ⌘-click on fmt goes to the declaration of Println.

Given that I have a working Go setup installed, I tried this out: With
Emacs 30 on GNU/Linux fmt and Println both jump to the correct location.

The most recent commit might have fixed the issue you are having:

commit 128ed5c9f17fab87fdb679326035aa2598612658
Author: Dmitry Gutov <dmitry <at> gutov.dev>
Date:   Thu Aug 31 03:21:11 2023 +0300

    Add one more mouse-set-point call to functions xref-find-*-at-mouse
    
    * lisp/progmodes/xref.el (xref-find-definitions-at-mouse)
    (xref-find-references-at-mouse): Call mouse-set-point to ensure
    that the search is initiated at the same place where
    xref-backend-identifier-at-point was called (bug#65578).

diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el
index 3f75f8d7132..dbafa00c3ad 100644
--- a/lisp/progmodes/xref.el
+++ b/lisp/progmodes/xref.el
@@ -1638,7 +1638,9 @@ xref-find-definitions-at-mouse
            (mouse-set-point event)
            (xref-backend-identifier-at-point (xref-find-backend)))))
     (if identifier
-        (xref-find-definitions identifier)
+        (progn
+          (mouse-set-point event)
+          (xref-find-definitions identifier))
       (user-error "No identifier here"))))
 
 ;;;###autoload
@@ -1652,6 +1654,7 @@ xref-find-references-at-mouse
            (xref-backend-identifier-at-point (xref-find-backend)))))
     (if identifier
         (let ((xref-prompt-for-identifier nil))
+          (mouse-set-point event)
           (xref-find-references identifier))
       (user-error "No identifier here"))))
 
There is a more recent version of Xref on ELPA, could you try installing
that as well, and see if that changes anything?

> On Mon, 10 Jun 2024 at 11:23, Eli Zaretskii <eliz <at> gnu.org> wrote:
>
>> > From: Alan Donovan <adonovan <at> google.com>
>> > Date: Mon, 10 Jun 2024 10:39:04 -0400
>> > Cc: Juri Linkov <juri <at> linkov.net>, Stefan Kangas <stefankangas <at> gmail.com>,
>>
>> >       Eli Zaretskii <eliz <at> gnu.org>, 71435 <at> debbugs.gnu.org
>> >
>> > > ?? This works for me:
>> > >  (global-set-key [C-down-mouse-1] 'xref-find-definitions-at-mouse)
>> >
>> > Ah, I remember the problem now: if the point is at position A and the
>> mouse click occurs at some unrelated
>> > position B, plain old xref-find-definitions-at-mouse will use position A
>> as the basis of the query
>>
>> I cannot reproduce thus.  I just tried, and the mouse click shows the
>> definition of identifier at mouse click, not at point.
>>
>> > So perhaps my request should instead have been expressed as a bug
>> report: xref-find-definitions-at-mouse
>> > uses the point instead of the mouse event position.
>>
>> Please show a recipe for reproducing this, and please also tell what
>> version of Emacs are you using and on which platform.
>>
>> Thanks.
>>

-- 
	Philip Kaludercic on peregrine




This bug report was last modified 345 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.