- Published: June 23, 2017
Using Emacs builtin functions to jump source code function definitions of variables.
Emacs has several ways to navigate through method and function definitions for each language without installing any additional package.
In Emacs a function, a method or a class, is known as an identifier, i.e.: a name of a syntactical subunit of the program.
Emacs provides a unified interface to quickly find where each identifier was defined and referenced or to rename identifiers across the entire project, called xref.
Each programming major mode will process its own rules and make xref able to:
- what files to search for identifiers
- how to find references to identifiers
- how to complete on identifiers
A tipical workflow for a backend to implement xref is:
- using an external program to extract references to identifiers by scanning source code files, and
- putting them into a database
We can use programs like
etags to regularly scan the code
for tagging identifier definitions and extract references into tags
Find function definitions and usage
To find the definition of a specific identifier (i.e.: function, method, class, etc) we can use M-. which is bound to xref-find-definitions and it will look for the identifier at point.
To get back where you previously were, use M-..
Find all class or functions
To look for a regex pattern we use C-M-. which invokes xref-find-apropos.
This is useful also to look for all the classes defined in the project, or functions, for example in Python: C-M-. class would retrieve all the classes known by the backend.
TODO: process from “28.3.1 find identifiers”: https://www.gnu.org/software/emacs/manual/html_node/emacs/Identifier-Search.html#Identifier-Search https://www.gnu.org/software/emacs/manual/html_node/emacs/List-Identifiers.html#List-Identifiers
los links de abajo en https://www.gnu.org/software/emacs/manual/html_node/emacs/Xref.html#Xref - Tags tables - Select tags table
- Xref in Emacs manual https://www.gnu.org/software/emacs/manual/html_node/emacs/Xref.html#Xref