質問

How do I directly navigate to a function definition in a given file in Slime/Emacs using keyboard shortcuts? I know about M-. but that is not I want. I am already in the file and know the function name. Search by text won't directly take me to the function definition as it will take me to call sites of that function as well.

For those of you who also know Eclipse, I am looking for the equivalent of using Ctrl-O to open the outline view and then as I type the method name, it will filter(elide) to the function I want, I then just press enter and it takes me there.

If there is an alternative that you use, I would be happy to try that too.

役に立ちましたか?

解決

It sounds like you're looking for M-x imenu. It doesn't have a keyboard shortcut by default; I like to bind it to s-i:

(global-set-key [(super ?i)] 'imenu)

他のヒント

As @legoscia said, Imenu is the answer. As additional info I'll mention how Icicles can enhance your use of Imenu.

The obvious enhancement is better completion (substring, regexp,...), including narrowing choices with multiple patterns.

Unobvious is the Icicles multi-commands that are specialized for Imenu navigation, giving you, in effect, an Imenu browser. This is described here.

  • There are different commands to navigate to/among different kinds of Emacs Lisp definitions: commands, non-command functions, faces, keymaps of different kinds, user options, and other variables.

  • While navigating, you can sort the candidates that match your input, and cycle among any subset of them in the sort order.

  • There are "full" versions of the commands, which provide as candidates not just what matches the Imenu regexps (e.g. (defun foobar () and your current input, but the complete definitions (e.g., full function definition).

  • These navigation commands are also for searching. In particular, the "full" versions provide the full definitions that match your current minibuffer input as candidates. As you change your input incrementally, the full definitions are searched, narrowing the choices. You can then navigate among any of those.

You can also do it with lispy. It's a mixture of Paredit, vi and IDE features for Elisp, Clojure, Common Lisp and Scheme.

The feature that you want is provided by lispy-goto, bound to g. It uses CEDET to parse the whole source directory, allowing you to jump to a tag in all files in current directory.

There's also lispy-goto-local bound to G, that looks for tags in just the current file.

helm completion is used for both commands so it's really fast. Have a look at Navigating a directory of Common Lisp code with lispy.el for a screencast.

You can see that it's much more advanced than imenu: it recognizes tag types such as in-package, defparameter, defconstant, defclass etc. This can also be extended to arbitrary tags, such as SLIME's define-pattern-substitution.

Also, lispy uses SLIME to provide inline arguments (alternative to eldoc) and eval bindings.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top