I have two files: A.el and B.el
Under my cursor in A.el is a function defined in B.el. How do I jump to the function in B.el?
M-x find-function does that.
Finds the source file containing the definition of the function
near point (selected by ‘function-called-at-point’) in a buffer and
places point before the definition.
You seem to be asking specifically about native Emacs Lisp; you need to have loaded the function into Emacs for this to work.
In the general case, this depends on the mode of the file, but the traditional solution is to use etags.
A somewhat more modern replacement called xref was introduced in Emacs 25; try M-.
Related
When I press M-. or C-c C-l it usually jumps to the function's declaration in .mli file. Oftentimes there is associated .ml file to which I can switch with C-c C-a but then, I have to search for the implementation of this function in it manually.
If there is an easy way to either jump directly to a definition in .ml file or somehow position to the corresponding function location when switching between .mli and .ml?
This is governed by the merlin-locate-preference variable, which documentation says:
Determine whether locate should in priority look in ml or mli files.
So you will land to the implementation, if it is available, once the variable is set to 'ml:
(setq merlin-locate-preference 'ml)
It is interesting though, that it defaults to 'ml so that either you overwrote it or merlin jumps to mli because it can't find the definition. If you want to jump to the definition in another project, then add corresponding S and B clauses to your .merlin file.
I just finished the Emacs Lisp intro and am getting my feet wet with customization. I've browsed the Emacs FAQ, the Emacs W32 FAQ, and perused the fine manual for drag and drop information. I am using GNU Emacs 24.5.1 for Windows without Cygwin (etc.).
I would like to update the default drag and drop behavior to open such files in read only mode. Through C-h f I've identified the dnd functions. In particular, dnd-open-file may be relevant. By C-h k and then dragging a file into Emacs, I've identified the function w32-drag-n-drop. Also, within the Reference Manual is a section on drag-and-drop which specifies x-dnd-types-alist.
How do I identify which of these items, if any, needs to be modified?
What is a safe way to modify its behavior?
I cannot find documentation on x-dnd-types-alist. Is it a function? A variable?
Is there a resource I've overlooked which I should be looking at?
Partial answers of a general nature - I can't help with your dnd problems,
but I hope these suggestions will be of some use.
Q2. It's a good idea to have a minimal init file, containing whatever is necessary to initialize an environment for testing. You can them invoke emacs like this:
emacs -q -l /path/to/minimal/init/file
bypassing your initialization file (-q) and loading the minimal init file instead. Then if something blows up, you just kill this emacs instance, and start again (possibly with a modified init file).
Q3. It's a variable (as are all alists). An alist (short for association list) is a list of key-value pairs. You can get the docstring of any variable with
C-h v VARNAME RET
e.g.
C-h v x-dnd-types-alist RET
Q4. If all else fails, the source is available...
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.
When emacs do the grep, it can split the window and show a nice buffer , and Emacs has the function (grep args),I want to know, How can I get the source code?
Emacs executes the external grep process, and formats the output. Assuming you mean the source for the code that wraps that up and displays it, not grep itself, that is pretty simple:
M-x find-function <RET> grep <RET>
(find-function FUNCTION)
Find the definition of the FUNCTION near point.
Finds the source file containing the definition of the function
near point (selected by `function-called-at-point') in a buffer and
places point before the definition.
Set mark before moving, if the buffer already existed.
You may also find find-library useful to poke around with.
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.