annotate runtime/indent/sh.vim @ 15446:8ac454818352 v8.1.0731

patch 8.1.0731: JS encoding does not handle negative infinity commit https://github.com/vim/vim/commit/5f6b379ff3e34297d171635933f907ec80ed4f05 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Jan 12 14:24:27 2019 +0100 patch 8.1.0731: JS encoding does not handle negative infinity Problem: JS encoding does not handle negative infinity. Solution: Add support for negative infinity for JS encoding. (Dominique Pelle, closes #3792)
author Bram Moolenaar <Bram@vim.org>
date Sat, 12 Jan 2019 14:30:06 +0100
parents 2f7e67dd088c
children fe57e4f0eac1
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>
13937
cd513458728c Updated runtime files
Christian Brabandt <cb@256bit.org>
parents: 13912
diff changeset
6 " Latest Revision: 2018-03-26
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:
14421
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 13937
diff changeset
10 " 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
11 " 20180326 - better support for line continuation
cd513458728c Updated runtime files
Christian Brabandt <cb@256bit.org>
parents: 13912
diff changeset
12 " 20180325 - better detection of function definitions
cd513458728c Updated runtime files
Christian Brabandt <cb@256bit.org>
parents: 13912
diff changeset
13 " 20180127 - better support for zsh complex commands
12045
444ad56c0cac Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11442
diff changeset
14 " 20170808: - better indent of line continuation
11442
d183d629509e Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9407
diff changeset
15 " 20170502: - get rid of buffer-shiftwidth function
d183d629509e Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9407
diff changeset
16 " 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
17 " 20160627: - detect heredocs correctly
619a98a67f67 commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents: 8246
diff changeset
18 " 20160213: - detect function definition correctly
619a98a67f67 commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents: 8246
diff changeset
19 " 20160202: - use shiftwidth() function
619a98a67f67 commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents: 8246
diff changeset
20 " 20151215: - set b:undo_indent variable
619a98a67f67 commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents: 8246
diff changeset
21 " 20150728: - add foreach detection for zsh
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 if exists("b:did_indent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 let b:did_indent = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 setlocal indentexpr=GetShIndent()
7013
349e6c01f35d Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 6918
diff changeset
29 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
30 setlocal indentkeys+=0=fin,0=fil,0=fip,0=fir,0=fix
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 setlocal indentkeys-=:,0#
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
32 setlocal nosmartindent
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33
8246
f16bfe02cef1 commit https://github.com/vim/vim/commit/f391327adbbffb11180cf6038a92af1ed144e907
Christian Brabandt <cb@256bit.org>
parents: 7924
diff changeset
34 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
35
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 if exists("*GetShIndent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
40 let s:cpo_save = &cpo
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
41 set cpo&vim
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
43 let s:sh_indent_defaults = {
11442
d183d629509e Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9407
diff changeset
44 \ 'default': function('shiftwidth'),
d183d629509e Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9407
diff changeset
45 \ 'continuation-line': function('shiftwidth'),
d183d629509e Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9407
diff changeset
46 \ 'case-labels': function('shiftwidth'),
d183d629509e Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9407
diff changeset
47 \ 'case-statements': function('shiftwidth'),
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
48 \ 'case-breaks': 0 }
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
49
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
50 function! s:indent_value(option)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
51 let Value = exists('b:sh_indent_options')
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
52 \ && has_key(b:sh_indent_options, a:option) ?
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
53 \ b:sh_indent_options[a:option] :
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
54 \ s:sh_indent_defaults[a:option]
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
55 if type(Value) == type(function('type'))
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
56 return Value()
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
57 endif
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
58 return Value
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
59 endfunction
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
60
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
61 function! GetShIndent()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 let lnum = prevnonblank(v:lnum - 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 if lnum == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64 return 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 endif
13912
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
66 let line = getline(lnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
68 let pnum = prevnonblank(lnum - 1)
13912
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
69 let pline = getline(pnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70 let ind = indent(lnum)
13912
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
71
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
72 " Check contents of previous lines
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
73 if line =~ '^\s*\%(if\|then\|do\|else\|elif\|case\|while\|until\|for\|select\|foreach\)\>' ||
14421
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 13937
diff changeset
74 \ (&ft is# 'zsh' && line =~ '\<\%(if\|then\|do\|else\|elif\|case\|while\|until\|for\|select\|foreach\)\>')
7013
349e6c01f35d Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 6918
diff changeset
75 if line !~ '\<\%(fi\|esac\|done\|end\)\>\s*\%(#.*\)\=$'
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
76 let ind += s:indent_value('default')
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
77 endif
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
78 elseif s:is_case_label(line, pnum)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
79 if !s:is_case_ended(line)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
80 let ind += s:indent_value('case-statements')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
81 endif
13912
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
82 " function definition
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
83 elseif s:is_function_definition(line)
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
84 if line !~ '}\s*\%(#.*\)\=$'
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
85 let ind += s:indent_value('default')
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_continuation_line(line)
13912
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
88 if pnum == 0 || !s:is_continuation_line(pline)
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
89 let ind += s:indent_value('continuation-line')
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
90 endif
13912
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
91 elseif s:end_block(line) && !s:start_block(line)
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
92 let ind -= s:indent_value('default')
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
93 elseif pnum != 0 && s:is_continuation_line(pline) && !s:end_block(getline(v:lnum))
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
94 " 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
95 let i = v:lnum
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
96 let ind2 = indent(s:find_continued_lnum(pnum))
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
97 while !s:is_empty(getline(i)) && i > pnum
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
98 let i -= 1
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
99 endw
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
100 if i == pnum
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
101 let ind += ind2
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
102 else
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
103 let ind = ind2
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
104 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
105 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
106
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
107 let pine = line
13912
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
108 " Check content of current line
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
109 let line = getline(v:lnum)
13912
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
110 if line =~ '^\s*\%(then\|do\|else\|elif\|fi\|done\|end\)\>' || s:end_block(line)
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
111 let ind -= s:indent_value('default')
5555
7818ca6de3d0 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2034
diff changeset
112 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
113 let ind -= s:indent_value('default')
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
114 elseif line =~ '^\s*esac\>'
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
115 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
116 \ 0 : s:indent_value('case-statements')) +
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
117 \ s:indent_value('case-labels')
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
118 if s:is_case_break(pine)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
119 let ind += s:indent_value('case-breaks')
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
120 endif
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
121 elseif s:is_case_label(line, lnum)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
122 if s:is_case(pine)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
123 let ind = indent(lnum) + s:indent_value('case-labels')
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
124 else
6153
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5555
diff changeset
125 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
126 \ 0 : s:indent_value('case-statements')) -
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5555
diff changeset
127 \ s:indent_value('case-breaks')
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
128 endif
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
129 elseif s:is_case_break(line)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
130 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
131 elseif s:is_here_doc(line)
619a98a67f67 commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents: 8246
diff changeset
132 let ind = 0
11442
d183d629509e Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9407
diff changeset
133 " statements, executed within a here document. Keep the current indent
d183d629509e Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9407
diff changeset
134 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
135 return indent(v:lnum)
13912
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
136 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
137 return indent(v:lnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
138 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
139
13912
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
140 return ind > 0 ? ind : 0
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
141 endfunction
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
142
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
143 function! s:is_continuation_line(line)
13912
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
144 " Comment, cannot be a line continuation
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
145 if a:line =~ '^\s*#'
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
146 return 0
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
147 else
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
148 " start-of-line
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
149 " \\ or && or || or |
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
150 " followed optionally by { or #
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
151 return a:line =~ '\%(\%(^\|[^\\]\)\\\|&&\|||\||\)' .
12045
444ad56c0cac Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11442
diff changeset
152 \ '\s*\({\s*\)\=\(#.*\)\=$'
13912
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
153 endif
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
154 endfunction
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
155
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
156 function! s:find_continued_lnum(lnum)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
157 let i = a:lnum
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
158 while i > 1 && s:is_continuation_line(getline(i - 1))
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
159 let i -= 1
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
160 endwhile
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
161 return i
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
162 endfunction
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
163
13912
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
164 function! s:is_function_definition(line)
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
165 return a:line =~ '^\s*\<\k\+\>\s*()\s*{' ||
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
166 \ a:line =~ '^\s*{' ||
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
167 \ a:line =~ '^\s*function\s*\w\S\+\s*\%(()\)\?\s*{'
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
168 endfunction
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
169
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
170 function! s:is_case_label(line, pnum)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
171 if a:line !~ '^\s*(\=.*)'
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
172 return 0
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
173 endif
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
174
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
175 if a:pnum > 0
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
176 let pine = getline(a:pnum)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
177 if !(s:is_case(pine) || s:is_case_ended(pine))
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
178 return 0
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
179 endif
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
180 endif
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
181
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
182 let suffix = substitute(a:line, '^\s*(\=', "", "")
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
183 let nesting = 0
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
184 let i = 0
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
185 let n = strlen(suffix)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
186 while i < n
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
187 let c = suffix[i]
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
188 let i += 1
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
189 if c == '\\'
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 elseif c == '('
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
192 let nesting += 1
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
193 elseif c == ')'
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
194 if nesting == 0
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
195 return 1
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
196 endif
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
197 let nesting -= 1
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
198 endif
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
199 endwhile
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
200 return 0
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
201 endfunction
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
202
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
203 function! s:is_case(line)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
204 return a:line =~ '^\s*case\>'
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
205 endfunction
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
206
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
207 function! s:is_case_break(line)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
208 return a:line =~ '^\s*;[;&]'
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
209 endfunction
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
210
9407
619a98a67f67 commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents: 8246
diff changeset
211 function! s:is_here_doc(line)
619a98a67f67 commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents: 8246
diff changeset
212 if a:line =~ '^\w\+$'
619a98a67f67 commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents: 8246
diff changeset
213 let here_pat = '<<-\?'. s:escape(a:line). '\$'
619a98a67f67 commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents: 8246
diff changeset
214 return search(here_pat, 'bnW') > 0
619a98a67f67 commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents: 8246
diff changeset
215 endif
619a98a67f67 commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents: 8246
diff changeset
216 return 0
619a98a67f67 commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents: 8246
diff changeset
217 endfunction
619a98a67f67 commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents: 8246
diff changeset
218
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
219 function! s:is_case_ended(line)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
220 return s:is_case_break(a:line) || a:line =~ ';[;&]\s*\%(#.*\)\=$'
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
221 endfunction
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
222
5555
7818ca6de3d0 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2034
diff changeset
223 function! s:is_case_empty(line)
7818ca6de3d0 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2034
diff changeset
224 if a:line =~ '^\s*$' || a:line =~ '^\s*#'
7818ca6de3d0 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2034
diff changeset
225 return s:is_case_empty(getline(v:lnum - 1))
7818ca6de3d0 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2034
diff changeset
226 else
7818ca6de3d0 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2034
diff changeset
227 return a:line =~ '^\s*case\>'
7818ca6de3d0 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2034
diff changeset
228 endif
7818ca6de3d0 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2034
diff changeset
229 endfunction
7818ca6de3d0 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2034
diff changeset
230
9407
619a98a67f67 commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents: 8246
diff changeset
231 function! s:escape(pattern)
619a98a67f67 commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents: 8246
diff changeset
232 return '\V'. escape(a:pattern, '\\')
619a98a67f67 commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents: 8246
diff changeset
233 endfunction
619a98a67f67 commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents: 8246
diff changeset
234
13912
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
235 function! s:is_empty(line)
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
236 return a:line =~ '^\s*$'
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
237 endfunction
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
238
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
239 function! s:end_block(line)
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
240 return a:line =~ '^\s*}'
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
241 endfunction
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
242
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
243 function! s:start_block(line)
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
244 return a:line =~ '{\s*\(#.*\)\?$'
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
245 endfunction
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
246
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
247 function! s:find_start_block(lnum)
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
248 let i = a:lnum
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
249 while i > 1 && !s:start_block(getline(i))
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
250 let i -= 1
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
251 endwhile
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
252 return i
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
253 endfunction
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
254
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
255 function! s:is_comment(line)
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
256 return a:line =~ '^\s*#'
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
257 endfunction
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12045
diff changeset
258
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
259 let &cpo = s:cpo_save
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
260 unlet s:cpo_save