diff options
author | Adam Stankiewicz <sheerun@sher.pl> | 2017-12-06 12:56:27 +0100 |
---|---|---|
committer | Adam Stankiewicz <sheerun@sher.pl> | 2017-12-06 12:56:27 +0100 |
commit | dce9e8dec5ef51730291c7bbff3e3997433eabbd (patch) | |
tree | 1ca7140cd4244dfdff3d8d58f936d9dc159c9d4e /indent/terraform.vim | |
parent | 30c87b73deff05c7dd9590228c0615a3299f39ff (diff) | |
download | vim-polyglot-dce9e8dec5ef51730291c7bbff3e3997433eabbd.tar.gz vim-polyglot-dce9e8dec5ef51730291c7bbff3e3997433eabbd.zip |
Update
Diffstat (limited to '')
-rw-r--r-- | indent/terraform.vim | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/indent/terraform.vim b/indent/terraform.vim index 5a29dfb4..9a081ff8 100644 --- a/indent/terraform.vim +++ b/indent/terraform.vim @@ -1,13 +1,13 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'terraform') == -1 +" Only load this file if no other indent file was loaded if exists("b:did_indent") finish endif - let b:did_indent = 1 setlocal nolisp -setlocal autoindent +setlocal autoindent sw=2 ts=2 setlocal indentexpr=TerraformIndent(v:lnum) setlocal indentkeys+=<:>,0=},0=) @@ -16,29 +16,30 @@ if exists("*TerraformIndent") endif function! TerraformIndent(lnum) - " previous non-blank line - let prevlnum = prevnonblank(a:lnum-1) - - " beginning of file? - if prevlnum == 0 + " Beginning of the file should have no indent + if a:lnum == 0 return 0 endif - " previous line without comments + " Previous non-blank line should continue the indent level + let prevlnum = prevnonblank(a:lnum-1) + + " Previous line without comments should continue the indent level let prevline = substitute(getline(prevlnum), '//.*$', '', '') let previndent = indent(prevlnum) let thisindent = previndent - " block open? + " Config block starting with [ { ( should increase the indent level if prevline =~ '[\[{\(]\s*$' let thisindent += &sw endif - " current line without comments + " Current line without comments should continue the indent level let thisline = substitute(getline(a:lnum), '//.*$', '', '') - " block close? - if thisline =~ '^\s*[\)\]}]' + " Config block ending with ) } ] should get the indentation + " level from the initial config block + if thisline =~ '^\s*[\)}\]]' let thisindent -= &sw endif |