Sublime Forum

Highlighting the names of typedef's C++

#1

Currently, when you type

typedef int nameInt;

nameInt is not highlighted. I would like for nameInt to be highlighted to same color as all the other types (ie, bool, int, etc.) Also, is there a way to do this with class names as well so that when you type

string test;

the word string, would be highlighted. I have looked at the C.tmLanguage file, and saw that I could add string to the list of types that would be highlighted, but that would not work for other classes such as vector. There would be too many class names to add. What would the code be like to highlight class name (string, vector, cin, cout, etc.)?

Edit: Would it be possible to add a regex that would pick the last word after typedef and add that to the list of types to be highlighted?

Edit2: How come this regex is not working typedef.*?\s(\w+)\s*;

0 Likes

#2

There are a lot of useful tools out there to help you get regex right.
Here’s one:
http://www.regular-expressions.info/javascriptexample.html

When I removed the trailing ‘’ from your regex to get this ‘typedef.?\s(\w+)\s;’
and tested it against the string ‘typedef int nameInt;’
Then it reported a successful match.
Whether is was the match you wanted and whether that match produced the desired syntax highlighting result is something only you can say.

Give it a try and let us know if you have more difficulties.

0 Likes

#3

Sorry, I never had a trailing “” when I was testing. I added it to the post by mistake. I still cannot get it to work though. Has anybody figured out how to highlight typedef names?

0 Likes