[TxMt] Folding in C

Allan Odgaard throw-away-1 at macromates.com
Fri Jan 6 02:58:36 UTC 2006


On 5/1/2006, at 9:53, Daniel Vollmer wrote:

> [...] Here, the end-comment marker has to have two *s, it doesn't  
> fold with one, but if I add a third * to the open comment bit, then  
> it still works?

The folding patterns just need to match a subset of the line. You  
could e.g. add (?!\*) after the two asterisks to ensure that a third  
doesn't follow (if this is desired).

> I am really bad with regular expressions, so I couldn't figure out  
> what they're trying to (referring to the folding patterns). I am  
> aware though, that I can change them myself if I were so inclined,  
> but I just wanted to ask whether TM expects me to do the above  
> things in different way which may be equally nice.

The simple case should be straight forward, as in something like: “\ 
{\s*($|/\*|//)”. This matches { which are last on the line, or which  
are followed by a block or single line comment. But then, one may  
ensure that the block comment either do not end at this line, or that  
only \s*$ follows the */ part…

I'm told that if you can write a wavelet codec, you should be able to  
learn this stuff :)

Though I now made them:

    foldingStartMarker = '/\*\*(?!\*)|\{\s*($|//|/\*(?!.*?\*/.*\S))|^@ 
(interface|protocol|implementation)\b';
    foldingStopMarker = '(?<!\*)\*\*/|^\s*\}|^@end\b';

The C pattern btw already seemed to handle the comments after { (I  
think Kevin added this some weeks ago), but maybe you were actually  
using C++ (which didn't have it).




More information about the textmate mailing list