Emacs etags

etags is a simple way to find the definition of a function. This is very useful if you’re reading code from a large application.

You can run the following command at the root of the sources:

find . | grep -P "(c|cpp|h|hpp)$" | etags - 

(Sorry, I don’t know how to do it directly with find)

Then, when using emacs, just place the cursor above the function name and type


This will take you to the function definition.



3 thoughts on “Emacs etags”

  1. Perhaps the “-” feature is new; it’s documented, but I don’t remember it. I always used to do it this way:

    true >| TAGS
    find . -regex ‘.*\.[ch]\(pp\)?$’ -exec etags -a {} \+

    Using “-” per your suggestion, this would become the more efficient:

    find . -regex ‘.*\.[ch]\(pp\)?$’ -print | etags –

    I’d bet neither invocation of etags deals well with files whose name contains a newline, though.

  2. For C/C++ code it could be better to use gtags package from GNU Global package – it more correctly works with C++ code, plus it have ability to find which code is calling some function…

  3. something like

    $ find . -type f -regextype ‘posix-egrep’ -iregex ‘.*(c|cpp|h|hpp)$’ | etags –

    works for me, but it’s not exactly shorter 😉

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s