Load multiple syntax highlighters for a file type


#1

I would like to convert one of my Vim plugins to Atom. In a nutshell, my plugin is for C and C++ and overlays the existing C and C++ syntax highlighter used by Vim. The plugin identifies and calls attention to dangerous APIs (a list configured within the plugin) by highlighting them in red. (I use this as a reminder to use better APIs, but it is also useful when I am reviewing code.)

Now I haven’t written an Atom syntax highlighter yet, but I’ve been looking into it. I don’t want to replace the existing C and C++ syntax highlighters. I also don’t want to make any changes to them. Ideally, for C and C++ file types, I would like to have my syntax highlighter loaded second, so that I can override the existing C or C++ syntax highlighter whenever a dangerous API is seen.

Is this approach supported by Atom? Is this the right way to perform additional syntax coloring on a loaded file? Thanks for any and all assistance!


#2

Actually, it sounds like you’re looking more for a linter type of thing … albeit perhaps a very simplistic one. If so, there are a couple popular linter packages: linter and atom-lint. If you want to roll your own, I suggest taking a look at the Decorations API.

If you really want to do this by creating a grammar, you may want to look at some hints on injection grammars here:


#3

This is helpful info. Thanks!