GNU bug report logs - #32029
PATCH: xref-find-definitions-at-mouse

Previous Next

Package: emacs;

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


Message #11 received at 32029 <at> debbugs.gnu.org (full text, mbox):

From: Tobias Gerdin <tgerdin <at> gmail.com>
To: Dmitry Gutov <dgutov <at> yandex.ru>, 32029 <at> debbugs.gnu.org
Subject: Re: bug#32029: [PATCH] xref-find-definitions-at-mouse
Date: Tue, 3 Jul 2018 23:37:23 +0200
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






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.