Why do you need etags?
- You would have come across situation where we need to traverse through pre-written source codes written in C, C++, Python, etc.,
- You might have come across difficulties in looking for function definitions that could be located anywhere among the included header files that are distributed across different directories.
- etags come to the rescue.
What is etags?
- When we use IDEs like Keil, MPLAB, etc., simply clicking on function call can take you to the function definition.
- etags provides you with similar functionality when using emacs as your editing tool.
- etags comes as part of emacs and hence no need to install it and you can directly jump in. Check man page for 'etags' to know more.
Usage
- Open terminal and move to the parent directory of the source code where you want the TAGS file to be created.
$ cd /location/of/parent/directory/
- Type in the below code to create the tags table in a file with default name 'TAGS' in the current directory. The name can be changed using the --output=filename option. The ''-'' as the filename prints the table to the standard output.
$ find . -regex ".*\.c\|.*\.h" -print | etags -to create tags table for selected files alone, you can simply use
$ etags filenames...Check your directory for the TAGS file created. It might take some time to create the file depending on the depth of your source.
Now you are done with configuration. Lets see how to use it to traverse across source code.
- Open any source file under your source directory using emacs.
- Move your text cursor over a function call.
- Type M-. (Alt+.) and click enter. You will be prompted with 'Find tag (default <function name>):'.
- Click <Enter>
- Now you will get a prompt 'Visit tags table (default TAGS):'. It means, you need to provide the location to the directory where the TAGS file is located. (This is a one time prompt for every emacs session.)
- Enter the location to your TAGS file and click enter.
- 'Mark set' will be displayed and you will be taken to the definition of the function. After reading through the definition, at any point you can type M-* (Alt+Shift+8) to return back where you started.
WARNING: Use (Alt+Shift+8) in the default keyboard. Don't use number pads.
NOTE: This procedure will hold good for traversing to header files and macros as well. Also, you can check tutorial on ctags.
References
No comments:
Post a Comment
Comment will be published after moderation only. Do not advertise here.