xref: /vim-8.2.3635/runtime/indent/dosbatch.vim (revision 577fadfc)
1" Vim indent file
2" Language:	MSDOS batch file (with NT command extensions)
3" Maintainer:	Ken Takata
4" URL:		https://github.com/k-takata/vim-dosbatch-indent
5" Last Change:	2017 May 10
6" Filenames:	*.bat
7" License:	VIM License
8
9if exists("b:did_indent")
10  finish
11endif
12let b:did_indent = 1
13
14setlocal nosmartindent
15setlocal noautoindent
16setlocal indentexpr=GetDosBatchIndent(v:lnum)
17setlocal indentkeys=!^F,o,O
18setlocal indentkeys+=0=)
19
20if exists("*GetDosBatchIndent")
21  finish
22endif
23
24let s:cpo_save = &cpo
25set cpo&vim
26
27function! GetDosBatchIndent(lnum)
28  let l:prevlnum = prevnonblank(a:lnum-1)
29  if l:prevlnum == 0
30    " top of file
31    return 0
32  endif
33
34  " grab the previous and current line, stripping comments.
35  let l:prevl = substitute(getline(l:prevlnum), '\c^\s*\%(@\s*\)\?rem\>.*$', '', '')
36  let l:thisl = getline(a:lnum)
37  let l:previ = indent(l:prevlnum)
38
39  let l:ind = l:previ
40
41  if l:prevl =~? '^\s*@\=if\>.*(\s*$' ||
42        \ l:prevl =~? '\<do\>\s*(\s*$' ||
43        \ l:prevl =~? '\<else\>\s*\%(if\>.*\)\?(\s*$' ||
44        \ l:prevl =~? '^.*\(&&\|||\)\s*(\s*$'
45    " previous line opened a block
46    let l:ind += shiftwidth()
47  endif
48  if l:thisl =~ '^\s*)'
49    " this line closed a block
50    let l:ind -= shiftwidth()
51  endif
52
53  return l:ind
54endfunction
55
56let &cpo = s:cpo_save
57unlet s:cpo_save
58
59" vim: ts=8 sw=2 sts=2
60