Using etags in emacs

  1. Generate tags:

in the root source directory,

find . -name "*.[ch]*" -o -name "*.cpp" -o -name "*.hpp" | xargs etags -a
  1. Set tags in emacs:
M-x visit-tags-table RET
  1. Look up tag definitions:
M-.
  1. Move back to last tag position:
M-*

Once you have a tags file, you can follow tags (of functions, variables, macros, whatever) to their definitions. These are the basic commands:

  • M-. (find-tag) – find a tag, that is, use the Tags file to look up a definition
  • M-* (pop-tag-mark) – jump back
  • tags-searchregexp-search through the source files indexed by a tags file (a bit like grep)
  • 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
  • tags-apropos – list all tags in a tags file that match a regexp
  • list-tags – list all tags defined in a source file

See the Emacs manual, node Tags for more information.