我正在尝试扩展python.lang
文件,以便它能够使__init__
这样的方法突出显示。我一直在努力想出一个能与所有__privateMethods()
相匹配的Regex。
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"/>
然后添加卡尔斯在他的答复中提供了的Regex
<context id="private-methods" style-ref="private-methods">
<match>(__[a-zA-Z_]*(__)?)</match>
</context>
这是你做完后的样子!
发布于 2011-02-04 21:00:17
它应该是:
(__[a-zA-Z0-9_]*(__)?)
为了匹配以下所有内容:
__hello()
__init__()
__this_is_a_function()
__this_is_also_a_function__()
__a_URL2_function__()
发布于 2011-02-04 20:23:18
将前面的案例与以下(圆柱形例子)相匹配:
(^__[a-z]*__$)
https://stackoverflow.com/questions/4902509
复制相似问题