summaryrefslogtreecommitdiff
path: root/xxx/vim-old/vim-potion/ftplugin/potion/folding.vim
diff options
context:
space:
mode:
authorMiguel <m.i@gmx.at>2021-11-03 19:59:44 +0100
committerMiguel <m.i@gmx.at>2021-11-03 19:59:44 +0100
commitf70d5dc9b1f546bcfae67f067fe2e3b67f94ca45 (patch)
tree3bffaa05b78db0e393bc44eb273f771e08320154 /xxx/vim-old/vim-potion/ftplugin/potion/folding.vim
parente3fb79099e233185825b248a0b275173bd182239 (diff)
improving dotfiles
Diffstat (limited to 'xxx/vim-old/vim-potion/ftplugin/potion/folding.vim')
-rw-r--r--xxx/vim-old/vim-potion/ftplugin/potion/folding.vim38
1 files changed, 38 insertions, 0 deletions
diff --git a/xxx/vim-old/vim-potion/ftplugin/potion/folding.vim b/xxx/vim-old/vim-potion/ftplugin/potion/folding.vim
new file mode 100644
index 0000000..d4cb32b
--- /dev/null
+++ b/xxx/vim-old/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 = <SID>IndentLevel(a:lnum)
+ let next_indent = <SID>IndentLevel(<SID>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