all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Tobias Gerdin <tgerdin@gmail.com>
To: Dmitry Gutov <dgutov@yandex.ru>, 32029@debbugs.gnu.org
Subject: bug#32029: [PATCH] xref-find-definitions-at-mouse
Date: Tue, 3 Jul 2018 23:37:23 +0200	[thread overview]
Message-ID: <ee9e1f4e-d599-2eab-006d-9ad13a7a2af9@gmail.com> (raw)
In-Reply-To: <cb06ef2b-4123-668d-79c1-7ea5cfba66c9@yandex.ru>

Den 2018-07-03 kl. 15:15, skrev Dmitry Gutov:

> On 7/2/18 2:18 AM, Tobias Gerdin wrote:
>
>> +;;;###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"))))
>
> You should call `mouse-set-point` before `xref-find-backend`, because 
> the latter might conceivably depend on the value of point.
>
> I think this can be written much shorter (call mouse-set-point, then 
> interactively call xref-find-definitions), but I'm not sure how.
A new version below. The initial version was modeled after 
`ffap-at-point`. Make using of call-interactively would be neat, but 
since we want to avoid making the call to xref-find-definitions inside 
the body of save-excursion I do not see how either (unless one woud 
actually move the point which I find a bit aggressive). I am not an 
overly experienced Elisp programmer so if you happen to come up with a 
way to do this I'm all ears. If not the below would do the job until then.

diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el
index 9a437b6f69..befebbb426 100644
--- a/lisp/progmodes/xref.el
+++ b/lisp/progmodes/xref.el
@@ -873,6 +873,16 @@ 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")
+  (if-let ((identifier (save-excursion
+             (mouse-set-point event)
+             (xref-backend-identifier-at-point (xref-find-backend)))))
+      (xref-find-definitions identifier)
+    (user-error "No identifier here")))
+
  (declare-function apropos-parse-pattern "apropos" (pattern))

  ;;;###autoload







  reply	other threads:[~2018-07-03 21:37 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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   ` Tobias Gerdin [this message]
2018-07-04  8:03     ` bug#32029: [PATCH] xref-find-definitions-at-mouse 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=ee9e1f4e-d599-2eab-006d-9ad13a7a2af9@gmail.com \
    --to=tgerdin@gmail.com \
    --cc=32029@debbugs.gnu.org \
    --cc=dgutov@yandex.ru \
    /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.