summaryrefslogtreecommitdiffstats
path: root/indent
diff options
context:
space:
mode:
Diffstat (limited to 'indent')
-rw-r--r--indent/bicep.vim68
-rw-r--r--indent/rst.vim2
-rw-r--r--indent/ruby.vim4
3 files changed, 73 insertions, 1 deletions
diff --git a/indent/bicep.vim b/indent/bicep.vim
new file mode 100644
index 00000000..08c8cd6b
--- /dev/null
+++ b/indent/bicep.vim
@@ -0,0 +1,68 @@
+if polyglot#init#is_disabled(expand('<sfile>:p'), 'bicep', 'indent/bicep.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
+
+let s:cpo_save = &cpoptions
+set cpoptions&vim
+
+setlocal nolisp
+setlocal autoindent shiftwidth=2 tabstop=2 softtabstop=2 expandtab
+setlocal indentexpr=BicepIndent(v:lnum)
+setlocal indentkeys+=<:>,0=},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('*BicepIndent')
+ finish
+endif
+
+let s:cpo_save = &cpoptions
+set cpoptions&vim
+
+function! BicepIndent(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 += 2
+ endif
+
+ " If the this line ends a block comment */, decrease by one
+ if thisline =~# '\*/'
+ let thisindent -= 2
+ endif
+
+ return thisindent
+endfunction
+
+let &cpoptions = s:cpo_save
+unlet s:cpo_save
diff --git a/indent/rst.vim b/indent/rst.vim
index f27c5ecb..66920d83 100644
--- a/indent/rst.vim
+++ b/indent/rst.vim
@@ -18,6 +18,8 @@ setlocal indentexpr=GetRSTIndent()
setlocal indentkeys=!^F,o,O
setlocal nosmartindent
+let b:undo_indent = "setlocal indentexpr< indentkeys< smartindent<"
+
if exists("*GetRSTIndent")
finish
endif
diff --git a/indent/ruby.vim b/indent/ruby.vim
index 0a7cfae6..e08a38cf 100644
--- a/indent/ruby.vim
+++ b/indent/ruby.vim
@@ -43,9 +43,11 @@ setlocal nosmartindent
" Now, set up our indentation expression and keys that trigger it.
setlocal indentexpr=GetRubyIndent(v:lnum)
setlocal indentkeys=0{,0},0),0],!^F,o,O,e,:,.
-setlocal indentkeys+==end,=else,=elsif,=when,=in,=ensure,=rescue,==begin,==end
+setlocal indentkeys+==end,=else,=elsif,=when,=in\ ,=ensure,=rescue,==begin,==end
setlocal indentkeys+==private,=protected,=public
+let b:undo_indent = "setlocal indentexpr< indentkeys< smartindent<"
+
" Only define the function once.
if exists("*GetRubyIndent")
finish