blob: d0358e3d858e5f1c04312f4019001934aaa0037b (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
let files = filter(globpath(&rtp, 'indent/terraform.vim', 1, 1), { _, v -> v !~ "vim-polyglot" && v !~ $VIMRUNTIME && v !~ "after" })
if len(files) > 0
exec 'source ' . files[0]
finish
endif
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
let s:cpo_save = &cpoptions
set cpoptions&vim
setlocal nolisp
setlocal autoindent shiftwidth=2 tabstop=2 softtabstop=2 expandtab
setlocal indentexpr=TerraformIndent(v:lnum)
setlocal indentkeys+=<:>,0=},0=)
let b:undo_indent = 'setlocal lisp< autoindent< shiftwidth< tabstop< softtabstop<'
\ . ' expandtab< indentexpr< indentkeys<'
let &cpoptions = s:cpo_save
unlet s:cpo_save
if exists('*TerraformIndent')
finish
endif
let s:cpo_save = &cpoptions
set cpoptions&vim
function! TerraformIndent(lnum)
" Beginning of the file should have no indent
if a:lnum == 0
return 0
endif
" Usual case is to continue at the same indent as the previous non-blank line.
let prevlnum = prevnonblank(a:lnum-1)
let thisindent = indent(prevlnum)
" If that previous line is a non-comment ending in [ { (, increase the
" indent level.
let prevline = getline(prevlnum)
if prevline !~# '^\s*\(#\|//\)' && prevline =~# '[\[{\(]\s*$'
let thisindent += &shiftwidth
endif
" If the current line ends a block, decrease the indent level.
let thisline = getline(a:lnum)
if thisline =~# '^\s*[\)}\]]'
let thisindent -= &shiftwidth
endif
" If the previous line starts a block comment /*, increase by one
if prevline =~# '/\*'
let thisindent += 1
endif
" If the previous line ends a block comment */, decrease by one
if prevline =~# '\*/'
let thisindent -= 1
endif
return thisindent
endfunction
let &cpoptions = s:cpo_save
unlet s:cpo_save
endif
|