Working with tags within emacs.
Facts - Editor: emacs
Wednesday, 17 September 2008 00:00

When making or reading a bigger program it is often useful to quickly find program identifiers, such as the definitions of user types, objects, or functions. This is an easy task from emacs:

  1. Download ctags, for instance as part of cygwin,
  2. Use ctags to create a tag table javaTags for your program code:
    /usr/bin/find c:/src/yourpackage/ -type f -iname "*.java" | /usr/bin/ctags.exe --language-force=java -e -f javaTags -L -
    Note that the input of ctags is a list of file names which is generated using the unix command find.
  3. <
  4. Then invoke the emacs command visit-tags-table: Meta-x visit-tags-table. Emacs asks you the name of the tags file (javaTags).
  5. Use the following commands to operate on tags:
    • find-tag --> "Alt-."
    • find-tag-other-window --> "C-x 4 ."
    • find-tag-other-frame --> "C-x 5 ."
    • complete-tag
    • tags-apropos
    • tags-search
    • tags-query-replace
    • tags-loop-continue --> "Alt-," --> repeat last tags-search or the last tags-query-replace

The find-tag methods find the definition of a tag. You can find all occurrences of a tag by first searching for a tag with tags-search and then executing one or more commands tags-loop-continue.

The find-tag methods have tag completion triggered by "TAB" which is not possible with the tags-search command. However with the tags-search command and the tags-loop-continue you perform do a repeating search.

For C++ code the ebrowse tags may provide better search results than with the ctags tags described here.

Last Updated ( Thursday, 18 September 2008 20:01 )