[Geany] Code folding doesn't work right.

Lex Trotman elextr at xxxxx
Wed Aug 4 13:11:14 UTC 2010


On 4 August 2010 20:32, Daniel Carrera <dcarrera at gmail.com> wrote:
> On Wed, Aug 4, 2010 at 11:28 AM, Lex Trotman <elextr at gmail.com> wrote:
>> Ok, thats because they are NEW fold points, the old ones you had
>> rolled up were removed when you turned the whole file into a string.
>>
>> New fold points are always open otherwise as you typed the program it
>> would fold up on you.
>
> I don't understand at all. What is a "new" fold point vs an "old" fold
> point? I'm talking about functions that have been in the file for more
> than a day. Isn't that "old" enough? Why does Geany keep unfolding
> everything? Are you saying that every single function in my program is
> a "new" fold point? How do I make them old?
>

Hi Daniel,

Sorry if I confused you.

let me try an example, of a simple piece of Perl, with the folds shown
as best I can in plain text

+-  if( $a<10 ){
|        print $i
--  }

+- sub aaa {
|      return 1
-- }

Then you fold up the sub aaa.

Now deciding to add some text to the print type a quote on that line,
the sub stays rolled up but notice that it changes colour to indicate
its part of the string and the fold indicators disappear, as they
should, it is parsed as part of a string.  So there is no fold point
here to store the information that this is folded.

You finish adding your string to the print statement and type closing
quotes.  So the sub aaa is now parsed as a sub again and so it gets
its fold markers back, but as noted above the information that it was
folded has been lost while it was a string.

>
>> This isn't a problem with other languages, except for Python triple
>> quotes, because AFAIK no other language embeds newlines in strings, so
>> the extent of an opened string is limited to one line and the fold
>> points don't disappear since they are on other lines.
>
>
> PHP does too, and Ruby as well, and JavaScript, and I suspect probably
> Lua. So that's at least six languages.

And folds in PHP and Ruby behave the same as Perl, they unfold, in
fact using the same scenario as above they unfold immediately you type
the opening quote, the others I don't know enough to test.

 It is news to me that you can't
> have a multi-line string in Java/C/C++. That sounds strange.

Dunno Java, you can't have unescaped embedded eol in C/C++ strings,
you include it with the \n escape.

>
>
>> Sadly I don't see an easy fix for the problem, what do other editors
>> do?  Maybe we can steal their algorithm if it works better.
>
> NetBeans doesn't have this problem. I don't know what algorithm they
> use, but I can tell you how it behaves. Say I start with the following
> PHP program:
>
> <?
>
> function test($var) {
>    // Do nothing.
>    // Do nothing.
>    // Do nothing.
> }
>
> ?>
>
> Then I fold the function:
>
> <?
>
> + function test($var) { ... }
>
> ?>
>
> Then I insert a string on top. The function remains folded:
>
>
> <?
> $string = "Hello
>
> + function test($var) { ... }
>
> ?>
>
> And the only way the function is expanded is if I *close* the string,
> on the other side of the function:
>
> <?
> $string = "Hello
>
> function test($var) {
>    // Do nothing.
>    // Do nothing.
>    // Do nothing.
> }
>
> ";
>
> ?>
>
>
> It seems to me that NetBeans figures out that the quotes are not
> properly closed (proven by the fact that the file ends in an
> un-terminated string) and it waits until the string is closed before
> deciding what to do with fold points. That's my best guess at their
> algorithm.

Geany doesn't actually control the parsing, its done by Scintilla the
editing component it uses.  So Geany doesn't actually know that there
is an unclosed string in the file, and so wouldn't be able to use this
approach as far as I can see.

Cheers
Lex

>
> Cheers,
> Daniel.
> --
> Intolerant people should be shot.
> _______________________________________________
> Geany mailing list
> Geany at uvena.de
> http://lists.uvena.de/cgi-bin/mailman/listinfo/geany
>



More information about the Users mailing list