How to Add CSS Support to Ctags

Any vi head knows how important the tags file can be. Unfortunately, the stock version of Exuberant ctags does not have support for CSS. Never fear, I will show you how to compile in Iago Rubio’s CSS ctags parser into ctags.

First of all, Iago’s parser was hard for me to find (his web site is not in English), so I keep a copy here: css.c Download it and put it with the rest of your ctags source.

Next, download the ctags source from: http://ctags.sourceforge.net. Version 5.6 is current at the time of this writing. Unarchive it, change to the directory w/ the source code, and drop in css.c from above.

1
2
3
4
5
cd ~/src
<i>... download ctags tarball here ...</i>
tar xzvf ctags-5.6.tar.gz
cd ctags-5.6
wget http://scie.nti.st/dist/css.c

You will now need to make 2 small changes to a couple files, very basic stuff. Just apply this diff (automatically with patch or do it by hand):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
--- ctags-5.6-stock/parsers.h   2006-05-29 21:37:12.000000000 -0700
+++ ctags-5.6/parsers.h 2006-11-25 18:40:28.000000000 -0800
@@ -24,6 +24,7 @@
        CppParser, \
        CsharpParser, \
        CobolParser, \
+       CssParser, \
        EiffelParser, \
        ErlangParser, \
        FortranParser, \

--- ctags-5.6-stock/source.mak  2004-06-09 20:01:17.000000000 -0700
+++ ctags-5.6/source.mak        2006-11-25 18:28:45.000000000 -0800
@@ -15,6 +15,7 @@
        beta.c \
        c.c \
        cobol.c \
+       css.c \
        eiffel.c \
        entry.c \
        erlang.c \
@@ -65,6 +66,7 @@
        beta.$(OBJEXT) \
        c.$(OBJEXT) \
        cobol.$(OBJEXT) \
+       css.$(OBJEXT) \
        eiffel.$(OBJEXT) \
        entry.$(OBJEXT) \
        erlang.$(OBJEXT) \

Now do the “./configure && make && make install” dance like normal and your new ctags binary will generate tags for CSS also!

Comments