[TxMt] Folding Request - Count Pairs

Gavin Kistner gavin at refinery.com
Wed Oct 12 13:16:38 UTC 2005


Summary
Folding should count fold start/stops at the current indentation  
level to properly pair a fold start with a fold end.

Details
With my Lua bundle, I have folding set to work for block comments and  
functions (among other things).

If 'v' represents a start fold marker, and '^' represents and end  
fold marker, then creating an unindented (column 0) function looks  
like this:

    v function foo( )
         print( 'hey' )
    ^ end

So far, so good. Now, suppose I block comment out this function  
(without indenting it):

    v --[[
    v function foo( )
         print( 'hey' )
    ^ end
    ^ ]]

This looks correct, but if I toggle the first folding marker, I get  
this:

    > --[[•••
    ^ ]]

In other words, the folding looked for the first end marker that was  
at the same depth as the start marker, and (incorrectly) used the  
'end' line. Instead, I propose that it should scan down and when it  
sees the second start fold marker at the same depth, add 1 to a  
counter; when it sees the first close fold marker at that depth, it  
checks the counter...since it is non-zero, it subtracts one. Finally,  
when it sees the last fold marker, and the counter is at zero, then  
it uses that as the correct, paired end fold.


P.S. What's the netiquette/guideline regarding attaching screenshot  
images inline to an email message to a mailing list, when that  
mailing list is almost certain to be used solely by MacOS users, who  
likely are using a Mail program that would support them? Would have  
been easier than the ascii art above (which itself is non-plain text,  
so I'm violating another common mailing list rule there).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macromates.com/textmate/attachments/20051012/efa636f2/attachment.html>


More information about the textmate mailing list