summaryrefslogtreecommitdiffstats
path: root/indent
diff options
context:
space:
mode:
authorAdam Stankiewicz <sheerun@sher.pl>2017-03-23 11:43:41 +0100
committerAdam Stankiewicz <sheerun@sher.pl>2017-03-23 11:43:41 +0100
commit461de4cc216cac858ccc4f2dd99644e6ea43589d (patch)
tree4ea2373904a594c143b029d279218f9650b6833c /indent
parentba758909360bbd037cea06fd4e4eec8da7bf8751 (diff)
downloadvim-polyglot-461de4cc216cac858ccc4f2dd99644e6ea43589d.tar.gz
vim-polyglot-461de4cc216cac858ccc4f2dd99644e6ea43589d.zip
Add caddyfile support, closes #195
Diffstat (limited to 'indent')
-rw-r--r--indent/caddyfile.vim46
1 files changed, 46 insertions, 0 deletions
diff --git a/indent/caddyfile.vim b/indent/caddyfile.vim
new file mode 100644
index 00000000..2f38c0db
--- /dev/null
+++ b/indent/caddyfile.vim
@@ -0,0 +1,46 @@
+if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'caddyfile') == -1
+
+if exists('b:did_indent')
+ finish
+endif
+let b:did_indent = 1
+
+setlocal nolisp
+setlocal autoindent
+setlocal indentexpr=GetCaddyfileIndent(v:lnum)
+setlocal indentkeys+=<:>,0=},0=)
+" setlocal cindent
+
+if exists('*shiftwidth')
+ func s:sw()
+ return shiftwidth()
+ endfunc
+else
+ func s:sw()
+ return &sw
+ endfunc
+endif
+
+function! GetCaddyfileIndent(lnum)
+ let prevlnum = prevnonblank(a:lnum-1)
+ if prevlnum == 0
+ return 0
+ endif
+
+ let thisl = substitute(getline(a:lnum), '#.*$', '', '')
+ let prevl = substitute(getline(prevlnum), '#.*$', '', '')
+
+ let ind = indent(prevlnum)
+
+ if prevl =~ '{\s*$'
+ let ind += s:sw()
+ endif
+
+ if thisl =~ '^\s*}\s*$'
+ let ind -= s:sw()
+ endif
+
+ return ind
+endfunction
+
+endif