Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Code Folding

by afresh1 (Hermit)
on Dec 29, 2008 at 22:48 UTC ( [id://733139] : note . print w/replies, xml ) Need Help??


in reply to Code Folding

For folding it doesn't matter if the below is folded recursively. It is more important for unfolding. It allows you to unfold an entire sub, or just the single level.

Imagine:

sub abc { my ($x) = @_; my $z; foreach my $y (@{ $x }) { # do xxx # on # lots # of # lines } return $z; }

when it is folded it would be (kinda like this in vim)

+-- 14 lines: sub abc {

when you unfold, would you get back the initial example, or

sub abc { my ($x) = @_; my $z; +--- 7 lines: foreach my $y (@{ $x }) { return $z; }

That is the purpose of recursive folding IMHO.

In Vim, it remembers the folded status of things, so if it is in the first example and you fold to the second example, when you unfold, it goes back to the first example. However, if you fold recursively, the default unfold will unfold to the third example.

l8rZ,
--
andrew

Replies are listed 'Best First'.
Re^2: Code Folding
by sir_lichtkind (Friar) on Dec 30, 2008 at 12:47 UTC
    Your' right but i was aware of that just didn't want point out all cornercases. My point was however that there is no immediat purpose to fold recursively. you have to make two operations, when i need just one to achieve the same result. hope could make this clearer now.

    Kephra, a beautiful Perl Editor lives at http://kephra.sourceforge.net

      Although vim has many commands for folding things, I really only use 2, za and zA. They toggle folding at the cursor, capital is recursive.

      My point is that folding can appear simple, but depending on features you want to allow it can be more complex.

      l8rZ,
      --
      andrew
        Thanks for the answer and it agrees to my gut feeling that these are the two most important. Thatswhy I put them together on the easier reachable key ("-" alt+minus and alt+shift+minus- the other 2 on plus) and on the 2 leftmost mouse keys and but the new sibling fold on right because it has also similarities with a popup menu which usually appears on right click.

        Kephra, a beautiful Perl Editor, designed along Perl like Paradigms lives at http://kephra.sourceforge.net

      I don't think you do acheive the same result, though i havn't managed to get the wX library to install so i'm not sure.

      sub test { # 5 important lines while ($x) { # 10 lines of good stuff } for (1..5) { # 100 lines of crap } }

      Now if you fold that recursively you get

       sub test { ... }

      and then a recursive unfold yeilds to original back. However a non recursive unfold returns

      sub test { # 5 important lines while ($x) { ... } } for (1..5) { ... } }

      So there are cases where a user might want a recursive fold/unfold, and other where they do not. Now if you through in remembering the fold state, maybe i've already folded the "100 lines of crap" but i left "10 lines of good stuff" unfolded. If i did a non recursive fold on test, and then a nonrecursive unfold i would still be able to see my "5 important lines" and the "10 lines of good stuff" but the "100 lines of crap would not be unfolded". If however you alwas do a recursive fold/unfold then as soon as i unfold test it unfolds my "100 lines of crap"


      ___________
      Eric Hodges
        because both loops are siblings in node hierarchy they get both folded by my new shiny sibling fold. differences appear just when you open the loops. if folded recursive you only see next level und can unfold further. if choden sibling fold you get all at once, because no further folding was done. but there are cases when recursive has advantages. thatsway i added it too.(see update above.)

        thank you too for answering.

        Kephra, a beautiful Perl Editor, designed along Perl like Paradigms lives at http://kephra.sourceforge.net