Jump To Function Definitions In Emacs

Published:
Last modified:

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 or an 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-, which invokes xref-pop-marker-stack and pops back to where M-. was last invoked.

The above behaviour is possible due to the Marker stack which pushes each time with xref-find-definitions and pops from the stack with xref-pop-marker-stack.

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.

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.

Clutter-free software concepts.
Translations English Español

Except as otherwise noted, the content of this page is licensed under CC BY-NC-ND 4.0 . Terms and Policy.

Powered by SimpleIT Hugo Theme

·