I appreciate the help, Lex. What I meant for the scanning was that it would happen twice, once to determine that, e.g. fold level 5 is actually fold level 2 and fold level 9 is actually fold level 3, and then again to do the actual folding. I think your outline of folding-as-you-go would probably work, too, and may, in fact, be better.

It would only scan when the user initiates the (un)fold all at level X action. Geany scans the whole file for the (un)fold all action already, and given that that doesn't take too long, I'm guessing that this wouldn't either. But I haven't tried it out yet.

Peter


On Sat, Jan 25, 2014 at 3:13 PM, Lex Trotman <elextr@gmail.com> wrote:



On 26 January 2014 02:53, Peter O'Malley <ooomalley@gmail.com> wrote:
On Fri, Jan 24, 2014 at 2:29 PM, Lex Trotman <elextr@gmail.com> wrote:
> ...
> 4) The folder would have to always count increases/decreases from the start
> of the file to actually get a level that counts correctly or save state on
> the file.  At the moment it starts from near the start of the visible range
> most of the time to make it faster, and saves no state so it only knows the
> actual indentation, not the level number.  You will have to keep count
> yourself as you go through the file clearing/setting the fold points.
>
> Cheers
> Lex
>

Let's say that I'm only interested in python code that's (close to)
PEP 8 and ignore stuff like triple-quoted strings for the moment.

Ok, just thought docstrings might be useful for you to show.

 
"Keeping count myself" throughout the entire file is basically the
only idea I had come up with. I was thinking of something fairly
simple like this:
* User requested to fold level 2
* Check document for HEADERFLAG's at fold level 1; found some; increment counter
* Check level 2... none exist, level 3... none exist... (etc) found
some at level 5
* Counter now at 2, so fold all level 5

Obviously this wouldn't scale too well for large files. But in my
(limited) experience python files don't grow very large...

wrong :)

If its put in Geany-Plugins you *will* get bug reports if its slow with big files.  Remember you are maintaining it :)

If I read your above right, you are scanning the file multiple times.  And what is triggering this?  How often will it run and annoy your users?  But if its only triggered manually I would have said its ok.

But in any case, naively I would have said only one scan is needed using the levels from the current lexer (warning, not much thought gone into this :) 

level = 0
fold_level = 0
for all lines:
    line_level = get_fold_level_of_line()
    if fold_level < line_level): ++level
    elif fold_level > line_level: --level
    fold_level = line_level
    if line has header_flag:
        if level < level_to_expand_to: unfold
        else fold
 
and I
personally don't like large source files anyway ;-).

Again if you are making it public via G-P it needs "a reasonable level of quality" since its not just your files any more :)
 
(And I suppose
this functionality could be turned on/off with a setting, too.)


Well, its a plugin, so it can be disabled. Thats fine.

Cheers
Lex
 
How does this sound?

And thanks for the pointers, too!

Best,
Peter
_______________________________________________
Devel mailing list
Devel@lists.geany.org
https://lists.geany.org/cgi-bin/mailman/listinfo/devel

Again if you are making it public via G-P it needs "a reasonable level of quality"


_______________________________________________
Devel mailing list
Devel@lists.geany.org
https://lists.geany.org/cgi-bin/mailman/listinfo/devel