How to use shell magic to create a recursive etags using GNU etags?
Asked Answered
H

4

12

The standard GNU etags does not support a recursive walk of directories as done by exuberant ctags -R. If I only have access to the GNU etags, how can I use bash shell magic to get etags to produce a TAGS table for all the C++ files *.cpp and *.h files in the current directory and all directories below the current one recursively to create a TAGS table in the current directory which has the proper path name for emacs to resolve the TAGS table entries.

Hebetate answered 24/5, 2012 at 13:14 Comment(2)
How is it that you "only have access to the GNU etags"? Exuberant ctags is freely available for many platforms. Can't you install it?Gleeson
Employer does not want unauthorized software installed, would rather not fight that if I can work around using provided etags.Hebetate
P
19

The Emacs Wiki is often a good source for answers to common problems or best practices. For your specific problem there is a solution for both Windows and Unixen:

http://www.emacswiki.org/emacs/RecursiveTags#toc2

Basically you run a command to find all .cpp and all .h files (change file selectors if you use different file endings, such as e.g., .C) and pipe the result into etags. Since Windows does not seem to have xargs, you need a more recent version of etags that can read from stdin (note the dash at the end of the line which symbolizes stdin). Of course, if you use a recent version of etags, you can use the dash parameter instead of xargs there, too.

Windows:

cd c:\source-root
dir /b /s *.cpp *.h *.hpp | etags --your_options -

Unix:

cd /path/to/source-root
find . -name "*.cpp" -print -or -name "*.h" -print | xargs etags --append
Partridgeberry answered 25/5, 2012 at 2:9 Comment(2)
using xargs limits the number of files to the max number of command-line args, the etags - version is preferable for large projects.Whallon
find -name '*.cpp' -or -name '*.h' | ... should be enough. You can also use fd '\.(cpp|h)$' -X etags. Is there a particular reason for using --append? I mean, is it faster? Produces no duplicates? A good default (it's generally best to use it every time)?Fibrin
A
5

This command creates etags file with default name "TAGS" for .c, .cpp, .Cpp, .hpp, .Hpp .h files recursively

find . -regex ".*\.[cChH]\(pp\)?" -print | etags -
Artistry answered 16/5, 2016 at 18:3 Comment(0)
D
2

Most of the answers posted here pipe the find output to xargs. This breaks if there are spaces in filenames inside the directory tree.

A more general solution that works if there are spaces in filenames (for .c and .h files) could be:

find . -name "*.[cChH]" -exec etags --append {} \;
Defeasible answered 1/7, 2019 at 20:6 Comment(0)
N
0

Use find. man find if you need to.

Nematic answered 24/5, 2012 at 13:17 Comment(1)
and man xargs too, I bet. . . . . or just install exuberant and use its etags ...Stonework

© 2022 - 2024 — McMap. All rights reserved.