如何为 PHP 函数添加颜色突出显示?

Jef*_*ker 5 notepad++ php syntax-highlighting

我最近开始使用 Notepad++,并且发现它的样式功能的一部分让我感到困惑。

我目前正在尝试为所有 PHP 定义的函数(例如 count()、strlen() 等)着色。在设置->样式配置器中,您无法为此类功能列表添加新样式。相反,我已经开始编辑stylers.xmllangs.xml

为了添加新的着色,在langs.xml 中,我将 php 部分修改为以下内容:

<Language name="php" ext="php php3 phtml" commentLine="//" commentStart="/*" commentEnd="*/">
    <Keywords name="instre1">[default keywords]</Keywords>
    <Keywords name="instre2">[my function list]</Keywords>
</Language>
Run Code Online (Sandbox Code Playgroud)

[default keywords][my function list]被替换的生词。

我还编辑了stylers.xml 中的 php 部分,如下所示:

<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>
Run Code Online (Sandbox Code Playgroud)

更改的部分是最后一个“FUNCTIONS”行。


当我重新启动 Notepad++ 并进入 Settings->Style Configurator 部分时,在 php 语言下,存在 FUNCTIONS 样式。我可以更改样式的颜色,并且可以在“默认关键字”下查看整个关键字列表。但是,它不会改变我代码中单词的颜色。

当我编辑包含“if”、“and”和“true”等内容的 WORD 样式时,代码中的内容会发生相应的变化。

关于如何使这项工作的任何想法?

小智 2

我也有同样的问题。目前似乎还没有解决办法。

该问题与notepad++无关,而是与Scintilla项目有关。

这里描述一下。

ideatorrent中也指出了这一点。

看来我们必须等待 Scintilla 的更新。