From 68b54b0d1729cd036fcba1c85f85ad4af6e9e3dc Mon Sep 17 00:00:00 2001 From: Miguel Date: Tue, 29 May 2018 20:27:28 +0200 Subject: added vim stuff --- vim/vim-potion/ftplugin/potion/folding.vim | 38 ++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 vim/vim-potion/ftplugin/potion/folding.vim (limited to 'vim/vim-potion/ftplugin/potion/folding.vim') diff --git a/vim/vim-potion/ftplugin/potion/folding.vim b/vim/vim-potion/ftplugin/potion/folding.vim new file mode 100644 index 0000000..d4cb32b --- /dev/null +++ b/vim/vim-potion/ftplugin/potion/folding.vim @@ -0,0 +1,38 @@ +setlocal foldmethod=expr +setlocal foldexpr=GetPotionFold(v:lnum) + +function! s:NextNonBlankLine(lnum) + let numlines = line('$') + let current = a:lnum + 1 + + while current <= numlines + if getline(current) =~? '\v\S' + return current + endif + + let current += 1 + endwhile + + return -2 +endfunction + +function! s:IndentLevel(lnum) + return indent(a:lnum) / &shiftwidth +endfunction + +function! GetPotionFold(lnum) + if getline(a:lnum) =~? '\v^\s*$' + return '-1' + endif + + let this_indent = IndentLevel(a:lnum) + let next_indent = IndentLevel(NextNonBlankLine(a:lnum)) + + if next_indent == this_indent + return this_indent + elseif next_indent < this_indent + return this_indent + elseif next_indent > this_indent + return '>' . next_indent + endif +endfunction -- cgit v1.2.3