How can I add color highlighting for PHP functions?
Posted
by
Jeff Gortmaker
on Super User
See other posts from Super User
or by Jeff Gortmaker
Published on 2011-09-24T18:17:47Z
Indexed on
2012/12/08
11:17 UTC
Read the original article
Hit count: 286
I've recently begun using Notepad++, and have found a part of its styling functionality that confuses me.
I'm currently attempting to color all of PHP's defined functions (such as count(), strlen(), etc.). In the Settings->Style Configurator, you cannot add a new style for such a function list. Instead, I have begun editing the stylers.xml and langs.xml.
To add the new coloring, in langs.xml, I've modified the php section to the following:
<Language name="php" ext="php php3 phtml" commentLine="//" commentStart="/*" commentEnd="*/">
<Keywords name="instre1">[default keywords]</Keywords>
<Keywords name="instre2">[my function list]</Keywords>
</Language>
The [default keywords]
and [my function list]
are replaced with wordlists.
I've also edited the php section in stylers.xml to look like the following:
<LexerType name="php" desc="php" ext="">
<WordsStyle name="QUESTION MARK" styleID="18" fgColor="FF0000" bgColor="FDF8E3" fontName="" fontStyle="0" fontSize="" />
<WordsStyle name="DEFAULT" styleID="118" fgColor="000000" bgColor="FEFCF5" fontName="" fontStyle="0" fontSize="" />
<WordsStyle name="STRING" styleID="119" fgColor="FF0000" bgColor="FEFCF5" fontName="" fontStyle="0" fontSize="" />
<WordsStyle name="STRING VARIABLE" styleID="126" fgColor="FF0000" bgColor="FEFCF5" fontName="" fontStyle="1" fontSize="" />
<WordsStyle name="SIMPLESTRING" styleID="120" fgColor="FF0000" bgColor="FEFCF5" fontName="" fontStyle="0" fontSize="" />
<WordsStyle name="WORD" styleID="121" fgColor="008040" bgColor="FEFCF5" fontName="" fontStyle="1" fontSize="" keywordClass="instre1">True False</WordsStyle>
<WordsStyle name="NUMBER" styleID="122" fgColor="FF0000" bgColor="FEFCF5" fontName="" fontStyle="0" fontSize="" />
<WordsStyle name="VARIABLE" styleID="123" fgColor="0080FF" bgColor="FEFCF5" fontName="" fontStyle="0" fontSize="" />
<WordsStyle name="COMMENT" styleID="124" fgColor="FF8040" bgColor="FEFCF5" fontName="" fontStyle="0" fontSize="" />
<WordsStyle name="COMMENTLINE" styleID="125" fgColor="FF8040" bgColor="FEFCF5" fontName="" fontStyle="0" fontSize="" />
<WordsStyle name="OPERATOR" styleID="127" fgColor="8000FF" bgColor="FEFCF5" fontName="" fontStyle="0" fontSize="" />
<WordsStyle name="FUNCTIONS" styleID="128" fgColor="000080" bgColor="FEFCF5" fontName="" fontStyle="1" fontSize="" keywordClass="instre2"></WordsStyle>
</LexerType>
The changed part is the last "FUNCTIONS" line.
When I restart Notepad++ and go into the Settings->Style Configurator section, under the php language, the FUNCTIONS style exists. I can change the style's color, and can see the entire keyword list under 'Default Keywords'. However, it is not changing the coloring of the words in my code.
When I edit the WORD style, which contains stuff like 'if', 'and', and 'true', things change accordingly in my code.
Any ideas on how to make this work?
© Super User or respective owner