In emacs (23.3.1, GNU) i have set a theme (doesn’t matter which i use this issue persists). While in C++ mode when i declare a variable the variable is highlighted (this case white) but upon calling that variable again in my program it will not be highlighted white as it was upon declaration. Any ideas why this happens and how to fix it? Thanks in advance. Here is an example although there is obviously no color:
int num; <------- would be white
cout << "The number is: " << num << endl; <-------- here it would not be white,
just regular foreground color?
That is because it is quite difficult for Emacs to tell that the
numin the second statement is a variable without doing a full syntactic parse of the buffer. In theory, Emacs is capable of doing that (see e.g. here), but most modes use regular expressions for keyword highlighting. That implies some limitations on what can be achieved, but is often preferred by mode programmers for its simplicity (oh, well, all is relative).You may consider this a weakness of the general purpose text editor that Emacs is, when compared to more specialized IDEs that often do full parsing to provide intelligent error messages, support flexible code browsing and suggest quick fixes for bugs.
If you want to dive deeper into Emacs syntax highlighting, check out Font Lock and in particular font-lock-keywords, but be warned that it is a complex matter.