[TxMt] Fortran Folding Markers

Allan Odgaard throw-away-1 at macromates.com
Tue Aug 15 03:12:27 UTC 2006


On 14/8/2006, at 11:45, guerom00 wrote:

> I've made myself some folding markers for Fortran which look like  
> this :
>
> foldingStartMarker = '(^[\t ]*((?i:real|complex|integer)(.*)\s)*\b
> (?i:subroutine|program|module|function)\b(.*)$)|(^\s*\b(\w*)\s*:\s*
> \b(?i:do)\b|^\s*\b(?i:do)\b)|(^\s*(\b(?i:IF)\b)(.*)(\b(?i:THEN)\b))| 
> (^\s*
> \b(\w*)\s*:\s*(\b(?i:IF)\b)(.*)(\b(?i:THEN)\b))';
> foldingStopMarker = '^\s*\b(?i:end\sprogram|end\sfunction|
> end\ssubroutine|end\smodule|endif|enddo|end\sif|end\sdo)\b';

Not sure if I broke anything, but here is my swing at a simplified  
version:

     foldingStartMarker = '(?ix)^\s*(
             ( (real|complex|integer) .* \s )*
             (subroutine|program|module|function)\b
         |   (\w+ \s* : \s*)? (do | IF \b .+ \b THEN) \b
     )';

     foldingStopMarker = '(?ix)^\s*(
             end    (do|if)
         |   end \s (do|if|function|module|program|subroutine)
     )\b';

I took out all the (?i:…) wrapping and put (?i) at the start, switch  
to extendedmode (?x) for multi-line and white-space, removed many of  
the word-boundary anchors (these seemed redundant when followed by \s  
etc., merged a few things, e.g. make the label match just option and  
then an alternation for do versus IF … THEN instead of having four  
alternations. I also switched e.g. \w* to \w+ and .* to .+ -- I think  
at least one match would be required.

If it works for you, we can put them in the default Fortran bundle.

I didn’t fully understand the first branch of the start pattern. You  
can have type + random text repeated zero or more times, and then the  
subroutine/program/module/function keyword?

> They seem to work quite allright except for the old-fashioned
> do-loop of Fortran 77 which reads :
>
>       do 10 i=1,10
>          some code here
>          .......
> 10     continue
>
> Note that the “continue” statement which ends the loop has the
> label “10” which matches the loop one.
> I've no idea how to implement folding markers for this syntax and
> any help is appreciated :)

Currently it is required that fold start and stop patterns have the  
same indent, so I am afraid this one is not possible to match.





More information about the textmate mailing list