diff options
author | Adam Stankiewicz <sheerun@sher.pl> | 2017-02-02 21:44:42 +0100 |
---|---|---|
committer | Adam Stankiewicz <sheerun@sher.pl> | 2017-02-02 21:44:42 +0100 |
commit | 39036a553f353ffb70ec4ad25c0789567fb3518d (patch) | |
tree | 9993c4d2ce0fddc3b014e39f18014d6af54a93bb /indent | |
parent | e685e4b431ab017d1aec9f9668fbeeeb6e7113e6 (diff) | |
download | vim-polyglot-39036a553f353ffb70ec4ad25c0789567fb3518d.tar.gz vim-polyglot-39036a553f353ffb70ec4ad25c0789567fb3518d.zip |
Add terraform, closes #163
Diffstat (limited to '')
-rw-r--r-- | indent/terraform.vim | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/indent/terraform.vim b/indent/terraform.vim new file mode 100644 index 00000000..30c78229 --- /dev/null +++ b/indent/terraform.vim @@ -0,0 +1,48 @@ +if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'terraform') == -1 + +if exists("b:did_indent") + finish +endif + +let b:did_indent = 1 + +setlocal nolisp +setlocal autoindent +setlocal indentexpr=TerraformIndent(v:lnum) +setlocal indentkeys+=<:>,0=},0=) + +if exists("*TerraformIndent") + finish +endif + +function! TerraformIndent(lnum) + " previous non-blank line + let prevlnum = prevnonblank(a:lnum-1) + + " beginning of file? + if prevlnum == 0 + return 0 + endif + + " previous line without comments + let prevline = substitute(getline(prevlnum), '//.*$', '', '') + let previndent = indent(prevlnum) + let thisindent = previndent + + " block open? + if prevline =~ '[\[{]\s*$' + let thisindent += &sw + endif + + " current line without comments + let thisline = substitute(getline(a:lnum), '//.*$', '', '') + + " block close? + if thisline =~ '^\s*[\]}]' + let thisindent -= &sw + endif + + return thisindent +endfunction + +endif |