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
|
26050
|
5 " Last Change: 2021-10-18
|
14668
|
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
|
26050
|
20 let b:undo_indent = "setl ai< inde< indk< si<"
|
|
21
|
14668
|
22 if exists("*GetDosBatchIndent")
|
|
23 finish
|
|
24 endif
|
|
25
|
|
26 let s:cpo_save = &cpo
|
|
27 set cpo&vim
|
|
28
|
|
29 function! GetDosBatchIndent(lnum)
|
|
30 let l:prevlnum = prevnonblank(a:lnum-1)
|
|
31 if l:prevlnum == 0
|
|
32 " top of file
|
|
33 return 0
|
|
34 endif
|
|
35
|
|
36 " grab the previous and current line, stripping comments.
|
|
37 let l:prevl = substitute(getline(l:prevlnum), '\c^\s*\%(@\s*\)\?rem\>.*$', '', '')
|
|
38 let l:thisl = getline(a:lnum)
|
|
39 let l:previ = indent(l:prevlnum)
|
|
40
|
|
41 let l:ind = l:previ
|
|
42
|
|
43 if l:prevl =~? '^\s*@\=if\>.*(\s*$' ||
|
|
44 \ l:prevl =~? '\<do\>\s*(\s*$' ||
|
|
45 \ l:prevl =~? '\<else\>\s*\%(if\>.*\)\?(\s*$' ||
|
|
46 \ l:prevl =~? '^.*\(&&\|||\)\s*(\s*$'
|
|
47 " previous line opened a block
|
|
48 let l:ind += shiftwidth()
|
|
49 endif
|
|
50 if l:thisl =~ '^\s*)'
|
|
51 " this line closed a block
|
|
52 let l:ind -= shiftwidth()
|
|
53 endif
|
|
54
|
|
55 return l:ind
|
|
56 endfunction
|
|
57
|
|
58 let &cpo = s:cpo_save
|
|
59 unlet s:cpo_save
|
|
60
|
|
61 " vim: ts=8 sw=2 sts=2
|