Creating a TAGS file

The etags command is used to create a tags file for Emacs. You can index an entire directory tree by using, at the root of the tree:

find . -name "*.[chCH]" -print | etags -

This command will create A TAGS file in the current directory.

Using a TAGS file

  • M-. (find-tag): find a tag, that is, use the Tags file to look up a definition. If there are multiple tags in the project with the same name, use C-u M-. to go to the next match.
  • M-* (pop-tag-mark): jump back
  • M-x tags-search: regexp-search through the source files indexed by a tags file (a bit like ‘grep’)
  • M-x tags-query-replace: query-replace through the source files indexed by a tags file
  • M-, (tags-loop-continue): resume ‘tags-search’ or ‘tags-query-replace’ starting at point in a source file
  • M-x tags-apropos: list all tags in a tags file that match a regexp
  • M-x list-tags: list all tags defined in a source file

Locating a TAGS file

Unfortunately, Emacs is not very smart about finding tags files which do not reside in the same directory as the source file being edited. You can make emacs search in specific locations by adding the following to the .emacs file in your home directory:

(setq tags-table-list '("<directory to search>"))

Additionally, there is an extension, called etags-table, which will search up the directory tree to find a TAGS file. The extension is available here:

Etags table

To activate the extension, the following must be added to the .emacs file:

(require 'etags-table)
(setq etags-table-search-up-depth 10)


Table Of Contents

Previous topic

Fedora LiveCD

Next topic

Automatic Login

This Page