user1990
user1990

Reputation: 546

I'm looking to add syntax color in emacs for global variable, define, local variable in a func like eclipse

I'm looking to add syntax coloring in Emacs for global variables, defines, local variables in a function.

For example, local variables would be green, globals would be orange, and defines would be blue, like this picture:

syntax highlighting example

Upvotes: 3

Views: 362

Answers (1)

sds
sds

Reputation: 60004

The short answer is - you cannot.

Emacs highlighting works on regular expressions, not on syntax analysis. E.g., foo_t is highlighted as a type because of the _t suffix (int et al are explicitly mentioned in the regexps).

To do better emacs must either parse the C syntax (prohibitively expensive) or talk to a C compiler (clang, because gcc does not reveal its parse tree).

See, e.g.,

These talk about completion, but they are using the same tools that you need and you can relatively easily extend them to do what you need.

Upvotes: 6

Related Questions