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 Answer 1

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.

2
  • 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 gnu.org/software/emacs/manual/html_node/elisp/… And have not been able to any real documentation about posn-set-point other than this other SO answer: stackoverflow.com/a/36088695 Do you have any recommended resources for learning more about built in functions like these and elisp in general? Dec 13, 2018 at 5:15
  • 1
    @Priceatronic: My recommendation is to look at other functions doing the same kinds of things.
    – Stefan
    Dec 13, 2018 at 14:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.