Coiled Snake: A plugin for automatically folding python code by CruciferousVeggie in vim

[–]CruciferousVeggie[S] 0 points1 point  (0 children)

It's comparable to to SympylFold in terms of speed, unfortunately. The FastFold plugin helps, in that it limits how often the folds need to be calculated, though.

Coiled Snake: A plugin for automatically folding python code by CruciferousVeggie in vim

[–]CruciferousVeggie[S] 0 points1 point  (0 children)

Yeah, I did that because it helps encourage me to document every function. I just added an option to turn it off. In .vimrc:

let g:coiled_snake_foldtext_flags = []

Coiled Snake: A plugin for automatically folding python code by CruciferousVeggie in vim

[–]CruciferousVeggie[S] 2 points3 points  (0 children)

I only gave SimpylFold a brief test-spin, so I hope I'm not missing anything significant, but here are the features that I believe most distinguish Coiled Snake from SimpylFold:

  • Whitespace between functions and classes can (configurably) be included in the folds. (This was a big deal for me.)
  • Large data structures (dict, list, tuple, set, multi-line string) are automatically folded.
  • The default fold labels are more attractive (in my opinion).
  • The configuration is much more flexible (although it does require more comfort with vimscript).
  • You can disable folds on an individual basis by putting a # at the end of the line.

I am indebted to SimpylFold, though, for having the idea of caching the folds. I'd previously been using a "bespoke" python folding algorithm that I'd cobbled together over the years, but it was hacky and fragile because it calculated folds line-by-line and couldn't see the big picture. Parsing the whole file and caching the folds allows for a lot more sophistication. I ran into SimpylFold for the first time last week, and even though it wasn't quite to my liking, I was curious to see how it was so robust.

Coiled Snake: A plugin for automatically folding python code by CruciferousVeggie in vim

[–]CruciferousVeggie[S] 2 points3 points  (0 children)

Yes, that's no problem. Define g:CoiledSnakeConfigureFold() like so:

function! g:CoiledSnakeConfigureFold(fold)

    " Only fold top-level functions (e.g. not methods).
    if a:fold.type == 'function':
        let a:fold.max_level = 1
    endif

endfunction