December 17, 2015

Etags - Source code navigation tool for Emacs

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.
  • 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.

  1. Open any source file under your source directory using emacs.
  2. Move your text cursor over a function call.
  3. Type M-. (Alt+.) and click enter. You will be prompted with 'Find tag (default <function name>):'.
  4. Click <Enter>
  5. 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.)
  6. Enter the location to your TAGS file and click enter.
  7. '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.

  1. Creating tags table
  2. etags
  3. Creating etags file
  4. ctags tutorial (For tutorial on ctags)

The above article doesn't give you any guarantee and the sole purpose of this article is to share my learning in the way I understood. Any comments to refine this article are welcome with great pleasure. Please report any breaking link by commenting below.

No comments:

Post a Comment

Comment will be published after moderation only. Do not advertise here.

Receive all updates via Facebook. Just Click the Like Button Below

You can also receive Free Email Updates:

dgpride - Study Zone - Free Books - Tamil Lyrics

Copyright © 2008 -2012 dgpride. All rights reserved.


2 Marks (26) 8051 (1) AC Machines (7) Animations (1) Anna University Chennai (31) Arduino (4) ARM (3) Audio (1) Basic C Concepts (8) Basic Electronics (13) Basic principles (9) Book list (1) CAD (1) Chemical (2) Circuit theory (6) Civil (2) Cloud Computing (1) Communication (4) Competitive exams (2) Computer Architecture (4) Control system and components (9) CSE (40) Curriculum (4) DC Machines (9) Did you know (14) Digital (13) DLC (4) Documentation (1) DSP (1) EC 2201 (3) ECE (45) EDC (1) EEE (34) EIE (63) Electrical (35) Electronics (43) Electroplating (2) Emacs (1) Embedded basics (19) Embedded C Programming (19) Embedded Linux (5) Embedded System (22) Engineering basics (15) Environmental Science (1) Fibre Optics (1) Filters (2) FPGA (1) GATE (3) General (7) GNU (4) Handwritten (1) Hobbyist (15) How to (8) HTML (3) Humanities (2) IC Engines (7) ICE (5) Industrial Electronics (10) Industrial Instrumentatin (2) industrial process (2) Instrumentation (21) IoT (2) IT (2) Laboratory Manuals (17) LabVIEW (2) Lesson notes (2) LIC (2) Links (9) Linux (8) Magnetics (1) Management (1) Mechanical (5) Mechatronics (9) Microcontrollers (14) Microprocessors (9) Microsoft (1) Motivation (1) Must Know (11) Networks (1) NuttX (1) Objective type (1) Open Source (1) Opportunities (7) Oscillators (2) Part Time (1) Physics (1) Post Graduation (1) Power Electronics (12) Power Plant Engineering (2) Power Supplies (2) Previous GATE Papers (1) Process Control (2) Project (4) Protocol (1) R2008 (11) R2009 (1) R2013 (1) Recruitment (2) Research (2) Robotics (9) RTOS (3) Signal Processing (8) Signals and Systems (4) SMPS (1) Software tutorial (4) Stepper Motor (2) Syllabus (5) Texas Instruments (2) Thermodynamics (2) Training and Placement (6) Transducer Engineering (2) Transformer (2) Transmission (1) Tutorials (48) Two Marks (26) U-Boot (1) University Question Papers (16) Verilog (1) Video (4) Virtual Instrumentation (3) Visual Basic (21) VLSI (11) Web designing (4) Wi-Fi (3) Wireless (6)