14668
|
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
|
|
9 if exists("b:did_indent")
|
|
10 finish
|
|
11 endif
|
|
12 let b:did_indent = 1
|
|
13
|
|
14 setlocal nosmartindent
|
|
15 setlocal noautoindent
|
|
16 setlocal indentexpr=GetDosBatchIndent(v:lnum)
|
|
17 setlocal indentkeys=!^F,o,O
|
|
18 setlocal indentkeys+=0=)
|
|
19
|
|
20 if exists("*GetDosBatchIndent")
|
|
21 finish
|
|
22 endif
|
|
23
|
|
24 let s:cpo_save = &cpo
|
|
25 set cpo&vim
|
|
26
|
|
27 function! 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
|
|
54 endfunction
|
|
55
|
|
56 let &cpo = s:cpo_save
|
|
57 unlet s:cpo_save
|
|
58
|
|
59 " vim: ts=8 sw=2 sts=2
|