代码折叠,python的一个独特问题? [英] code folding, a unique problem to python?

查看:122
本文介绍了代码折叠,python的一个独特问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

具体来说,我正在使用UltraEdit并且可能没有完美的方式

用它实现代码折叠,给出它如何使用它的语法

突出显示要执行此操作的文件(即,您必须指定一个打开和

关闭字符,其中包含代码,如大括号)。


但我的问题更为笼统:是否有可能实现代码

使用Python进行折叠,因为它没有真正的块分隔符?或者是

这仍然是您使用的特定编辑器/ IDE的问题?就我而言

我已尝试(如其他地方所建议的)使用''def''作为开头和

关闭关键字,但这当然会包含即使您的函数定义之间有更多代码(例如,作为新类定义的
),两个之间的所有内容之间的内容都是定义的。


所以也许我被困在UE中,但是我很好奇是否有一些通用的方式

这样做,或者Python是否过于简单和简洁以获得自己的好处? :)

解决方案

>但我的问题更为笼统:是否可以使用Python实现

代码折叠,因为它没有真正的块分隔符?或者这仍然是您使用的特定编辑器/ IDE的问题?


是的,这是一个编辑器。在Vim中,它就像


:set foldmethod = indent


和presto!我相信其他质量的编辑提供类似的

选项。 ;)

所以也许我被困在UE中,但是我很好奇是否有一些通用的方法来做到这一点,或者Python太简单了并且
简洁自己的好处? :)




大多数编辑都过于简单而简洁[他们自己的

good。 :)


-tkc


JohnSalernoírta:

具体来说,我正在使用UltraEdit并且可能没有完美的方法来实现代码折叠,考虑到它如何使用它的语法
突出显示文件(即,你有指定一个打开和
关闭字符,在其中包含代码,例如大括号。

但我的问题更通用:是否可以实现代码<鉴于它没有真正的块分隔符,用Python折叠?或者这仍然是你使用的特定编辑器/ IDE的问题?就我而言
我已经尝试过(如其他地方所建议的那样)使用''def''作为开头和
关闭关键字,但这当然会包含两个
defs之间的所有内容,即使你的函数定义之间有更多的代码(例如新的类定义)。

所以也许我被困在UE中,但我很好奇是否有是一些通用的方法来做到这一点,还是Python过于简单和简洁自己的好处? :)




有很多编辑器可以做到这一点。对于Python,折叠基于

IDENT和DEDENT令牌。您可以在Python中查找他们的定义

语言参考。


例如,SPE可以执行此操作。请参阅此屏幕截图:

http://stani.be/python/spe/screensho...ux-blender.png

Best,


Laszlo


John Salerno写道:

但我的问题更为笼统:是否有可能实现代码
用Python折叠,因为它没有真正的块分隔符?或者这仍然是你使用哪个特定编辑器/ IDE的问题?




因为Python语法*有*实际块分隔符(查找INDENT和

语言参考中的DEDENT),这是一个编辑问题。


< / F>


Specifically, I''m using UltraEdit and perhaps there''s no way perfect way
to implement code folding with it, given how it uses its syntax
highlighting file to do so (i.e., you have to specify an "Opening" and
"Closing" character in which to enfold code, such as braces).

But my question is more general: is it possible to implement code
folding with Python given that it has no real block delimiters? Or is
this still a matter of which particular editor/IDE you use? For my part
I''ve tried (as was suggested elsewhere) to use ''def'' as an opening and
closing keyword, but this of course will enfold everything between two
defs, even if you have more code between your function definitons (such
as a new class definition).

So maybe I''m stuck in UE, but I''m curious if there is some general way
to do this, or is Python just too simple and concise for its own good? :)

解决方案

> But my question is more general: is it possible to implement

code folding with Python given that it has no real block
delimiters? Or is this still a matter of which particular
editor/IDE you use?
Yes, it is an editor thing. In Vim, it''s as simple as

:set foldmethod=indent

and presto! I''m sure other quality editors provide similar
options. ;)
So maybe I''m stuck in UE, but I''m curious if there is some
general way to do this, or is Python just too simple and
concise for its own good? :)



Most editors are "just too simple and concise for [their] own
good". :)

-tkc



John Salerno írta:

Specifically, I''m using UltraEdit and perhaps there''s no way perfect way
to implement code folding with it, given how it uses its syntax
highlighting file to do so (i.e., you have to specify an "Opening" and
"Closing" character in which to enfold code, such as braces).

But my question is more general: is it possible to implement code
folding with Python given that it has no real block delimiters? Or is
this still a matter of which particular editor/IDE you use? For my part
I''ve tried (as was suggested elsewhere) to use ''def'' as an opening and
closing keyword, but this of course will enfold everything between two
defs, even if you have more code between your function definitons (such
as a new class definition).

So maybe I''m stuck in UE, but I''m curious if there is some general way
to do this, or is Python just too simple and concise for its own good? :)



There are many editors that do this. For Python, folding is based on
IDENT and DEDENT tokens. You can look for their definition in the Python
Language Reference.

For example, SPE can do this. See this screenshot:

http://stani.be/python/spe/screensho...ux-blender.png
Best,

Laszlo


John Salerno wrote:

But my question is more general: is it possible to implement code
folding with Python given that it has no real block delimiters? Or is
this still a matter of which particular editor/IDE you use?



since the Python syntax *has* real block delimiters (look up INDENT and
DEDENT in the language reference), it''s an editor issue.

</F>


这篇关于代码折叠,python的一个独特问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