GNU bug report logs -
#32029
PATCH: xref-find-definitions-at-mouse
Previous Next
Reported by: Tobias Gerdin <tgerdin <at> gmail.com>
Date: Sun, 1 Jul 2018 23:52:01 UTC
Severity: wishlist
Done: Eli Zaretskii <eliz <at> gnu.org>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
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
This bug report was last modified 7 years and 35 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.