tweekmonster / braceless.vim

:snake: Text objects, folding, and more for Python and other indented languages.
395 stars 13 forks source link

Folding functions inconsistent depending on indent #6

Closed AlbericC closed 8 years ago

AlbericC commented 8 years ago

with this sample code, folding myfunction leaves the two blank lines above the def in line 7, while folding myotherfunction also folds the blank lines above the if statement.

Is there any way to always leave the blanks or always fold blank lines ?

def myfunction():
    print("going")
    for i in range(10):
        print("loop {}".format(i))

def myotherfunction():
    print("going")
    for i in range(10):
        print("loop {}".format(i))
    return 

if __name__ == '__main__':
    myfunction()
    myotherfunction()
tweekmonster commented 8 years ago

Just tried some things and it looks like I can do either.

  1. If I exclude blank lines from folding, attempting to fold between your example functions will result in "no fold found". If you wrapped the whole thing in a class, the blank lines between the functions would fold the class.
  2. If the blank lines are included in the block above it, (blank lines will match the def's since they're the closest matching indent), folding while on the blank lines will fold up to the functions. If they were wrapped in a class, it would still fold up to the functions.

I'm inclined to say 2 is the best way and is most likely to be the expected behavior. What do you think?

AlbericC commented 8 years ago

What bugs me is the odd aspect of a folded file, with spacing uneven. So whatever is fine I guess.

Come to think of it, 2 is probably better for compactness.

AlbericC commented 8 years ago

Perfect: folding a bunch of functions with k<space> is definitely comfortable ! Thank you !

hovissimo commented 8 years ago

FWIW, I think you made the right choice. PEP-8 recommends empty lines following a lot of blocks, and if those aren't folded in I'm wasting twice the space in a folded file.

tweekmonster commented 8 years ago

I agree. It definitely grew on me. I was too narrowly focused on finding the block borders in the beginning. :expressionless: