Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

elisp programming - navigate through code?

15 views
Skip to first unread message

Martin

unread,
Mar 29, 2014, 12:49:48 PM3/29/14
to GNU Emacs users list
Hi there,

This is now specially for elisp, but maybe its possible for other things to
(ruby on rails - ruby, javascript, coffeescript, ...)

Is there a way to navigate better through my code.

like having a function (foo arg1 arg2) putting the cursor to foo will
C-h f suggest I want to read the docstring for that. Thats good.

But now I'd like to navigate to the definition (which can be in the same
buffer or somewhere else). Is that possbile?

Thanks,
Martin



Thorsten Jolitz

unread,
Mar 29, 2014, 1:17:38 PM3/29/14
to help-gn...@gnu.org
you can use tags

,--------------------------------------------------------------------
| http://www.gnu.org/software/emacs/manual/html_node/eintr/etags.html
`--------------------------------------------------------------------

or a function like this:

,---------------------------------------------------
| ;; jumps to the source of the symbol at point
| (defun tj/goto-symbol-definition ()
| "jump to the source of the symbol at point."
| (interactive)
| (require 'finder)
| (let ((thing (intern (thing-at-point 'symbol))))
| (if (functionp thing)
| (find-function thing)
| (find-variable thing))))
`---------------------------------------------------

--
cheers,
Thorsten


Michael Heerdegen

unread,
Mar 29, 2014, 2:10:26 PM3/29/14
to help-gn...@gnu.org
Hi Martin,

> This is now specially for elisp, but maybe its possible for other
> things to
> (ruby on rails - ruby, javascript, coffeescript, ...)
>
> Is there a way to navigate better through my code.
>
> like having a function (foo arg1 arg2) putting the cursor to foo will
> C-h f suggest I want to read the docstring for that. Thats good.
>
> But now I'd like to navigate to the definition (which can be in the same
> buffer or somewhere else). Is that possbile?

For elisp, you can use something like this:

--8<---------------cut here---------------start------------->8---
(progn

(require 'thingatpt)

(defun my-find-symbol-at-point ()
"Find the definition of the symbol at point."
(interactive)
(let ((sym (symbol-at-point)))
(funcall (pcase sym
((pred facep) #'find-face)
((pred symbol-function) #'find-function)
(_ #'find-variable))
sym)))

(global-set-key [(shift return)] #'my-find-symbol-at-point))
--8<---------------cut here---------------end--------------->8---


Michael.


Thien-Thi Nguyen

unread,
Mar 29, 2014, 5:00:37 PM3/29/14
to Michael Heerdegen, help-gn...@gnu.org
() Michael Heerdegen <michael_...@web.de>
() Sat, 29 Mar 2014 19:10:26 +0100

(let ((sym (symbol-at-point)))
(funcall (pcase sym
((pred facep) #'find-face)
((pred symbol-function) #'find-function)
(_ #'find-variable))
sym))

Any particular reason you use ‘pcase’ here instead of ‘cond’?

--
Thien-Thi Nguyen
GPG key: 4C807502
(if you're human and you know it)
read my lisp: (responsep (questions 'technical)
(not (via 'mailing-list)))
=> nil

Michael Heerdegen

unread,
Mar 29, 2014, 6:31:05 PM3/29/14
to Thien-Thi Nguyen, help-gn...@gnu.org
Thien-Thi Nguyen <t...@gnu.org> writes:

> Any particular reason you use ‘pcase’ here instead of ‘cond’?

Yes, I want to get more used to it ;-). And this is a common use case,
since all "conditions" only depend on one value.

Michael.

Alex Kost

unread,
Mar 30, 2014, 1:23:51 AM3/30/14
to Martin, GNU Emacs users list
Martin (2014-03-29 20:49 +0400) wrote:

> Hi there,
>
> This is now specially for elisp, but maybe its possible for other things to
> (ruby on rails - ruby, javascript, coffeescript, ...)
>
> Is there a way to navigate better through my code.
>
> like having a function (foo arg1 arg2) putting the cursor to foo will
> C-h f suggest I want to read the docstring for that. Thats good.
>
> But now I'd like to navigate to the definition (which can be in the same
> buffer or somewhere else). Is that possbile?

You may install "elisp-slime-nav" package
(https://github.com/purcell/elisp-slime-nav). Can be found on MELPA.

It allows to move to the function/variable/face definition immediately.

--
Alex Kost

0 new messages