Excluding directories in Exuberant CTags
Asked Answered
E

3

18

I'm working with a very large code base and I find it useful to be selective about which directories are included for use with Exuberant Ctags.

The --exclude option works well to eliminate individual file and directory names (with globing wildcards), but I can't figure out how to get it to exclude path patterns containing more than one directory.

For example, I may want to exclude a directory tests, but only when processing thirdparty\tests (under Windows). The problem is if I just use --exclude=tests I exclude too many directories, including a test directory in the code I'm actively working on.

Here are some things I've tried:

--exclude=thirdparty\tests
--exclude=thirdparty\\tests
--exclude=*\thirdparty\tests
--exclude=*\\thirdparty\\tests
--exclude=thirdparty/tests

Ctags silently ignores all these as evidenced by an examination of the tags file.

How can I exclude a directory only when it is preceded by a given parent directory?

ADDED:

Here's my ctags --version output:

Exuberant Ctags 5.8, Copyright (C) 1996-2009 Darren Hiebert
  Compiled: Jul  9 2009, 17:05:35
  Addresses: <[email protected]>, http://ctags.sourceforge.net
  Optional compiled features: +win32, +regex, +internal-sort
Edwinaedwine answered 19/11, 2011 at 9:44 Comment(9)
Does ctags --version show +wildcards in the output?Mooncalf
@sarnold: Hmmm, nope! So you think one of the *\thirdparty\tests would work if I had that option?Edwinaedwine
Yeah, it probably would -- but I wouldn't know how to go about getting the wildcards support under Windows. (Having a /bin/sh installed when compiling it might be sufficient.)Mooncalf
I had originally answered you question as if you only wanted to exluded a few directories. I think your best be it to use --exclude option to use a file with the names of the directories you want to exlude. its in the manual I think all you need to do is put an @ in front of the filenameHighball
@Will: Thanks, this was a while ago, but I think I wrote a Python script to filter exactly as I needed, wrote that to a file, and used @ as you alluded.Edwinaedwine
The manual also notes that you should quote wildcards when they are supported (otherwise the shell expands them).Operant
Possible duplicate of How to exclude multiple directories with Exuberant ctags?Palladian
@CiroSantilli刘晓波死六四事件法轮功, note that this question was asked first. The other question is the duplicate.Edwinaedwine
@CodieCodeMonkey hi Codie, Current consensus is to close by "quality": meta.stackexchange.com/questions/147643/… Since "quality" is not measurable, I just go by upvotes. ;-) Likely it comes down to which question hit the best newb Google keywords on the title.Palladian
M
16

At some point it might be easier to define the list of files you do want indexed; save that list to a file, and use ctags -L <filename> to index just the chosen few.

This lets you use find(1) to prune the directories you don't want to index, e.g.:

find . -path ./Documentation -prune -o -print > indexme

would skip all the files in all subdirectories of ./Documentation.

Mooncalf answered 19/11, 2011 at 9:56 Comment(7)
You'll have to get a version of find for Windows though.Leasehold
Or scrap together something Good Enough if find(1) is too hard to port. You really just need a list of file names, not the full functionality of find(1).Mooncalf
+1 that's a good suggestion, I can use a tool to generate a list of directories I want, which will give me more filtering options beyond the ones I asked for. Today, I'm too lazy. :-)Edwinaedwine
Lazy is good; it makes you look for new ways to solve problems. :)Mooncalf
Could someone do a noob step-by-step of this process? TnxNuncle
@JoseBrowne: I think the consensus is to use a two-step process: first run a tool to build a file for ctags to consume, then run ctags and reference that file. The choice of tools is up to you. If you generate a list of files to include, you can use the -L option as Sarnold suggested, or if you generate a list of options--notably --exclude options--you can use ctags @<file> to read this options as if you had typed them all at the command line.Edwinaedwine
I prefer find . -type f -not -path './Documentation/*' because it's more intuitive and less obscureAnzus
M
10
ack -f | ctags -L -

ack will list the source files in a given dir. You can limit the scope to a specific language with ack -f --ruby or ack -f --type=ruby. You can exclude dirs as well with --ignore-dir.

Use ack --dump to see the built-in file types for ack.

Matney answered 10/6, 2014 at 12:45 Comment(2)
That rocks. This never occurred to me.Coypu
Great answer. I used git ls-files | ctags -L -Permanganate
L
0

ctags -R --exclude="thirdparty/test/**"

use "dir/**" fix my case

Leticia answered 4/6, 2021 at 5:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.