Skip to content

Instantly share code, notes, and snippets.

@felipecrv
Created May 11, 2012 04:09
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felipecrv/2657477 to your computer and use it in GitHub Desktop.
Save felipecrv/2657477 to your computer and use it in GitHub Desktop.
CSS for ctags
--langdef=css \
--langmap=css:.css \
--regex-css='/^[ \t]*\.([A-Za-z0-9_-]+)/#\1/c,class,classes/' \
--regex-css='/^[ \t]*#([A-Za-z0-9_-]+)/.\1/i,id,ids/' \
--regex-css='/^[ \t]*(([A-Za-z0-9_-]+[ \t\n,]+)+)\{/\1/t,tag,tags/' \
--regex-css='/^[ \t]*@media\s+([A-Za-z0-9_-]+)/\1/m,media,medias/' \
@felipecrv
Copy link
Author

From http://book.abe.free.fr/blog/public/ctags and slightly changed

@marlun
Copy link

marlun commented Mar 19, 2013

I'm trying to add this but I'm getting error:

$ ctags -R .
ctags: Warning: Unknown language "css:.css \" in "langmap" option
ctags: Warning: unknown language "css" in --regex-css option
ctags: Warning: unknown language "css" in --regex-css option
ctags: Warning: unknown language "css" in --regex-css option
ctags: Warning: unknown language "css" in --regex-css option

It's like it's not seeing the --langdef=css \ line.

Any idea why?

@marlun
Copy link

marlun commented Mar 19, 2013

The problem was that I needed to remove the quotes around the regex and the \ in the end of the lines. Works fine now.

@felipecrv
Copy link
Author

I had to the quotes and backslashes cause I've made a script -- ct -- with the big command in it instead of adding theses line to a .ctagsrc file.

@alexrah
Copy link

alexrah commented Dec 11, 2013

I tried to include your CSS regex with a modified version of Ctags -> https://github.com/fishman/ctags
the only missing filter in the modded Ctags version above is Media Queries so I tried with your regex but:

your regex just filter the FIRST AND ONLY THE FIRST WORD of the media query string.
for instance I have this media query:
@media only screen and (min-device-width : 768px)

but your regex filter just the FIRST word after @media -> in this case "only".

so what I get is a list of "only" and "screen" under media queries instead of something more useful such as:
"only screen and (min-device-width: 768px)"

I'm not a good regex writer, otherwise I would modify it by myself: would you please help me fix this?

many thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment