简体   繁体   中英

Add to Python Syntax Highlighting in Notepad++

I wanted to add syntax highlighting for Python built-ins in Notepad++. I modified langs.xml in AppData/Notepad++ by adding this line to the python tag:

<Keywords name="instre2">len max min sum map str int reduce</Keywords>

I also added this line to the python tag in stylers.xml in the same location:

<WordsStyle name="BUILTINS" styleID="13" fgColor="8080FF" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" keywordClass="instre2" />

When I go to Settings->Style Configurator->Python->BUILTINS, I see my list of built-in functions as well as the colour I assigned to them. However, when editing a Python file, the built-in functions are not highlighted. Why is this?

I found something similar here , but I could not find the file LexPython.cxx. How do I resolve this? Is it possible to resolve?

基于.cxx文件扩展名,该扩展名会使LexPython.cxx成为c ++源文件,因此听起来您需要编写Python词法分析器并将其添加到Notepad ++生成过程中。

What he meant is the "...\\scintilla\\lexers\\LexPython.cxx" in the source code package of Notepad++.

You can't add an additional type just like that. I would recommend to simply add your BUILTINS words to the existing KEYWORDS list for instance. That's what I usually do.

You are almost there ... Just set the styleID to 14 for the keyword list you added, only 14 works. Now you can set the color through the style configurator. See the effect here built-in function highlighting The built-in function int() and range() are rendered with custom color.

A little bit explanation:

It's pointed out here that " ... Syntilla lexers use predefined numbers for coloring things (these are the "styleID"s) ..." and they're defined for each language. You can check it in the notepad++ source file SciLexer.h.

There's actually a group WORD2 with id 14 defined for python (SCE_P_WORD2), but it's not used in the default stylers.xml.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM