unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#32029: PATCH: xref-find-definitions-at-mouse
@ 2018-07-01 23:18 Tobias Gerdin
  2018-07-03 13:15 ` Dmitry Gutov
  0 siblings, 1 reply; 11+ messages in thread
From: Tobias Gerdin @ 2018-07-01 23:18 UTC (permalink / raw)
  To: 32029

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






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

end of thread, other threads:[~2018-07-07  9:04 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-07-01 23:18 bug#32029: PATCH: xref-find-definitions-at-mouse Tobias Gerdin
2018-07-03 13:15 ` Dmitry Gutov
2018-07-03 21:37   ` bug#32029: [PATCH] xref-find-definitions-at-mouse Tobias Gerdin
2018-07-04  8:03     ` Tobias Gerdin
2018-07-04 12:24       ` Dmitry Gutov
2018-07-04 15:17         ` Eli Zaretskii
2018-07-06  8:55     ` Eli Zaretskii
2018-07-06  9:03       ` Dmitry Gutov
2018-07-06 20:23         ` Tobias Gerdin
2018-07-07  9:04           ` Eli Zaretskii
2018-07-07  9:02     ` Eli Zaretskii

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).