Slime/Emacs : Keyboard shortcut for Go to function ( Not M-.) - emacs

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.

Related

clojuredocs integration with emacs

My Current Workflow
I need to use 'doseq'
I don't remember it's args.
I go to clojuredocs , lookup 'doseq', and look at the examples.
My Ideal Setup
Inside emacs, I type some magic key combo, I type in doseq,
and it EXTRACTS EXAMPLES FROM A LOCAL MIRROR OF CLOJUREDOCS
and presents it inside my emacs browser.
What I found via Google:
https://www.reddit.com/r/emacs/comments/450x84/a_clojuredocsorg_for_emacs/
Basically other people also want this.
My Question:
Is there anyway to do this in emacs?
Thanks!
I use cider-grimoire. In Spacemacs, I just type the leader key, followed by hg. Behind the scene, cider will perform a search on conj.io and return the result in another Emacs buffer.
Late to the party, but here it is:
https://github.com/mbuczko/helm-clojuredocs
It is helm-based solution which redirects to the clojuredocs.org displaying documentation of given search phrase (if found). Most useful when used with helm-clojuredocs-at-point function which simply searches for phrase under the cursor.
If you use cider, C-c C-d C-d on a var will show you the docstring for that var. Not exactly what you're describing but for many use-cases the docstring is enough to figure out the arguments to a function.
cider will also show the arguments to the current function (under cursor) in the echo area.

Is there command documentation and searching built into emacs?

Suppose I want to install a new package. To do this I need to remember that M-x package-install RET package-name is the sequence of keystrokes to type into emacs to do this.
If I forget this keystroke, my go to solution is to google the action I want to complete and browse through the results until I find the right command.
I suspect there is a better way to look up emacs commands and what they do though. If so, can anybody point me to it?
Thanks!
The number one goto command for this would be the apropos-command, which is invoked by using C-h a (or M-x apropos-command), and then typing a search query for the command.
If you know the name of a function, you can use C-h f which runs the describe-function command to get more details about the command.
Lastly, if you know the key sequence, and want more details regarding the command you run, you can use C-h k - describe-key to have emacs tell you what command and the documentation for that command when typing a sequence of keys.
You can get a more complete list of help commands by typing C-h ?.
The built-in manuals are the other obvious places to look, and you can search each one using its index, or isearch through the full-text of the manual.
https://stackoverflow.com/a/22380057/324105
If you use Icicles then the equivalent of apropos-command is built into every command that reads a command name, and you can change the pattern on the fly to tweak the set of matches. See apropos completion.
Whereas with apropos-command you need to provide at the outset the regexp or the complete list of keywords to match (and you need to get them right), with Icicles you can modify/correct them incrementally, and you can add more patterns progressively (progressive completion).
And when you have a set of matches for your pattern(s), you can see the complete doc for each on demand, as opposed to searching the output from apropos-command (which only shows partial doc anyway).
In addition, Icicles extends the standard apropos commands in various ways.

Emacs: Enter commands like in gedit

