How to add comments to an Exuberant Ctags config file?
Asked Answered
O

4

31

What character can I use to put comments in an Exuberant Ctags .ctags file?

I would like to add comments with explanations, and perhaps to disable some regexps.

But I can't find any comment character which ctags-exuberant accepts!
I keep getting the warning:

ctags: Warning: Ignoring non-option in /home/joey/.ctags

which is better than an error, but still a little annoying.

I have tried # // /* ... */ and ; as comments, but ctags tries to parse them all!

Here is an example file with some comments which ctags will complain about:

# Add some more rules for Javascript
--langmap=javascript:+.jpp
--regex-javascript=/^[ \t]*var ([a-zA-Z_$][0-9a-zA-Z_$]*).*$/\1/v,variable/
--regex-javascript=/^[ \t]*this\.([a-zA-Z_$][0-9a-zA-Z_$]*)[ \t]*=.*$/\1/e,export/
--regex-javascript=/^[ \t]*([a-zA-Z_$][0-9a-zA-Z_$]*):.*$/\1/p,property/
--regex-javascript=/^\<function\>[ \t]*([a-zA-Z_$][0-9a-zA-Z_$]*)/\1/f,function/

# Define tags for the Coffeescript language
--langdef=coffee
--langmap=coffee:.coffee
--regex-coffee=/^class @?([a-zA-Z_$][0-9a-zA-Z_$]*)( extends [a-zA-Z_$][0-9a-zA-Z_$]*)?$/\1/c,class/
--regex-coffee=/^[ \t]*(@|this\.)([a-zA-Z_$][0-9a-zA-Z_$]*).*$/\2/e,export/
--regex-coffee=/^[ \t]*@?([a-zA-Z_$][0-9a-zA-Z_$]*):.*[-=]>.*$/\1/f,function/
--regex-coffee=/^[ \t]*([a-zA-Z_$][0-9a-zA-Z_$]*)[ \t]+=.*[-=]>.*$/\1/f,function/
--regex-coffee=/^[ \t]*([a-zA-Z_$][0-9a-zA-Z_$]*)[ \t]+=[^->\n]*$/\1/v,variable/
--regex-coffee=/^[ \t]*@?([a-zA-Z_$][0-9a-zA-Z_$]*):.*$/\1/p,property/
Outboard answered 10/6, 2012 at 23:37 Comment(0)
P
10

As @joeytwiddle points out, comments are not supported by the parser, but there is a work-around.

Example .ctags file:

--regex-C=/$x/x/x/e/ The ctags parser currently doesn't support comments
--regex-C=/$x/x/x/e/ This is a work-around which works with '/' characters
--regex-C=/$x/x/x/e/ https://mcmap.net/q/463554/-how-to-add-comments-to-an-exuberant-ctags-config-file
--regex-C=/$x/x/x/e/ 
--regex-C=/$x/x/x/e/ You can add whatever comment text you want here.
Pettifogging answered 12/8, 2016 at 11:17 Comment(0)
O
31

You can't! I looked through the source code (thanks to apt-get source). There are no checks for lines to ignore. The relevant code is in parseFileOptions() in options.c

But sometimes comments are a neccessity, so as a workaround I put a comment in as a regexp, in such as way that it is unlikely to ever match anything.

--regex-coffee=/^(COMMENT: Disable next line when using prop tag)/\1/X,XXX/

The ^ helps the match to fail quickly, whilst the ( ) wrapper is purely for visual effect.

Your comment should be a valid regexp, to avoid warnings on stderr. (That means unescaped /s must be avoided, and if you use any [ ] ( or )s they should be paired up.) See Tom's solution to avoid these restrictions.

Outboard answered 18/6, 2012 at 9:35 Comment(3)
+1 for looking through the source code. The hackish solution is rather ugly though, I'd rather live with the warnings.Wavelength
Can we suggest the support for comments on the development team?Hadji
Note this solution fails if there is a / in between the ( and ). See my answer for something that works with this and looks visually neater.Pettifogging
P
10

As @joeytwiddle points out, comments are not supported by the parser, but there is a work-around.

Example .ctags file:

--regex-C=/$x/x/x/e/ The ctags parser currently doesn't support comments
--regex-C=/$x/x/x/e/ This is a work-around which works with '/' characters
--regex-C=/$x/x/x/e/ https://mcmap.net/q/463554/-how-to-add-comments-to-an-exuberant-ctags-config-file
--regex-C=/$x/x/x/e/ 
--regex-C=/$x/x/x/e/ You can add whatever comment text you want here.
Pettifogging answered 12/8, 2016 at 11:17 Comment(0)
T
4

You can use '#' as the start of comment if you are using Universal-ctag(https://ctags.io).

Theseus answered 1/7, 2017 at 2:22 Comment(0)
A
1

Given that comments don't work, what about a .ctags.readme file...

For most things you don't actually need a comment, e.g. you don't really need the comment below.

# Define tags for the Coffeescript language
--langdef=coffee
--langmap=coffee:.coffee

I can see however that you might want to add comments explaining some mind bending regex, so for each line that absolutely needs it you can copy paste it into the .ctags.readme file as a markdown file:

Forgive me father for I have regexed
It was purely because I wanted some lovely coffee properties
```
--regex-coffee=/^[ \t]*@?([a-zA-Z_$][0-9a-zA-Z_$]*):.*$/\1/p,property/
```

Keeping .ctags.readme and .ctags in sync

You could have a block at the bottom of the ctags file separated with a line break, then delete this final block.

If you only have the one line break in your .ctags file this sed will delete all the lines after the line break.

Then do some grepping for the --regex lines to append the lines from .ctags.readme into .ctags.

sed -i '/^\s*$/,$d' .ctags
grep "^--regex" .ctags.readme >> .ctags
Among answered 15/6, 2017 at 22:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.