summaryrefslogtreecommitdiffstats
path: root/ftplugin
diff options
context:
space:
mode:
authorAdam Stankiewicz <sheerun@sher.pl>2016-05-02 10:44:59 +0200
committerAdam Stankiewicz <sheerun@sher.pl>2016-05-02 10:44:59 +0200
commit76d23a21e6904b1c09ddad1cb3fa769bbfe17991 (patch)
tree59a3472dd1f6ca1782261d66b971485f4b2995a4 /ftplugin
parent5dd1a7e83966c92d220073185f1738dfe441f59e (diff)
downloadvim-polyglot-76d23a21e6904b1c09ddad1cb3fa769bbfe17991.tar.gz
vim-polyglot-76d23a21e6904b1c09ddad1cb3fa769bbfe17991.zip
Add cryptol syntax, closes #107
Diffstat (limited to 'ftplugin')
-rw-r--r--ftplugin/cryptol/folding.vim50
1 files changed, 50 insertions, 0 deletions
diff --git a/ftplugin/cryptol/folding.vim b/ftplugin/cryptol/folding.vim
new file mode 100644
index 00000000..2b8ee5a3
--- /dev/null
+++ b/ftplugin/cryptol/folding.vim
@@ -0,0 +1,50 @@
+if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'cryptol') == -1
+
+" Copyright © 2013 Edward O'Callaghan. All Rights Reserved.
+
+"setlocal foldmethod=indent
+"setlocal foldignore=
+
+setlocal foldmethod=expr
+setlocal foldexpr=GetPotionFold(v:lnum)
+
+" Helper function: To tackle non-blank lines,
+" wish to know their indentation level
+function! IndentLevel(lnum)
+ return indent(a:lnum) / &shiftwidth
+endfunction
+
+" Helper function: .
+function! 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! 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
+
+endif