annotate runtime/indent/sh.vim @ 20432:05b26264315a

Added tag v8.2.0770 for changeset 682513df5af1c71205a993c1554da8ef496220f7
author Bram Moolenaar <Bram@vim.org>
date Sat, 16 May 2020 19:00:08 +0200
parents 6d11fc4aa683
children f0d7cb510ce3
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
7013
349e6c01f35d Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 6918
diff changeset
2 " Language: Shell Script
349e6c01f35d Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 6918
diff changeset
3 " Maintainer: Christian Brabandt <cb@256bit.org>
13937
cd513458728c Updated runtime files
Christian Brabandt <cb@256bit.org>
parents: 13912
diff changeset
4 " Original Author: Nikolai Weibull <now@bitwi.se>
6918
2def7b25de60 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 6153
diff changeset
5 " Previous Maintainer: Peter Aronoff <telemachus@arpinum.org>
18456
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 17571
diff changeset
6 " Latest Revision: 2019-10-24
7013
349e6c01f35d Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 6918
diff changeset
7 " License: Vim (see :h license)
349e6c01f35d Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 6918
diff changeset
8 " Repository: https://github.com/chrisbra/vim-sh-indent
9407
619a98a67f67 commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents: 8246
diff changeset
9 " Changelog:
17571
2704c4e3e20a Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
10 " 20190726 - Correctly skip if keywords in syntax comments
2704c4e3e20a Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
11 " (issue #17)
2704c4e3e20a Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
12 " 20190603 - Do not indent in zsh filetypes with an `if` in comments
16610
1eaf34420bb3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16267
diff changeset
13 " 20190428 - De-indent fi correctly when typing with
1eaf34420bb3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16267
diff changeset
14 " https://github.com/chrisbra/vim-sh-indent/issues/15
16267
b471858040bc Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16208
diff changeset
15 " 20190325 - Indent fi; correctly
b471858040bc Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16208
diff changeset
16 " https://github.com/chrisbra/vim-sh-indent/issues/14
b471858040bc Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16208
diff changeset
17 " 20190319 - Indent arrays (only zsh and bash)
b471858040bc Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16208
diff changeset
18 " https://github.com/chrisbra/vim-sh-indent/issues/13
b471858040bc Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16208
diff changeset
19 " 20190316 - Make use of searchpairpos for nested if sections
b471858040bc Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16208
diff changeset
20 " fixes https://github.com/chrisbra/vim-sh-indent/issues/11
b471858040bc Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16208
diff changeset
21 " 20190201 - Better check for closing if sections
14421
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 13937
diff changeset
22 " 20180724 - make check for zsh syntax more rigid (needs word-boundaries)
13937
cd513458728c Updated runtime files
Christian Brabandt <cb@256bit.org>
parents: 13912
diff changeset
23 " 20180326 - better support for line continuation
cd513458728c Updated runtime files
Christian Brabandt <cb@256bit.org>
parents: 13912
diff changeset
24 " 20180325 - better detection of function definitions
cd513458728c Updated runtime files
Christian Brabandt <cb@256bit.org>
parents: 13912
diff changeset
25 " 20180127 - better support for zsh complex commands
12045
444ad56c0cac Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11442
diff changeset
26 " 20170808: - better indent of line continuation
11442
d183d629509e Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9407
diff changeset
27 " 20170502: - get rid of buffer-shiftwidth function
d183d629509e Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9407
diff changeset
28 " 20160912: - preserve indentation of here-doc blocks
9407
619a98a67f67 commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents: 8246
diff changeset
29 " 20160627: - detect heredocs correctly
619a98a67f67 commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents: 8246
diff changeset
30 " 20160213: - detect function definition correctly
619a98a67f67 commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents: 8246
diff changeset
31 " 20160202: - use shiftwidth() function
619a98a67f67 commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents: 8246
diff changeset
32 " 20151215: - set b:undo_indent variable
619a98a67f67 commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents: 8246
diff changeset
33 " 20150728: - add foreach detection for zsh
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 if exists("b:did_indent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 let b:did_indent = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 setlocal indentexpr=GetShIndent()
7013
349e6c01f35d Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 6918
diff changeset
41 setlocal indentkeys+=0=then,0=do,0=else,0=elif,0=fi,0=esac,0=done,0=end,),0=;;,0=;&
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
42 setlocal indentkeys+=0=fin,0=fil,0=fip,0=fir,0=fix
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 setlocal indentkeys-=:,0#
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
44 setlocal nosmartindent
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45
8246
f16bfe02cef1 commit https://github.com/vim/vim/commit/f391327adbbffb11180cf6038a92af1ed144e907
Christian Brabandt <cb@256bit.org>
parents: 7924
diff changeset
46 let b:undo_indent = 'setlocal indentexpr< indentkeys< smartindent<'
f16bfe02cef1 commit https://github.com/vim/vim/commit/f391327adbbffb11180cf6038a92af1ed144e907
Christian Brabandt <cb@256bit.org>
parents: 7924
diff changeset
47
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 if exists("*GetShIndent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
52 let s:cpo_save = &cpo
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
53 set cpo&vim
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
55 let s:sh_indent_defaults = {
11442
d183d629509e Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9407
diff changeset
56 \ 'default': function('shiftwidth'),
d183d629509e Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9407
diff changeset
57 \ 'continuation-line': function('shiftwidth'),
d183d629509e Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9407
diff changeset
58 \ 'case-labels': function('shiftwidth'),
d183d629509e Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9407
diff changeset
59 \ 'case-statements': function('shiftwidth'),
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
60 \ 'case-breaks': 0 }
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
61
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
62 function! s:indent_value(option)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
63 let Value = exists('b:sh_indent_options')
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
64 \ && has_key(b:sh_indent_options, a:option) ?
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
65 \ b:sh_indent_options[a:option] :
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
66 \ s:sh_indent_defaults[a:option]
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
67 if type(Value) == type(function('type'))
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
68 return Value()
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
69 endif
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
70 return Value
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
71 endfunction
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
72
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
73 function! GetShIndent()
16267
b471858040bc Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16208
diff changeset
74 let curline = getline(v:lnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75 let lnum = prevnonblank(v:lnum - 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76 if lnum == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 return 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78 endif
13912
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
79 let line = getline(lnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
81 let pnum = prevnonblank(lnum - 1)
13912
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
82 let pline = getline(pnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83 let ind = indent(lnum)
13912
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
84
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
85 " Check contents of previous lines
17571
2704c4e3e20a Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
86 " should not apply to e.g. commented lines
13912
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
87 if line =~ '^\s*\%(if\|then\|do\|else\|elif\|case\|while\|until\|for\|select\|foreach\)\>' ||
17571
2704c4e3e20a Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
88 \ (&ft is# 'zsh' && line =~ '^\s*\<\%(if\|then\|do\|else\|elif\|case\|while\|until\|for\|select\|foreach\)\>')
16267
b471858040bc Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16208
diff changeset
89 if !s:is_end_expression(line)
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
90 let ind += s:indent_value('default')
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
91 endif
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
92 elseif s:is_case_label(line, pnum)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
93 if !s:is_case_ended(line)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
94 let ind += s:indent_value('case-statements')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
95 endif
13912
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
96 " function definition
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
97 elseif s:is_function_definition(line)
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
98 if line !~ '}\s*\%(#.*\)\=$'
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
99 let ind += s:indent_value('default')
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
100 endif
16267
b471858040bc Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16208
diff changeset
101 " array (only works for zsh or bash)
b471858040bc Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16208
diff changeset
102 elseif s:is_array(line) && line !~ ')\s*$' && (&ft is# 'zsh' || s:is_bash())
b471858040bc Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16208
diff changeset
103 let ind += s:indent_value('continuation-line')
b471858040bc Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16208
diff changeset
104 " end of array
b471858040bc Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16208
diff changeset
105 elseif curline =~ '^\s*)$'
b471858040bc Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16208
diff changeset
106 let ind -= s:indent_value('continuation-line')
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
107 elseif s:is_continuation_line(line)
13912
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
108 if pnum == 0 || !s:is_continuation_line(pline)
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
109 let ind += s:indent_value('continuation-line')
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
110 endif
13912
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
111 elseif s:end_block(line) && !s:start_block(line)
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
112 let ind -= s:indent_value('default')
16267
b471858040bc Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16208
diff changeset
113 elseif pnum != 0 &&
b471858040bc Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16208
diff changeset
114 \ s:is_continuation_line(pline) &&
b471858040bc Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16208
diff changeset
115 \ !s:end_block(curline) &&
b471858040bc Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16208
diff changeset
116 \ !s:is_end_expression(curline)
13912
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
117 " only add indent, if line and pline is in the same block
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
118 let i = v:lnum
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
119 let ind2 = indent(s:find_continued_lnum(pnum))
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
120 while !s:is_empty(getline(i)) && i > pnum
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
121 let i -= 1
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
122 endw
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
123 if i == pnum
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
124 let ind += ind2
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
125 else
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
126 let ind = ind2
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
127 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
128 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
129
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
130 let pine = line
13912
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
131 " Check content of current line
16267
b471858040bc Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16208
diff changeset
132 let line = curline
b471858040bc Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16208
diff changeset
133 " Current line is a endif line, so get indent from start of "if condition" line
b471858040bc Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16208
diff changeset
134 " TODO: should we do the same for other "end" lines?
b471858040bc Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16208
diff changeset
135 if curline =~ '^\s*\%(fi\);\?\s*\%(#.*\)\=$'
17571
2704c4e3e20a Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
136 let ind = indent(v:lnum)
18456
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 17571
diff changeset
137 let previous_line = searchpair('\<if\>', '', '\<fi\>\zs', 'bnW', 'synIDattr(synID(line("."),col("."), 1),"name") =~? "comment\\|quote"')
16267
b471858040bc Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16208
diff changeset
138 if previous_line > 0
b471858040bc Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16208
diff changeset
139 let ind = indent(previous_line)
b471858040bc Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16208
diff changeset
140 endif
b471858040bc Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16208
diff changeset
141 elseif line =~ '^\s*\%(then\|do\|else\|elif\|done\|end\)\>' || s:end_block(line)
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
142 let ind -= s:indent_value('default')
5555
7818ca6de3d0 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2034
diff changeset
143 elseif line =~ '^\s*esac\>' && s:is_case_empty(getline(v:lnum - 1))
7818ca6de3d0 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2034
diff changeset
144 let ind -= s:indent_value('default')
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
145 elseif line =~ '^\s*esac\>'
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
146 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
147 \ 0 : s:indent_value('case-statements')) +
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
148 \ s:indent_value('case-labels')
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
149 if s:is_case_break(pine)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
150 let ind += s:indent_value('case-breaks')
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
151 endif
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
152 elseif s:is_case_label(line, lnum)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
153 if s:is_case(pine)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
154 let ind = indent(lnum) + s:indent_value('case-labels')
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
155 else
6153
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5555
diff changeset
156 let ind -= (s:is_case_label(pine, lnum) && s:is_case_ended(pine) ?
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5555
diff changeset
157 \ 0 : s:indent_value('case-statements')) -
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5555
diff changeset
158 \ s:indent_value('case-breaks')
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
159 endif
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
160 elseif s:is_case_break(line)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
161 let ind -= s:indent_value('case-breaks')
9407
619a98a67f67 commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents: 8246
diff changeset
162 elseif s:is_here_doc(line)
619a98a67f67 commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents: 8246
diff changeset
163 let ind = 0
11442
d183d629509e Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9407
diff changeset
164 " statements, executed within a here document. Keep the current indent
d183d629509e Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9407
diff changeset
165 elseif match(map(synstack(v:lnum, 1), 'synIDattr(v:val, "name")'), '\c\mheredoc') > -1
d183d629509e Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9407
diff changeset
166 return indent(v:lnum)
13912
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
167 elseif s:is_comment(line) && s:is_empty(getline(v:lnum-1))
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
168 return indent(v:lnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
169 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
170
13912
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
171 return ind > 0 ? ind : 0
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
172 endfunction
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
173
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
174 function! s:is_continuation_line(line)
13912
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
175 " Comment, cannot be a line continuation
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
176 if a:line =~ '^\s*#'
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
177 return 0
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
178 else
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
179 " start-of-line
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
180 " \\ or && or || or |
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
181 " followed optionally by { or #
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
182 return a:line =~ '\%(\%(^\|[^\\]\)\\\|&&\|||\||\)' .
12045
444ad56c0cac Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11442
diff changeset
183 \ '\s*\({\s*\)\=\(#.*\)\=$'
13912
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
184 endif
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
185 endfunction
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
186
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
187 function! s:find_continued_lnum(lnum)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
188 let i = a:lnum
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
189 while i > 1 && s:is_continuation_line(getline(i - 1))
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
190 let i -= 1
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
191 endwhile
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
192 return i
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
193 endfunction
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
194
13912
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
195 function! s:is_function_definition(line)
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
196 return a:line =~ '^\s*\<\k\+\>\s*()\s*{' ||
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
197 \ a:line =~ '^\s*{' ||
18456
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 17571
diff changeset
198 \ a:line =~ '^\s*function\s*\k\+\s*\%(()\)\?\s*{'
13912
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
199 endfunction
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
200
16267
b471858040bc Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16208
diff changeset
201 function! s:is_array(line)
b471858040bc Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16208
diff changeset
202 return a:line =~ '^\s*\<\k\+\>=('
b471858040bc Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16208
diff changeset
203 endfunction
b471858040bc Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16208
diff changeset
204
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
205 function! s:is_case_label(line, pnum)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
206 if a:line !~ '^\s*(\=.*)'
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
207 return 0
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
208 endif
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
209
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
210 if a:pnum > 0
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
211 let pine = getline(a:pnum)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
212 if !(s:is_case(pine) || s:is_case_ended(pine))
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
213 return 0
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
214 endif
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
215 endif
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
216
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
217 let suffix = substitute(a:line, '^\s*(\=', "", "")
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
218 let nesting = 0
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
219 let i = 0
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
220 let n = strlen(suffix)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
221 while i < n
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
222 let c = suffix[i]
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
223 let i += 1
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
224 if c == '\\'
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
225 let i += 1
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
226 elseif c == '('
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
227 let nesting += 1
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
228 elseif c == ')'
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
229 if nesting == 0
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
230 return 1
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
231 endif
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
232 let nesting -= 1
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
233 endif
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
234 endwhile
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
235 return 0
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
236 endfunction
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
237
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
238 function! s:is_case(line)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
239 return a:line =~ '^\s*case\>'
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
240 endfunction
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
241
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
242 function! s:is_case_break(line)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
243 return a:line =~ '^\s*;[;&]'
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
244 endfunction
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
245
9407
619a98a67f67 commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents: 8246
diff changeset
246 function! s:is_here_doc(line)
619a98a67f67 commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents: 8246
diff changeset
247 if a:line =~ '^\w\+$'
16267
b471858040bc Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16208
diff changeset
248 let here_pat = '<<-\?'. s:escape(a:line). '\$'
b471858040bc Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16208
diff changeset
249 return search(here_pat, 'bnW') > 0
9407
619a98a67f67 commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents: 8246
diff changeset
250 endif
619a98a67f67 commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents: 8246
diff changeset
251 return 0
619a98a67f67 commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents: 8246
diff changeset
252 endfunction
619a98a67f67 commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents: 8246
diff changeset
253
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
254 function! s:is_case_ended(line)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
255 return s:is_case_break(a:line) || a:line =~ ';[;&]\s*\%(#.*\)\=$'
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
256 endfunction
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
257
5555
7818ca6de3d0 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2034
diff changeset
258 function! s:is_case_empty(line)
7818ca6de3d0 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2034
diff changeset
259 if a:line =~ '^\s*$' || a:line =~ '^\s*#'
7818ca6de3d0 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2034
diff changeset
260 return s:is_case_empty(getline(v:lnum - 1))
7818ca6de3d0 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2034
diff changeset
261 else
7818ca6de3d0 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2034
diff changeset
262 return a:line =~ '^\s*case\>'
7818ca6de3d0 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2034
diff changeset
263 endif
7818ca6de3d0 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2034
diff changeset
264 endfunction
7818ca6de3d0 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2034
diff changeset
265
9407
619a98a67f67 commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents: 8246
diff changeset
266 function! s:escape(pattern)
619a98a67f67 commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents: 8246
diff changeset
267 return '\V'. escape(a:pattern, '\\')
619a98a67f67 commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents: 8246
diff changeset
268 endfunction
619a98a67f67 commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents: 8246
diff changeset
269
13912
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
270 function! s:is_empty(line)
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
271 return a:line =~ '^\s*$'
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
272 endfunction
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
273
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
274 function! s:end_block(line)
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
275 return a:line =~ '^\s*}'
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
276 endfunction
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
277
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
278 function! s:start_block(line)
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
279 return a:line =~ '{\s*\(#.*\)\?$'
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
280 endfunction
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
281
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
282 function! s:find_start_block(lnum)
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
283 let i = a:lnum
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
284 while i > 1 && !s:start_block(getline(i))
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
285 let i -= 1
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
286 endwhile
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
287 return i
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
288 endfunction
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
289
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
290 function! s:is_comment(line)
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
291 return a:line =~ '^\s*#'
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
292 endfunction
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
293
16267
b471858040bc Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16208
diff changeset
294 function! s:is_end_expression(line)
b471858040bc Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16208
diff changeset
295 return a:line =~ '\<\%(fi\|esac\|done\|end\)\>\s*\%(#.*\)\=$'
b471858040bc Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16208
diff changeset
296 endfunction
b471858040bc Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16208
diff changeset
297
b471858040bc Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16208
diff changeset
298 function! s:is_bash()
b471858040bc Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16208
diff changeset
299 return get(g:, 'is_bash', 0) || get(b:, 'is_bash', 0)
b471858040bc Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16208
diff changeset
300 endfunction
b471858040bc Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16208
diff changeset
301
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
302 let &cpo = s:cpo_save
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
303 unlet s:cpo_save