summaryrefslogtreecommitdiffstats
path: root/indent
diff options
context:
space:
mode:
authorAdam Stankiewicz <sheerun@sher.pl>2021-07-08 11:54:15 +0200
committerAdam Stankiewicz <sheerun@sher.pl>2021-07-08 11:54:15 +0200
commitc794f186c0a618d2d4cdd5445d9ff20e6f640762 (patch)
tree11e6b01bac01b0ec694c8fa5c574870f5e268182 /indent
parent4f5388350be1052f610b830c8fce8fbc17370ec6 (diff)
downloadvim-polyglot-c794f186c0a618d2d4cdd5445d9ff20e6f640762.tar.gz
vim-polyglot-c794f186c0a618d2d4cdd5445d9ff20e6f640762.zip
Update
Diffstat (limited to 'indent')
-rw-r--r--indent/hcl.vim65
-rw-r--r--indent/pascal.vim4
-rw-r--r--indent/terraform.vim61
3 files changed, 63 insertions, 67 deletions
diff --git a/indent/hcl.vim b/indent/hcl.vim
index 346e8585..1338fec0 100644
--- a/indent/hcl.vim
+++ b/indent/hcl.vim
@@ -1,15 +1,68 @@
-if polyglot#init#is_disabled(expand('<sfile>:p'), 'hcl', 'indent/hcl.vim')
+if polyglot#init#is_disabled(expand('<sfile>:p'), 'terraform', 'indent/hcl.vim')
finish
endif
+" Only load this file if no other indent file was loaded
if exists('b:did_indent')
finish
endif
-
let b:did_indent = 1
-" cindent seems to work adequately with HCL's brace-y syntax
-setlocal cindent
+let s:cpo_save = &cpoptions
+set cpoptions&vim
+
+setlocal nolisp
+setlocal autoindent shiftwidth=2 tabstop=2 softtabstop=2 expandtab
+setlocal indentexpr=HclIndent(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('*HclIndent')
+ finish
+endif
+
+let s:cpo_save = &cpoptions
+set cpoptions&vim
+
+function! HclIndent(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
-" don't de-indent comments (cindent treats them like preprocessor directives)
-setlocal cinkeys-=0#
+let &cpoptions = s:cpo_save
+unlet s:cpo_save
diff --git a/indent/pascal.vim b/indent/pascal.vim
index 9e1c3e96..d4a6a5a7 100644
--- a/indent/pascal.vim
+++ b/indent/pascal.vim
@@ -6,7 +6,7 @@ endif
" Language: Pascal
" Maintainer: Neil Carter <n.carter@swansea.ac.uk>
" Created: 2004 Jul 13
-" Last Change: 2017 Jun 13
+" Last Change: 2021 Jul 01
"
" This is version 2.0, a complete rewrite.
"
@@ -24,6 +24,8 @@ setlocal indentkeys+==end;,==const,==type,==var,==begin,==repeat,==until,==for
setlocal indentkeys+==program,==function,==procedure,==object,==private
setlocal indentkeys+==record,==if,==else,==case
+let b:undo_indent = "setl indentkeys< indentexpr<"
+
if exists("*GetPascalIndent")
finish
endif
diff --git a/indent/terraform.vim b/indent/terraform.vim
index 32c194ef..3f7690f8 100644
--- a/indent/terraform.vim
+++ b/indent/terraform.vim
@@ -6,63 +6,4 @@ endif
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
+runtime! indent/hcl.vim