[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [StrongED] Better C folding



In message <8360b74553.fjgraute@xxxxxxxxx>
          Fred Graute <fjgraute@xxxxxxxxx> wrote:

> In message <CALE3-UAGtOyo43eCu80qotDiy2uSYF0EpXMw0=abmaMomybcKg@xxxxxxxxxxxxxx>
>           Richard Griffin <rik.griffin@xxxxxxxxxxxxxxxxxxx> wrote:
>
> > I noticed that the default C ModeFile doesn't fold functions
> > perfectly. For example it doesn't match a function that returns
> > "unsigned long long int".

[snip]

> > In the Search section I've altered the Function pattern:
> >
> >  function_ ("extern" | "volatile" | "static" | "signed" | "unsigned" |
> > "long") {" "}
> >  Function < {function_} ~"else" ~"return" {AD|"_"}+ {' *'}+ {AD|"_"}+
> > {" "} "(" * ")" {\s} "{"
>
> This seems to work reasonably well but I did come a across a couple of
> issues. It doesn't work when the function's parameter list is split over
> multiple lines or when old K&R style definitions are used.
>
> I've altered it to:
>
>   function_ {("extern" | "volatile" | "static" | "signed" | "unsigned" |
>   "long") {" "}} {AD|"_"}+ {' *'}+
>   Function < [function_] {AD|"_"}+ {" "} "(" ** ")" {\s} "{"
>
> Which seems to work better but may have issues too.

There were indeed issues. It didn't find functions which used, say,
'static unsigned long', nor did it find functions that return user
defined datatypes. Also, sometimes it would produce false positives.

After a quite a bit of experimentation I've come up with the following:

  FuncType  < {{' *'} {\i}+ {\s} ~"("}+ {\s} {'*'} {\s}
  FoldFunc  FuncType {"("} @0 {\i}+ {")"} {\s} {\( {" "}}+ ~";" ** \{ @9
  Function  FuncType {"("} @0 {\i}+ @9 {")"} {\s} {\( {" "}}+ ~";" ** \{

A lot more involved but so far it seems to be working rather well. It
certainly seems to perform better than ListOfC.

The search constructs '\(' and '\{' are new. They will test the current
character against the bracket given and if they match, search through
the text to the matching closing bracket, skipping comments and strings.
The search then continues after the closing bracket.

Only problem was that the new constructs used GotoBracket functionality
which meant that if the text was folded, all folds would be opened. I've
now rewritten GotoBracket so it doesn't use syntax colouring anymore,
and that's stopped folds from being opened.

If you'd like to try this then let me know and I'll send you a copy of
4.70a1 .

Cheers,
Fred.

-- 
StrongED Developer
http://www.stronged.iconbar.com/

-- 
To unsubscribe send a mail to StrongED+unsubscribe@xxxxxxxxxxxxxx