Jump To Function Definitions In Emacs

  • Published: June 23, 2017

Overview

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.

Terminology

Identifiers

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.

xref

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

backend

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 ctags or etags to regularly scan the code for tagging identifier definitions and extract references into tags tables.

A reference can be an identifier definition oran identifier usage.

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

References

Uruguay
Marcelo Canina
I'm Marcelo Canina, a developer from Uruguay. I build websites and web-based applications from the ground up and share what I learn here.
comments powered by Disqus

Jump to the file and line of the definition of a function, method or class while developing in Emacs.

Except as otherwise noted, the content of this page is licensed under CC BY-NC-ND 4.0 ·