Search code examples
vimctags

Why can't exclude files with exclude argument in ctags command?


I want to create tag file for C and C++, exclude all files in /usr/include/python2.7, all files in /usr/include/* instead of /usr/include/python2.7 were created tag.

ctags -R -I __THROW -I __attribute_pure__ -I __nonnull -I __attribute__ \
    --file-scope=yes --langmap=c:+.h --languages=c,c++ --links=yes --c-kinds=+p \
    --c++-kinds=+p --fields=+iaS --extra=+q  \
    -f .vim/tags/c.tag /usr/include/*  --exclude="/usr/include/python2.7"

It is no use to write it as

ctags -R -I __THROW -I __attribute_pure__ -I __nonnull -I __attribute__ \
    --file-scope=yes --langmap=c:+.h --languages=c,c++ --links=yes --c-kinds=+p \
    --c++-kinds=+p --fields=+iaS --extra=+q  \
    -f .vim/tags/c.tag /usr/include/*  --exclude=/usr/include/python2.7/*

Why still many contents come form /usr/include/python2.7 ?

grep  "python*"  /home/debian8/.vim/tags/c.tag
ysize   /usr/include/python2.7/Imaging.h    /^    int xsize, ysize, xoff, yoff;$/;" m   struct:ImagingCodecStateInstance    access:public
ysize   /usr/include/python2.7/Imaging.h    /^    int ysize;$/;"    m   struct:ImagingMemoryInstance    access:public
ystep   /usr/include/python2.7/Imaging.h    /^    int ystep;$/;"    m   struct:ImagingCodecStateInstance    access:public

Solution

  • You are trying to add more options after your target directory. That won't work.

    This should work:

    ctags -R -I __THROW -I __attribute_pure__ -I __nonnull -I __attribute__ \
        --file-scope=yes --langmap=c:+.h --languages=c,c++ --links=yes --c-kinds=+p \
        --c++-kinds=+p --fields=+iaS --extra=+q  \
        -f .vim/tags/c.tag --exclude=python2.7 /usr/include
    

    It is the same command you used with three differences:

    1. Specifies --exclude option before the target directory to index.

    2. Specifies the target directory (/usr/include) without a wildcard, as ctags already knows to look at everything inside.

    3. Only has to exclude python2.7 because only that directory name is needed. If it sees that directory name, it will not go in there and index anything. Full path is not required here.