7
|
1 " Vim indent file
|
375
|
2 " Language: Shell Script
|
839
|
3 " Maintainer: Nikolai Weibull <now@bitwi.se>
|
|
4 " Latest Revision: 2006-04-19
|
7
|
5
|
|
6 if exists("b:did_indent")
|
|
7 finish
|
|
8 endif
|
|
9 let b:did_indent = 1
|
|
10
|
|
11 setlocal indentexpr=GetShIndent()
|
|
12 setlocal indentkeys+==then,=do,=else,=elif,=esac,=fi,=fin,=fil,=done
|
|
13 setlocal indentkeys-=:,0#
|
|
14
|
|
15 if exists("*GetShIndent")
|
|
16 finish
|
|
17 endif
|
|
18
|
375
|
19 let s:cpo_save = &cpo
|
|
20 set cpo&vim
|
7
|
21
|
|
22 function GetShIndent()
|
|
23 let lnum = prevnonblank(v:lnum - 1)
|
|
24 if lnum == 0
|
|
25 return 0
|
|
26 endif
|
|
27
|
|
28 " Add a 'shiftwidth' after if, while, else, case, until, for, function()
|
|
29 " Skip if the line also contains the closure for the above
|
|
30 let ind = indent(lnum)
|
|
31 let line = getline(lnum)
|
|
32 if line =~ '^\s*\(if\|then\|do\|else\|elif\|case\|while\|until\|for\)\>'
|
375
|
33 \ || line =~ '^\s*\<\k\+\>\s*()\s*{'
|
|
34 \ || line =~ '^\s*{'
|
7
|
35 if line !~ '\(esac\|fi\|done\)\>\s*$' && line !~ '}\s*$'
|
|
36 let ind = ind + &sw
|
|
37 endif
|
|
38 endif
|
|
39
|
|
40 " Subtract a 'shiftwidth' on a then, do, else, esac, fi, done
|
|
41 " Retain the indentation level if line matches fin (for find)
|
|
42 let line = getline(v:lnum)
|
|
43 if (line =~ '^\s*\(then\|do\|else\|elif\|esac\|fi\|done\)\>' || line =~ '^\s*}')
|
375
|
44 \ && line !~ '^\s*fi[ln]\>'
|
7
|
45 let ind = ind - &sw
|
|
46 endif
|
|
47
|
|
48 return ind
|
|
49 endfunction
|
|
50
|
375
|
51 let &cpo = s:cpo_save
|
|
52 unlet s:cpo_save
|