bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


From: Tobias Gerdin
Subject: bug#32029: PATCH: xref-find-definitions-at-mouse
Date: Mon, 2 Jul 2018 01:18:50 +0200
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:52.0) Gecko/20100101 Thunderbird/52.8.0

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






reply via email to

[Prev in Thread] Current Thread [Next in Thread]