<HTML><BODY style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space; "><DIV><SPAN class="Apple-style-span"><B>Summary</B></SPAN></DIV><DIV><SPAN class="Apple-style-span">Folding should count fold start/stops at the current indentation level to properly pair a fold start with a fold end.</SPAN></DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV><B>Details</B></DIV>With my Lua bundle, I have folding set to work for block comments and functions (among other things).<DIV><BR class="khtml-block-placeholder"></DIV><DIV>If 'v' represents a start fold marker, and '^' represents and end fold marker, then creating an unindented (column 0) function looks like this:<DIV><BR class="khtml-block-placeholder"></DIV><DIV><FONT class="Apple-style-span" color="#000000"><FONT class="Apple-style-span" face="Courier">   <B><FONT class="Apple-style-span" color="#B0B0B0">v</FONT></B> function foo( )</FONT></FONT></DIV><DIV><FONT class="Apple-style-span" color="#000000"><FONT class="Apple-style-span" face="Courier">        print( 'hey' )</FONT></FONT></DIV><DIV><FONT class="Apple-style-span" face="Courier">   <B><FONT class="Apple-style-span" color="#B0B0B0">^</FONT></B> end</FONT></DIV><DIV><FONT class="Apple-style-span" face="Courier"><BR class="khtml-block-placeholder"></FONT></DIV><DIV>So far, so good. Now, suppose I block comment out this function (without indenting it):</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV><FONT class="Apple-style-span" face="Courier">   <B><FONT class="Apple-style-span" color="#B0B0B0">v</FONT></B> --[[</FONT></DIV><DIV><FONT class="Apple-style-span" face="Courier">   <B><FONT class="Apple-style-span" color="#B0B0B0">v</FONT></B> function foo( )</FONT></DIV><DIV><FONT class="Apple-style-span" face="Courier">        print( 'hey' )</FONT></DIV><DIV><FONT class="Apple-style-span" face="Courier">   <B><FONT class="Apple-style-span" color="#B0B0B0">^</FONT></B> end</FONT></DIV><DIV><FONT class="Apple-style-span" face="Courier">   <B><FONT class="Apple-style-span" color="#B0B0B0">^</FONT></B> ]]</FONT></DIV><DIV><FONT class="Apple-style-span" face="Courier"><BR class="khtml-block-placeholder"></FONT></DIV><DIV>This looks correct, but if I toggle the first folding marker, I get this:</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV><FONT class="Apple-style-span" face="Courier">   <B><FONT class="Apple-style-span" color="#B0B0B0">></FONT></B> --[[•••</FONT></DIV><DIV><FONT class="Apple-style-span" face="Courier">   <B><FONT class="Apple-style-span" color="#B0B0B0">^</FONT></B> ]]</FONT></DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>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.</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>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).</DIV></DIV></BODY></HTML>