4

在 TextMate 1.5.10 r1623 中,您会看到允许您折叠方法块的小箭头:

替代文字

不幸的是,如果你有一个多行的 Python 注释,它不能识别它,所以你不能折叠它:

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

 print "bar"

TextMate 在他们的网站上有关于如何自定义折叠的内容:http: //manual.macromates.com/en/navigation_overview#customizing_foldings

...但我对正则表达式的熟练程度不足以对此做任何事情。TextMate 使用Oniguruma正则表达式 API,我使用的是通过 GetBundles 更新到最新版本的默认 Python.tmbundle。

有谁知道如何做到这一点?在此先感谢您的帮助!:)


在 Bundle Editor 中的 Python 语言下添加 Python.tmbundle的默认值foldingStartMarker和正则表达式值:foldingStopMarker

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

2 回答 2

2

看来,多行注释折叠在 TextMate 中确实有效,但您必须完全像这样排列引号:

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

这似乎做到了:

在此处输入图像描述

在此处输入图像描述

于 2011-02-03T03:12:51.893 回答
1

根据此 Textmate Mailing list thread,如果您一直遵循它,则不支持 Python 的正确代码折叠。基本上,在 foldStartMarker 和 foldStopMarker 中实现的正则表达式不允许捕获,因此“结束折叠”开始处的间距量不能与“开始折叠”匹配。

Textmate 的创建者 Allan Odgaard 并没有最终正式解决这个问题。但是,由于该线程来自 2005 年,我认为这是一个死问题,而不是一个将得到支持的问题。

于 2011-06-02T20:29:13.640 回答