如何在 TextMate 中启用 Python 注释的块折叠?
在 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,我正在使用默认的 Python.tmbundle 更新为通过 GetBundles 获取最新版本。
有谁知道如何做到这一点?预先感谢您的帮助! :)
在 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*$';
In TextMate 1.5.10 r1623, you get little arrows that allow you to fold method blocks:
Unfortunately, if you have a multi-lined Python comment, it doesn't recognize it, so you can't fold it:
def foo():
"""
How do
I fold
these comments?
"""
print "bar"
TextMate has this on their site on how to customize folding: http://manual.macromates.com/en/navigation_overview#customizing_foldings
...but I'm not skilled in regex enough to do anything about it. TextMate uses the Oniguruma regex API, and I'm using the default Python.tmbundle updated to the newest version via GetBundles.
Does anyone have an idea of how to do this? Thanks in advance for your help! :)
Adding the default foldingStartMarker
and foldingStopMarker
regex values for Python.tmbundle under the Python Language in Bundle Editor:
foldingStartMarker = '^\s*(def|class)\s+([.a-zA-Z0-9_ <]+)\s*(\((.*)\))?\s*:|\{\s*$|\(\s*$|\[\s*$|^\s*"""(?=.)(?!.*""")';
foldingStopMarker = '^\s*$|^\s*\}|^\s*\]|^\s*\)|^\s*"""\s*
;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看来多行注释折叠在 TextMate 中确实有效,但您必须完全像这样排列引号:
这似乎可以做到:
It appears that multi-line comment folding does work in TextMate, but your must line up your quotes exactly like so:
That seems to do it:
根据此 Textmate 邮件列表线程,如果您按照它到底,不支持 Python 的正确代码折叠。基本上,在foldingStartMarker 和foldingStopMarker 中实现的正则表达式不允许捕获,因此“结束折叠”开始处的间距量无法与“开始折叠”匹配。
Textmate 的创建者 Allan Odgaard 并未最终正式解决这个问题;然而,由于该线程来自 2005 年,我认为这是一个死问题,并且不会得到支持。
According to this Textmate Mailing list thread, if you follow it to the end, proper code folding for Python is not supported. Basically, regular expressions as implemented in the foldingStartMarker and foldingStopMarker do not allow for captures, thus the amount of spacing at the beginning of the "end fold" cannot be matched to the "begin fold".
The issue is not finally and officially addressed by Textmate's creator, Allan Odgaard; however since the thread is from 2005, I assume it is a dead issue, and not one that will be supported.