1

I have been trying to add a custom keyboard command that will find a functions definition using S-mouse1.

The issue is that I need two mouse clicks for this to work. The first click is to move cursor to the function who's definition I want to find. The second click is the S-mouse-1 to trigger the function to find it's definition.

Here is what I have added to my .emacs:

(global-set-key (kbd "<S-mouse-1>")
            (lambda ()
              (interactive)
              (xref-find-definitions (thing-at-point 'word))))

An ideal solution would update point based on my mouse position and then use thing-at-point to pass the symbol into xref-find-definitions

I tried adding the following solution to my config without success: https://emacs.stackexchange.com/a/30856/21056

1 Answers1

1

You want something like:

(lambda (event)
  (interactive (list last-command-event))
  (posn-set-point (event-end event))
  (xref-find-definitions (thing-at-point 'word)))

In the case of mouse events, the event contains data about where the event took place, so you can use it to move point where the click happened.

Stefan
  • 26,154
  • 3
  • 46
  • 84
  • This works perfectly. Relatively new to elisp, so this helps a ton. I can't find much documentation on some of these functions. I found a little bit about `last-command-event` here https://www.gnu.org/software/emacs/manual/html_node/elisp/Command-Loop-Info.html And have not been able to any real documentation about `posn-set-point` other than this other SO answer: https://stackoverflow.com/a/36088695 Do you have any recommended resources for learning more about built in functions like these and elisp in general? – Priceatronic Dec 13 '18 at 05:15
  • 1
    @Priceatronic: My recommendation is to look at other functions doing the same kinds of things. – Stefan Dec 13 '18 at 14:18