我正在尝试扩展python.lang
文件,以便它使方法像__init__
突出显示。我一直在尝试想出一个匹配 all 的正则表达式__privateMethods()
。
这python.lang
是一个 XML 文件,其中包含 python 文件的所有突出显示规则。前任:
<context id="special-variables" style-ref="special-variable">
<prefix>(?<![\w\.])</prefix>
<keyword>self</keyword>
<keyword>__name__</keyword>
<keyword>__debug__</keyword>
</context>
如何扩展它以匹配双下划线?
[解决方案]:我添加到python.lang
文件中的内容(如果有人感兴趣):
首先,您需要在定义样式的顶部附近添加此行。
<style id="private-methods" _name="Private Methods" map-to="def:special-constant"/>
然后,您将添加Carles 在他的回答中提供的正则表达式:
<context id="private-methods" style-ref="private-methods">
<match>(__[a-zA-Z_]*(__)?)</match>
</context>
这是完成后的样子!