in gedit it's possible to define so-called "snippets" for simpler input.
For example, there is a snippet while. This means: If you type while -> (-> stands for tab key). And gedit automatically converts it to the following (including correct indentation):
while (condition){
}
In vim (in conjunction with latex-suite) I saw the following: If you type (, vim inserts just a (. If you type ( a second time, vim automatically converts it to \left( \right).
I found abbrev-mode but this mode doesn't place the cursor properly (i.e. between parentheses or inside the while loop).
I managed to create custom emacs keybindings/macros that do just the same (without having to press the tab key), so I know it's possible.
However, is there already and package where you can define such "snippets" without much effort? Or are there even any serious reasons not to use such things?
See yasnippet. It provides snippets for most major languages, and it is easy to add new ones or modify the old ones.
Yes, yasnippet is probably the way to go. But make sure you learn the major mode you're using for your editing - when writing in LaTeX, learn auctex. Major modes can contain functionality that makes some snippets pointless, and do the same thing even better. So instead of using a begin/end-snippet in a LaTeX buffer, try C-c C-e in auctex. Etc :)
Don't forget abbrev-mode.

In Emacs, how can I jump between functions in the current file?

I'd like to quickly move point to a function in my Emacs buffer. I'd like to run some function and get a prompt asking me for the function name, with completion provided for every function defined in the current buffer.
I generally use etags to navigate around, but sometimes I'm looking for a framework method that's been overridden in several files. In these cases, I can find the file I need but then I'd like to quickly jump to the function there. There is a similar feature in TextMate where you can select a definition from a list in the bottom right of the editor.
Just to jump around functions in the current file? Use imenu. It's the simplest and lightest of all the alternatives listed so far and might be enough for what you want. It's also built into Emacs and has minimum setup hassle. It features graphical and textual interfaces. Anything extra and you'll be better off using one of the other excellent suggestions made here.
speedbar comes standard, and gives you a collapsible menu for each file in the current directory, by default middle clicking on an entry for a function definition jumps to that def. With emacs23 this was changed to the more normal leftclick.
You can use etags-select to select from multiple matching tags. But the answer to what you asked is imenu.
Icicles is probably closer to what you are looking for:
http://www.emacswiki.org/emacs/Icicles_-_Tags_Enhancements
It's an enhancement to etags and includes (among other things) the file name with the tag so you can tell if it's the one you are looking for.
try CEDET. It is a bit difficult to set up the first, but here is an excellent tutorial: by Alex ott
And when he gets installed, you can use semantic-complete-jump. pressed tab couple times, and it is also brings up symbol definitions.
If M-. brings up the wrong method, you can type C-u M-. to find the next one with the same name.
global gtags is very good
To navigate within the current file or a set of files that you select, you do not need a TAGS file. You can use Imenu. But it is better to use Icicles imenu commands.
Why? Because they let you use completion. Substring, regexp, prefix, or fuzzy completion. Combine simple patterns to match, or subtract them.
Command icicle-imenu is bound in Icicle mode to C-c =. Butyou can also look up just a command or just a non-command function (non-interactive), using command icicle-imenu-command or icicle-imenu-non-interactive-function.
These commands are multi-commands, meaning that they are actually browsers: you can trip among function definitions using keys C-RET or C-mouse-2 (direct jumps) and C-down (cycle). Hit RET or click mouse-2 to settle down at a final destination.
I use C-M-a and C-M-e to jump between the beginning and end of functions.
Otherwise, open up Speedbar and click the + icon next to a file name to view a list of functions contained in the file. Then click on the function names to jump to them directly.

Emacs how to auto-complete words of include files on C?

How can I make Emacs to complete words that are in C include files ?
#include <stdio.h>
int main(){
print//<-- this is where I want it to complete printf
What's the simplest way? (something simpler than Cedet)
First generate tags for the source and include files you'd like to be able to autocomplete for. See my blogpost for tips on using tags if you didn't use tag tables before.
Now if you have a TAGS table that includes the stdio.h, then you can autocomplete 'printf' using the command `complete-tag'.
Perhaps bind `complete-tag' to a key:
(global-set-key [f3] 'complete-tag)
Unlike complete-tag, dabbrev-expand, or hippie-expand (which does dabbrev-expand like things), the CEDET suite does exactly what the question describes. When asked to perform a completion, it looks and sees that you have included stdio.h, and then looks there for possible completions.
CEDET does a lot of other things related to completion as well which will provide very focused and correct suggestions, not just vaguely similar suggestions. A side affect is that CEDET takes more effort to setup. You need to teach it where you include files are, for example, and sometimes how to deal with macros, and what the project you are working on is like.
There is more detail on this here:
link text
You might want to try out M-/ (dabbrev-expand). This command attempts to complete the identifier immediately preceding the point (ie, where your cursor is) using the contents of the current buffer and then the contents of other buffers of the same mode. If the first completion offered isn't the one you want, just keep typing M-/. If you have the habit of keeping a single emacs session open continuously (which, if you don't have, you should really acquire), and have a handful of files from the current project open, you're quite likely to be able to find an the expansion you want for any particular prefix.
So, to answer you're original question, M-/ will find the printf completion you're looking for if (a) you've used printf anywhere else in the buffer you're editing, or (b) it appears in any other .c or .h file you have open in emacs.
You might also try hippie-expand, which has additional options regarding where it looks for completion information. I bind M-/ to hippie-expand, and then modified the order of the elements in hippie-expand-try-functions-list as follows:
(global-set-key (kbd "M-/") 'hippie-expand)
(setq hippie-expand-try-functions-list '(try-expand-dabbrev try-expand-dabbrev-all-buffers try-expand-dabbrev-from-kill try-complete-file-name-partially try-complete-file-name try-expand-all-abbrevs try-expand-list try-expand-line try-complete-lisp-symbol-partially try-complete-lisp-symbol))
This makes hippie-expand act like the normal M-/ at first, but repeated presses will yield more possible expansions.