A very similar question came up internally at WRI, so I have a nearly ready-made answer. In that case, the fellow wanted to highlight certain loop constructs, like
For in his code automatically. Here's how I responded.
In a fresh notebook, Format->Edit Stylesheet..., then paste and interpret the
cells below at the bottom of the stylesheet. And voila, you'll got purple
Fors in the notebook the stylesheet modified.
FontColor->RGBColor[0.5, 0, 0.5]]
Some caveats about using this:
- The thing on the rhs of the rule must be a named style (a slightly archaic and embarrassing limitation in a modern FE, but that's the way it is in v8).
- There's a bug (fixed for future versions) in the validation of this option which can cause a crash if you feed it values formatted in any way other than this.
- This will only work in typeset cells
- This will only work to style things which are lexically word-type tokens. You cannot, for example, auto-style two words in sequence, a subexpression with an operator, or a substring of a word token.