From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ted Zlatanov Newsgroups: gmane.emacs.help Subject: Re: Eclipse-style control-click on Elisp function name to visit source Date: Fri, 06 May 2011 15:41:47 -0500 Organization: =?utf-8?B?0KLQtdC+0LTQvtGAINCX0LvQsNGC0LDQvdC+0LI=?= @ Cienfuegos Message-ID: <87r58btvck.fsf@lifelogs.com> References: <87vcxn7tkp.fsf@lifelogs.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1306268926 20169 80.91.229.12 (24 May 2011 20:28:46 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 24 May 2011 20:28:46 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue May 24 22:28:41 2011 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1QOyDY-00026t-FF for geh-help-gnu-emacs@m.gmane.org; Tue, 24 May 2011 22:28:40 +0200 Original-Received: from localhost ([::1]:52716 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QOyDX-00050d-UJ for geh-help-gnu-emacs@m.gmane.org; Tue, 24 May 2011 16:28:40 -0400 Original-Path: usenet.stanford.edu!news-transit.tcx.org.uk!news.albasani.net!.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 61 Original-X-Trace: news.albasani.net rcE6X6odCG9JaX2GeNm9e/J/hu7q92MpUKKWFXE97ny69qSoXljHe/P7iq3UxZCi0ek55OIZe3FbDJyqNaAbcA== Original-NNTP-Posting-Date: Fri, 6 May 2011 20:41:49 +0000 (UTC) Injection-Info: news.albasani.net; logging-data="RDmRmWCNHij00tzXetXhQMgKCEjXM7GDwrwY/ifQH9DuJ+qjoOmr7SQRUH/aqLUNp9L/SH1ZJCKEFQ2nDvzCoF3HYC/wif2YMXibs+P5OblyklOch9ftZBtg8gWMScvW"; mail-complaints-to="abuse@albasani.net" User-Agent: Gnus/5.110018 (No Gnus v0.18) Emacs/24.0.50 (gnu/linux) X-Face: bd.DQ~'29fIs`T_%O%C\g%6jW)yi[zuz6; d4V0`@y-~$#3P_Ng{@m+e4o<4P'#(_GJQ%TT= D}[Ep*b!\e,fBZ'j_+#"Ps?s2!4H2-Y"sx" Cancel-Lock: sha1:aszwRKiY9KYXLH+6PqjkjsPDgXs= sha1:MHaLw42IubQOrJNXeMPJtsOAqM8= Original-Xref: usenet.stanford.edu gnu.emacs.help:186803 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:81164 Archived-At: On Fri, 6 May 2011 17:20:28 +0000 (UTC) Alan Mackenzie wrote: AM> Ted Zlatanov 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 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