all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Ted Zlatanov <tzz@lifelogs.com>
To: help-gnu-emacs@gnu.org
Subject: Re: Eclipse-style control-click on Elisp function name to visit source
Date: Fri, 06 May 2011 15:41:47 -0500	[thread overview]
Message-ID: <87r58btvck.fsf@lifelogs.com> (raw)
In-Reply-To: iq1aks$l7c$1@colin2.muc.de

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


  reply	other threads:[~2011-05-06 20:41 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-06 15:11 Eclipse-style control-click on Elisp function name to visit source Ted Zlatanov
2011-05-06 17:20 ` Alan Mackenzie
2011-05-06 20:41   ` Ted Zlatanov [this message]
2011-05-06 17:28 ` Stefan Monnier
2011-05-07 17:56   ` Vagn Johansen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87r58btvck.fsf@lifelogs.com \
    --to=tzz@lifelogs.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.