2011-01-09 107 views
4

在TextMate的1.5.10 r1623,你的小箭头,使您可以折叠方法块:如何在TextMate中为Python注释启用块折叠?

alt text

不幸的是,如果你有一个多行的Python评论,不承认它,所以你不能把它折叠:

def foo(): 
""" 
How do 
I fold 
these comments? 
""" 

print "bar" 

TextMate中有这对他们如何定制折叠网站:http://manual.macromates.com/en/navigation_overview#customizing_foldings

...但我并不擅长于正则表达式够做任何事AB出来吧。 TextMate使用Oniguruma正则表达式API,我使用通过GetBundles更新到最新版本的默认Python.tmbundle。

有没有人有如何做到这一点的想法?在此先感谢您的帮助! :)


添加默认foldingStartMarker和Python语言在包编辑器下Python.tmbundle foldingStopMarker正则表达式的值:

foldingStartMarker = '^\s*(def|class)\s+([.a-zA-Z0-9_ <]+)\s*(\((.*)\))?\s*:|\{\s*$|\(\s*$|\[\s*$|^\s*"""(?=.)(?!.*""")'; 
foldingStopMarker = '^\s*$|^\s*\}|^\s*\]|^\s*\)|^\s*"""\s*$'; 
+0

这不应该是将foldingStartMarker和foldingStopMarker定义为`“”“|'''`吗? – delnan 2011-01-09 03:30:46

+0

@delnan,我认为你在正确的轨道上。当前的正则表达式值有点复杂将它们添加到上面的问题中) – 2011-01-09 14:53:28

回答

1

this Textmate Mailing list thread,如果你按照它的结束,不支持正确的代码折叠为Python。基本上,在foldingStartMarker和foldingStopMarker中实现的正则表达式不允许捕获,因此“end fold”开始处的间隔量不能与“begin fold”匹配。

这个问题并没有最终由Textmate的创造者Allan Odgaard正式解决;然而,由于线程是从2005年开始的,我认为这是一个死亡问题,而不是一个将被支持的问题。

2

看来,多行注释的折叠确实在TextMate的工作,但你必须精确地排队你的报价,如下所示:

""" Some sort of multi 
    line comment, which needs quotes 
    in just the right places to work. """ 

这似乎做到这一点:

enter image description here

enter image description here

+1

这是正确的,但是您没有提及重要的事实,即您的第21行需要与第18行对应的选项卡,否则它将无法工作 – 2011-08-28 04:07:42

相关问题