[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Eclipse-style control-click on Elisp function name to visit source
From: |
Ted Zlatanov |
Subject: |
Re: Eclipse-style control-click on Elisp function name to visit source |
Date: |
Tue, 24 May 2011 20:01:59 -0000 |
User-agent: |
Gnus/5.110018 (No Gnus v0.18) Emacs/24.0.50 (gnu/linux) |
On Fri, 6 May 2011 17:20:28 +0000 (UTC) Alan Mackenzie <acm@muc.de> wrote:
AM> Ted Zlatanov <tzz@lifelogs.com> wrote:
>> Right now, if I want to see the definition of a function, I do `C-h f'
>> to see the docstring, then RET on the link to the definition.
>> I'd like to bind that visit directly to `C-mouse-1' click on any
>> function name in any ELisp buffer, similar to how Eclipse does it for
>> Java code for instance. I couldn't find a way to do it in Emacs. Any
>> ideas? Or should I write it myself?
AM> I think you should write it yourself. Shouldn't be too difficult. The
AM> difficult bit is chosing a key binding (or a "mouse binding").
On Fri, 06 May 2011 14:28:51 -0300 Stefan Monnier <monnier@iro.umontreal.ca>
wrote:
SM> M-x find-function is pretty close.
The code below seems to do the job (I don't use the regular C-Mouse-1
binding that selects among the buffers).
I'd like to highlight valid symbols *only* (which would respond to one
of the handled conditions in `tzz-find-symbol-at-point') when the mouse
hovers over them but haven't done it. Otherwise this seems like a nice
feature for people who are used to the Eclipse style of finding
functions and variables, and could even be enabled by default in Emacs
or made into a package. I'm happy with it as it is, but if you find it
useful let me know and I'll make it fit for general consumption.
Thanks
Ted
#+begin_src lisp
(defun tzz-find-symbol-at-point ()
"Find the function, face, or variable definition for the symbol at point
in the other window."
(interactive)
(let ((symb (symbol-at-point)))
(cond
((and (or (functionp symb)
(fboundp symb))
(find-definition-noselect symb nil))
(find-function-other-window symb))
((and (facep symb) (find-definition-noselect symb 'defface))
(find-face-definition symb))
((and (boundp symb) (find-definition-noselect symb 'defvar))
(find-variable-other-window symb))
(t (message "No symbol at point")))))
(global-set-key [(control mouse-1)]
(lambda (click)
(interactive "e")
(mouse-minibuffer-check click)
(let* ((window (posn-window (event-start click)))
(buf (window-buffer window)))
(with-current-buffer buf
(save-excursion
(goto-char (posn-point (event-start click)))
(tzz-find-symbol-at-point))))))
#+end_src