annotate runtime/indent/dosbatch.vim @ 29236:0eef32b4ebbc

Update runtime files Commit: https://github.com/vim/vim/commit/d799daa660b8821943cbe1682f00da9e812dd48c Author: Bram Moolenaar <Bram@vim.org> Date: Mon Jun 20 11:17:32 2022 +0100 Update runtime files
author Bram Moolenaar <Bram@vim.org>
date Mon, 20 Jun 2022 12:30:06 +0200
parents ebedba7a4898
children
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
26050
ebedba7a4898 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14668
diff changeset
5 " Last Change: 2021-10-18
14668
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
26050
ebedba7a4898 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14668
diff changeset
20 let b:undo_indent = "setl ai< inde< indk< si<"
ebedba7a4898 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14668
diff changeset
21
14668
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
22 if exists("*GetDosBatchIndent")
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23 finish
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
24 endif
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
25
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
26 let s:cpo_save = &cpo
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
27 set cpo&vim
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
28
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
29 function! GetDosBatchIndent(lnum)
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
30 let l:prevlnum = prevnonblank(a:lnum-1)
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31 if l:prevlnum == 0
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
32 " top of file
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
33 return 0
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
34 endif
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
35
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
36 " grab the previous and current line, stripping comments.
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
37 let l:prevl = substitute(getline(l:prevlnum), '\c^\s*\%(@\s*\)\?rem\>.*$', '', '')
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
38 let l:thisl = getline(a:lnum)
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
39 let l:previ = indent(l:prevlnum)
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 let l:ind = l:previ
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
42
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
43 if l:prevl =~? '^\s*@\=if\>.*(\s*$' ||
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
44 \ l:prevl =~? '\<do\>\s*(\s*$' ||
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
45 \ l:prevl =~? '\<else\>\s*\%(if\>.*\)\?(\s*$' ||
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
46 \ l:prevl =~? '^.*\(&&\|||\)\s*(\s*$'
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
47 " previous line opened a block
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
48 let l:ind += shiftwidth()
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
49 endif
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
50 if l:thisl =~ '^\s*)'
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
51 " this line closed a block
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
52 let l:ind -= shiftwidth()
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
53 endif
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
54
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
55 return l:ind
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
56 endfunction
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
57
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
58 let &cpo = s:cpo_save
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
59 unlet s:cpo_save
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
60
34fd018452ed Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
61 " vim: ts=8 sw=2 sts=2