折叠 TextMate 中的所有 PHP 函数
我对如何在 TextMate 中折叠和组织我的代码有点耿耿于怀,而 TextMate 的代码折叠行为一直困扰我的一个问题是,对于 PHP,如果我有一个包含一堆函数的文件,而我只想要折叠所有函数(但不是其内容),我必须单击每个函数并按 F1(或单击行指示器中的小折叠按钮)。
我发现 在 TextMate 中全部折叠,这还可以,但不太理想,因为折叠了所有级别代码意味着每个函数内的每个 if、else、while 等语句也将被折叠,这意味着我在处理函数时必须不断单击或按 F1。
有什么方法可以让 TextMate 将 PHP 文件内的所有函数识别为“级别 1”,这样当我选择“在级别:1 切换折叠”时,函数会折叠(但内部没有任何内容)?
现在,如果我这样做,只有整个文件中的第一个函数被折叠。如果我执行第 4 级,则第二个函数会折叠(我不确定为什么会这样...我所有的函数都缩进完全相同...可能是我使用空格而不是制表符来缩进 a 中的内容功能?)。
以下是捆绑包编辑器中定义的开始和停止标记(默认值):
foldingStartMarker = '(/\*|\{\s*$|<<<HTML)';
foldingStopMarker = '(\*/|^\s*\}|^HTML;)';
I'm a bit anal about how I fold and organize my code in TextMate, and one issue that continually bothers me about TextMate's code folding behavior is that, with PHP, if I have a file with a bunch of functions, and I just want to fold all the functions (but not their contents), I have to click on each function and hit F1 (or click the little folding button in the line indicator).
I found Collapse All in TextMate, which is okay, but less than ideal, since folding all levels of code means that every if, else, while, etc. statement inside every function will also be folded, meaning I have to keep klicking or hitting F1 while I work through a function.
Is there any way to make TextMate recognize all functions inside a PHP file as 'level 1' so when I choose 'Toggle foldings at Level: 1', the functions are collapsed (but nothing inside)?
Right now, if I do that, only the first function in the entire file is collapsed. If I do level 4, the second function is collapsed (I'm not sure why this is so... all my functions are indented exactly the same... could it be that I use spaces instead of tabs to indent what's inside a function?).
Here are my start and stop markers (defaults) as defined in the Bundle Editor:
foldingStartMarker = '(/\*|\{\s*$|<<<HTML)';
foldingStopMarker = '(\*/|^\s*\}|^HTML;)';
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
仅供参考,我录制了一个宏,其中查找正则表达式“^function”,然后按向右箭头键,然后按 F1(折叠该函数),并将该宏设置为键盘快捷键。
它并不像一次折叠所有内容那么棒,但现在当我打开一个包含数百个函数的大文件时,我可以多次敲击我的组合键,所有函数都会被折叠:)
[编辑:< /strong> 我在修复这个问题上做了更多工作(对我来说),因为我不想折叠注释块,但确实想要折叠函数(对于 Drupal 模块文件等) ),我在 PHP 语言中更改了以下两行语法包(在 Textmate 的包编辑器中):
to:
所以,它现在对我来说工作得很好。哇!]
Just FYI, I've recorded a macro of me finding the regex '^function ', then pressing the right arrow key, then pressing F1 (to fold the function), and I've set that macro to a keyboard shortcut.
It's not as awesome as just folding everything at once, but now when I open a huge file with hundreds of functions, I can hit my key combo a bunch of times, and all the functions get folded :)
[Edit: I've worked a bit more at fixing this (for me), and since I don't want to fold comment blocks, but do want to fold functions (for Drupal module files and such), I've changed the following two lines in the PHP language syntax bundle (in Textmate's bundle editor):
to:
So, it's working pretty well for me now. Woot!]