Subject: bug#32029: closed (Re: bug#32029: [PATCH] xref-find-definitions-at-mouse)

From: [email-masked] (GNU bug Tracking System)
Date: Sat, 07 Jul 2018 09:03:02 +0000

Your bug report

#32029: PATCH: xref-find-definitions-at-mouse

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
32029: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=32029
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#32029: [PATCH] xref-find-definitions-at-mouse
From: Eli Zaretskii <[email-masked]>
To: Tobias Gerdin <[email-masked]>
Cc: [email-masked], [email-masked]
Date: Sat, 07 Jul 2018 12:02:43 +0300
List-Id: <debbugs-submit.debbugs.gnu.org>

> From: Tobias Gerdin <[email-masked]>
> Date: Tue, 3 Jul 2018 23:37:23 +0200
> 
> A new version below.

Thanks, pushed to the master branch.

Subject: PATCH: xref-find-definitions-at-mouse
From: Tobias Gerdin <[email-masked]>
To: [email-masked]
Date: Mon, 2 Jul 2018 01:18:50 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

Hello,

I find it convenient to be able to go to definitions using the mouse 
(especially when getting to know new code bases). I have the below 
function bound to C-mouse-1 like so:

(global-set-key [C-mouse-1] 'xref-find-definitions-at-mouse)
(global-set-key [C-down-mouse-1] nil)

I also find it convenient to be able to get back to where I was using 
only the mouse (enabling keyboard-free navigation):

(global-set-key [C-mouse-3] 'xref-pop-marker-stack)
(global-set-key [C-down-mouse-3] nil)

Finding suitable default keybindings (well, "mouse bindings") is beyond 
the scope of this patch, but what I have above is the same binding as 
other popular IDEs such as IntelliJ and VS Code.

Regards,

Tobias Gerdin

diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el
index 9a437b6f69..85a1bc6be4 100644
--- a/lisp/progmodes/xref.el
+++ b/lisp/progmodes/xref.el
@@ -873,6 +873,18 @@ With prefix argument, prompt for the identifier."
    (interactive (list (xref--read-identifier "Find references of: ")))
    (xref--find-xrefs identifier 'references identifier nil))

+;;;###autoload
+(defun xref-find-definitions-at-mouse (event)
+  "Find the definition of identifier around mouse click."
+  (interactive "e")
+  (let* ((backend (xref-find-backend))
+     (identifier (save-excursion
+              (mouse-set-point event)
+              (xref-backend-identifier-at-point backend))))
+    (if identifier
+    (xref--find-definitions identifier nil)
+      (user-error "No identifier here"))))
+
  (declare-function apropos-parse-pattern "apropos" (pattern))

  ;;;###autoload