我正在尝试扩展
这是完成后的效果!
python.lang
文件,以便使像__init__
这样的方法得到突出显示。我一直在努力想出一个正则表达式,以匹配所有__privateMethods()
。
python.lang
是一个包含Python文件所有突出显示规则的XML文件。例如:<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>
这是完成后的效果!
![enter image description here](https://istack.dev59.com/q1jGv.webp)