annotate runtime/indent/sh.vim @ 839:1f3b1021f002 v7.0e05

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