kalekundert / vim-coiled-snake

Compact, but ready to strike. 🐍
124 stars 11 forks source link

num_blanks_below not working? #7

Closed ipartola closed 5 years ago

ipartola commented 5 years ago

I would like to have whitespace between classes and class methods not be hidden. For example:

class Foo:
    def bar(self):
        return self.a

    def bam(self):
         return self.b

class XX:
    def x(self):
        return 'x'

Should fold down to:

class Foo:

class XX:

How do I use num_blanks_below to make that happen?

kalekundert commented 5 years ago

This should keep whitespace between any kind of fold:

function! g:CoiledSnakeConfigureFold(fold)
    let a:fold.num_blanks_below = 0
endfunction

If you want to keep whitespace between just classes and class methods, but not other kinds of folds (e.g. regular functions), you could do something like this:

function! g:CoiledSnakeConfigureFold(fold)
  let is_class =  (a:fold.type == 'class')
  let is_method = (a:fold.type == 'function' && get(a:fold.parent, 'type', '') == 'class')

  if is_class || is_method
    let a:fold.num_blanks_below = 0
  endif
endfunction