annotate runtime/indent/dosbatch.vim @ 17505:a76219d230b3

Added tag v8.1.1750 for changeset 5d63aa71efe1fb7c930487a2297c4724f96c8ff6
author Bram Moolenaar <Bram@vim.org>
date Fri, 26 Jul 2019 20:00:08 +0200
parents 34fd018452ed
children ebedba7a4898
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14668
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 " Vim indent file
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2 " Language: MSDOS batch file (with NT command extensions)
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3 " Maintainer: Ken Takata
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4 " URL: https://github.com/k-takata/vim-dosbatch-indent
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5 " Last Change: 2017 May 10
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6 " Filenames: *.bat
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7 " License: VIM License
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9 if exists("b:did_indent")
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10 finish
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11 endif
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 let b:did_indent = 1
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14 setlocal nosmartindent
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15 setlocal noautoindent
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
16 setlocal indentexpr=GetDosBatchIndent(v:lnum)
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17 setlocal indentkeys=!^F,o,O
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
18 setlocal indentkeys+=0=)
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
20 if exists("*GetDosBatchIndent")
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
21 finish
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
22 endif
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
24 let s:cpo_save = &cpo
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
25 set cpo&vim
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
26
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
27 function! GetDosBatchIndent(lnum)
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
28 let l:prevlnum = prevnonblank(a:lnum-1)
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
29 if l:prevlnum == 0
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
30 " top of file
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31 return 0
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
32 endif
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
33
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
34 " grab the previous and current line, stripping comments.
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
35 let l:prevl = substitute(getline(l:prevlnum), '\c^\s*\%(@\s*\)\?rem\>.*$', '', '')
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
36 let l:thisl = getline(a:lnum)
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
37 let l:previ = indent(l:prevlnum)
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
38
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
39 let l:ind = l:previ
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
40
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
41 if l:prevl =~? '^\s*@\=if\>.*(\s*$' ||
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
42 \ l:prevl =~? '\<do\>\s*(\s*$' ||
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
43 \ l:prevl =~? '\<else\>\s*\%(if\>.*\)\?(\s*$' ||
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
44 \ l:prevl =~? '^.*\(&&\|||\)\s*(\s*$'
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
45 " previous line opened a block
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
46 let l:ind += shiftwidth()
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
47 endif
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
48 if l:thisl =~ '^\s*)'
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
49 " this line closed a block
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
50 let l:ind -= shiftwidth()
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
51 endif
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
52
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
53 return l:ind
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
54 endfunction
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
55
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
56 let &cpo = s:cpo_save
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
57 unlet s:cpo_save
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
58
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
59 " vim: ts=8 sw=2 sts=2