annotate runtime/indent/sh.vim @ 2111:aab202d244b6 v7.2.394

updated for version 7.2.394 Problem: .xz files are not supported. Solution: Recognize .xz files so that they can be edited.
author Bram Moolenaar <bram@zimbu.org>
date Wed, 10 Mar 2010 17:16:12 +0100
parents 7bc41231fbc7
children 7818ca6de3d0
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
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
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>
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
4 " Latest Revision: 2010-01-06
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()
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
12 setlocal indentkeys+=0=then,0=do,0=else,0=elif,0=fi,0=esac,0=done,),0=;;,0=;&
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
13 setlocal indentkeys+=0=fin,0=fil,0=fip,0=fir,0=fix
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 setlocal indentkeys-=:,0#
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
15 setlocal nosmartindent
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 if exists("*GetShIndent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
21 let s:cpo_save = &cpo
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
22 set cpo&vim
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
24 function s:buffer_shiftwidth()
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
25 return &shiftwidth
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
26 endfunction
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
27
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
28 let s:sh_indent_defaults = {
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
29 \ 'default': function('s:buffer_shiftwidth'),
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
30 \ 'continuation-line': function('s:buffer_shiftwidth'),
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
31 \ 'case-labels': function('s:buffer_shiftwidth'),
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
32 \ 'case-statements': function('s:buffer_shiftwidth'),
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
33 \ 'case-breaks': 0 }
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
34
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
35 function! s:indent_value(option)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
36 let Value = exists('b:sh_indent_options')
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
37 \ && has_key(b:sh_indent_options, a:option) ?
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
38 \ b:sh_indent_options[a:option] :
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
39 \ s:sh_indent_defaults[a:option]
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
40 if type(Value) == type(function('type'))
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
41 return Value()
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
42 endif
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
43 return Value
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
44 endfunction
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
45
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
46 function! GetShIndent()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 let lnum = prevnonblank(v:lnum - 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 if lnum == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49 return 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
52 let pnum = prevnonblank(lnum - 1)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
53
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 let ind = indent(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55 let line = getline(lnum)
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
56 if line =~ '^\s*\%(if\|then\|do\|else\|elif\|case\|while\|until\|for\|select\)\>'
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
57 if line !~ '\<\%(fi\|esac\|done\)\>\s*\%(#.*\)\=$'
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
58 let ind += s:indent_value('default')
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
59 endif
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
60 elseif s:is_case_label(line, pnum)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
61 if !s:is_case_ended(line)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
62 let ind += s:indent_value('case-statements')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 endif
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
64 elseif line =~ '^\s*\<\k\+\>\s*()\s*{' || line =~ '^\s*{'
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
65 if line !~ '}\s*\%(#.*\)\=$'
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
66 let ind += s:indent_value('default')
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
67 endif
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
68 elseif s:is_continuation_line(line)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
69 if pnum == 0 || !s:is_continuation_line(getline(pnum))
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
70 let ind += s:indent_value('continuation-line')
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
71 endif
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
72 elseif pnum != 0 && s:is_continuation_line(getline(pnum))
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
73 let ind = indent(s:find_continued_lnum(pnum))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
76 let pine = line
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 let line = getline(v:lnum)
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
78 if line =~ '^\s*\%(then\|do\|else\|elif\|fi\|done\)\>' || line =~ '^\s*}'
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
79 let ind -= s:indent_value('default')
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
80 elseif line =~ '^\s*esac\>'
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
81 let ind -= (s:is_case_label(pine, lnum) && s:is_case_ended(pine) ?
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
82 \ 0 : s:indent_value('case-statements')) +
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
83 \ s:indent_value('case-labels')
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
84 if s:is_case_break(pine)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
85 let ind += s:indent_value('case-breaks')
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
86 endif
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
87 elseif s:is_case_label(line, lnum)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
88 if s:is_case(pine)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
89 let ind = indent(lnum) + s:indent_value('case-labels')
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
90 else
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
91 let ind -= s:indent_value('case-statements') - s:indent_value('case-breaks')
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
92 endif
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
93 elseif s:is_case_break(line)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
94 let ind -= s:indent_value('case-breaks')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
95 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
96
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
97 return ind
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
98 endfunction
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
99
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
100 function! s:is_continuation_line(line)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
101 return a:line =~ '\%(\%(^\|[^\\]\)\\\|&&\|||\)$'
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
102 endfunction
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
103
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
104 function! s:find_continued_lnum(lnum)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
105 let i = a:lnum
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
106 while i > 1 && s:is_continuation_line(getline(i - 1))
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
107 let i -= 1
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
108 endwhile
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
109 return i
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
110 endfunction
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
111
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
112 function! s:is_case_label(line, pnum)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
113 if a:line !~ '^\s*(\=.*)'
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
114 return 0
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
115 endif
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
116
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
117 if a:pnum > 0
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
118 let pine = getline(a:pnum)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
119 if !(s:is_case(pine) || s:is_case_ended(pine))
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
120 return 0
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
121 endif
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
122 endif
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
123
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
124 let suffix = substitute(a:line, '^\s*(\=', "", "")
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
125 let nesting = 0
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
126 let i = 0
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
127 let n = strlen(suffix)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
128 while i < n
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
129 let c = suffix[i]
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
130 let i += 1
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
131 if c == '\\'
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
132 let i += 1
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
133 elseif c == '('
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
134 let nesting += 1
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
135 elseif c == ')'
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
136 if nesting == 0
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
137 return 1
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
138 endif
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
139 let nesting -= 1
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
140 endif
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
141 endwhile
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
142 return 0
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
143 endfunction
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
144
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
145 function! s:is_case(line)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
146 return a:line =~ '^\s*case\>'
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
147 endfunction
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
148
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
149 function! s:is_case_break(line)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
150 return a:line =~ '^\s*;[;&]'
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
151 endfunction
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
152
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
153 function! s:is_case_ended(line)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
154 return s:is_case_break(a:line) || a:line =~ ';[;&]\s*\%(#.*\)\=$'
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
155 endfunction
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
156
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
157 let &cpo = s:cpo_save
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
158 unlet s:cpo_save