Question

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;)';
Was it helpful?

Solution

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):

foldingStartMarker = '(/\*|\{\s*$|<<<HTML)';
foldingStopMarker = '(\*/|^\s*\}|^HTML;)';

to:

foldingStartMarker = '(\{\s*$|<<<HTML)';
foldingStopMarker = '(^\s*\}|^HTML;)';

So, it's working pretty well for me now. Woot!]

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top