all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Tobias Gerdin <tgerdin@gmail.com>
To: 32029@debbugs.gnu.org
Subject: bug#32029: PATCH: xref-find-definitions-at-mouse
Date: Mon, 2 Jul 2018 01:18:50 +0200	[thread overview]
Message-ID: <9af0d021-361d-ccc6-a051-f102589bccb7@gmail.com> (raw)

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	other threads:[~2018-07-01 23:18 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-01 23:18 Tobias Gerdin [this message]
2018-07-03 13:15 ` bug#32029: PATCH: xref-find-definitions-at-mouse 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
     [not found]         ` <528d74b1-c346-006f-2005-6ad78390ce1d@gmail.com>
2018-07-05 14:00           ` Dmitry Gutov
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9af0d021-361d-ccc6-a051-f102589bccb7@gmail.com \
    --to=tgerdin@gmail.com \
    --cc=32029@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.