annotate runtime/indent/sh.vim @ 12289:294f510f6d35 v8.0.1024

patch 8.0.1024: folds lost when session file has a buffer in two windows commit https://github.com/vim/vim/commit/4bebc9a0565670b853d227f81a9a31eafdb47eed Author: Bram Moolenaar <Bram@vim.org> Date: Wed Aug 30 21:07:38 2017 +0200 patch 8.0.1024: folds lost when session file has a buffer in two windows Problem: Manual folds are lost when a session file has the same buffer in two windows. (Jeansen) Solution: Use ":edit" only once. (Christian Brabandt, closes #1958)
author Christian Brabandt <cb@256bit.org>
date Wed, 30 Aug 2017 21:15:04 +0200
parents 444ad56c0cac
children a9fdf01085a8
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>
6918
2def7b25de60 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 6153
diff changeset
4 " Previous Maintainer: Peter Aronoff <telemachus@arpinum.org>
7013
349e6c01f35d Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 6918
diff changeset
5 " Original Author: Nikolai Weibull <now@bitwi.se>
12045
444ad56c0cac Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11442
diff changeset
6 " Latest Revision: 2017-08-08
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:
12045
444ad56c0cac Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11442
diff changeset
10 " 20170808: - better indent of line continuation
11442
d183d629509e Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9407
diff changeset
11 " 20170502: - get rid of buffer-shiftwidth function
d183d629509e Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9407
diff changeset
12 " 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
13 " 20160627: - detect heredocs correctly
619a98a67f67 commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents: 8246
diff changeset
14 " 20160213: - detect function definition correctly
619a98a67f67 commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents: 8246
diff changeset
15 " 20160202: - use shiftwidth() function
619a98a67f67 commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents: 8246
diff changeset
16 " 20151215: - set b:undo_indent variable
619a98a67f67 commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents: 8246
diff changeset
17 " 20150728: - add foreach detection for zsh
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 if exists("b:did_indent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 let b:did_indent = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 setlocal indentexpr=GetShIndent()
7013
349e6c01f35d Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 6918
diff changeset
25 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
26 setlocal indentkeys+=0=fin,0=fil,0=fip,0=fir,0=fix
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 setlocal indentkeys-=:,0#
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
28 setlocal nosmartindent
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29
8246
f16bfe02cef1 commit https://github.com/vim/vim/commit/f391327adbbffb11180cf6038a92af1ed144e907
Christian Brabandt <cb@256bit.org>
parents: 7924
diff changeset
30 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
31
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 if exists("*GetShIndent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
36 let s:cpo_save = &cpo
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
37 set cpo&vim
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
39 let s:sh_indent_defaults = {
11442
d183d629509e Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9407
diff changeset
40 \ 'default': function('shiftwidth'),
d183d629509e Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9407
diff changeset
41 \ 'continuation-line': function('shiftwidth'),
d183d629509e Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9407
diff changeset
42 \ 'case-labels': function('shiftwidth'),
d183d629509e Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9407
diff changeset
43 \ 'case-statements': function('shiftwidth'),
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
44 \ 'case-breaks': 0 }
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! s:indent_value(option)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
47 let Value = exists('b:sh_indent_options')
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
48 \ && has_key(b:sh_indent_options, a:option) ?
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
49 \ b:sh_indent_options[a:option] :
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
50 \ s:sh_indent_defaults[a:option]
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
51 if type(Value) == type(function('type'))
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
52 return Value()
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
53 endif
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
54 return Value
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
55 endfunction
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
56
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
57 function! GetShIndent()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 let lnum = prevnonblank(v:lnum - 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59 if lnum == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60 return 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
63 let pnum = prevnonblank(lnum - 1)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
64
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 let ind = indent(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 let line = getline(lnum)
7013
349e6c01f35d Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 6918
diff changeset
67 if line =~ '^\s*\%(if\|then\|do\|else\|elif\|case\|while\|until\|for\|select\|foreach\)\>'
349e6c01f35d Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 6918
diff changeset
68 if line !~ '\<\%(fi\|esac\|done\|end\)\>\s*\%(#.*\)\=$'
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
69 let ind += s:indent_value('default')
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
70 endif
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
71 elseif s:is_case_label(line, pnum)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
72 if !s:is_case_ended(line)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
73 let ind += s:indent_value('case-statements')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 endif
8246
f16bfe02cef1 commit https://github.com/vim/vim/commit/f391327adbbffb11180cf6038a92af1ed144e907
Christian Brabandt <cb@256bit.org>
parents: 7924
diff changeset
75 elseif line =~ '^\s*\<\k\+\>\s*()\s*{' || line =~ '^\s*{' || line =~ '^\s*function\s*\w\S\+\s*\%(()\)\?\s*{'
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
76 if line !~ '}\s*\%(#.*\)\=$'
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
77 let ind += s:indent_value('default')
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
78 endif
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
79 elseif s:is_continuation_line(line)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
80 if pnum == 0 || !s:is_continuation_line(getline(pnum))
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
81 let ind += s:indent_value('continuation-line')
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
82 endif
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
83 elseif pnum != 0 && s:is_continuation_line(getline(pnum))
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
84 let ind = indent(s:find_continued_lnum(pnum))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
87 let pine = line
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88 let line = getline(v:lnum)
7013
349e6c01f35d Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 6918
diff changeset
89 if line =~ '^\s*\%(then\|do\|else\|elif\|fi\|done\|end\)\>' || line =~ '^\s*}'
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
90 let ind -= s:indent_value('default')
5555
7818ca6de3d0 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2034
diff changeset
91 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
92 let ind -= s:indent_value('default')
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
93 elseif line =~ '^\s*esac\>'
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
94 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
95 \ 0 : s:indent_value('case-statements')) +
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
96 \ s:indent_value('case-labels')
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
97 if s:is_case_break(pine)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
98 let ind += s:indent_value('case-breaks')
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
99 endif
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
100 elseif s:is_case_label(line, lnum)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
101 if s:is_case(pine)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
102 let ind = indent(lnum) + s:indent_value('case-labels')
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
103 else
6153
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5555
diff changeset
104 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
105 \ 0 : s:indent_value('case-statements')) -
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5555
diff changeset
106 \ s:indent_value('case-breaks')
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
107 endif
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
108 elseif s:is_case_break(line)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
109 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
110 elseif s:is_here_doc(line)
619a98a67f67 commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents: 8246
diff changeset
111 let ind = 0
11442
d183d629509e Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9407
diff changeset
112 " statements, executed within a here document. Keep the current indent
d183d629509e Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 9407
diff changeset
113 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
114 return indent(v:lnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
115 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
116
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
117 return ind
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118 endfunction
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
119
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
120 function! s:is_continuation_line(line)
12045
444ad56c0cac Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11442
diff changeset
121 return a:line =~ '\%(\%(^\|[^\\]\)\\\|&&\|||\||\)' .
444ad56c0cac Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11442
diff changeset
122 \ '\s*\({\s*\)\=\(#.*\)\=$'
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
123 endfunction
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
124
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
125 function! s:find_continued_lnum(lnum)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
126 let i = a:lnum
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
127 while i > 1 && s:is_continuation_line(getline(i - 1))
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
128 let i -= 1
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
129 endwhile
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
130 return i
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
131 endfunction
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
132
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
133 function! s:is_case_label(line, pnum)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
134 if a:line !~ '^\s*(\=.*)'
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
135 return 0
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
136 endif
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
137
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
138 if a:pnum > 0
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
139 let pine = getline(a:pnum)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
140 if !(s:is_case(pine) || s:is_case_ended(pine))
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
141 return 0
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
142 endif
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
143 endif
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 let suffix = substitute(a:line, '^\s*(\=', "", "")
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
146 let nesting = 0
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
147 let i = 0
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
148 let n = strlen(suffix)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
149 while i < n
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
150 let c = suffix[i]
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
151 let i += 1
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
152 if c == '\\'
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
153 let i += 1
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
154 elseif c == '('
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
155 let nesting += 1
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
156 elseif c == ')'
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
157 if nesting == 0
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
158 return 1
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 let nesting -= 1
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
161 endif
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
162 endwhile
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
163 return 0
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
164 endfunction
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
165
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
166 function! s:is_case(line)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
167 return a:line =~ '^\s*case\>'
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
168 endfunction
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
169
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
170 function! s:is_case_break(line)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
171 return a:line =~ '^\s*;[;&]'
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
172 endfunction
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
173
9407
619a98a67f67 commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents: 8246
diff changeset
174 function! s:is_here_doc(line)
619a98a67f67 commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents: 8246
diff changeset
175 if a:line =~ '^\w\+$'
619a98a67f67 commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents: 8246
diff changeset
176 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
177 return search(here_pat, 'bnW') > 0
619a98a67f67 commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents: 8246
diff changeset
178 endif
619a98a67f67 commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents: 8246
diff changeset
179 return 0
619a98a67f67 commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents: 8246
diff changeset
180 endfunction
619a98a67f67 commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents: 8246
diff changeset
181
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
182 function! s:is_case_ended(line)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
183 return s:is_case_break(a:line) || a:line =~ ';[;&]\s*\%(#.*\)\=$'
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
184 endfunction
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 856
diff changeset
185
5555
7818ca6de3d0 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2034
diff changeset
186 function! s:is_case_empty(line)
7818ca6de3d0 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2034
diff changeset
187 if a:line =~ '^\s*$' || a:line =~ '^\s*#'
7818ca6de3d0 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2034
diff changeset
188 return s:is_case_empty(getline(v:lnum - 1))
7818ca6de3d0 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2034
diff changeset
189 else
7818ca6de3d0 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2034
diff changeset
190 return a:line =~ '^\s*case\>'
7818ca6de3d0 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2034
diff changeset
191 endif
7818ca6de3d0 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2034
diff changeset
192 endfunction
7818ca6de3d0 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2034
diff changeset
193
9407
619a98a67f67 commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents: 8246
diff changeset
194 function! s:escape(pattern)
619a98a67f67 commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents: 8246
diff changeset
195 return '\V'. escape(a:pattern, '\\')
619a98a67f67 commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents: 8246
diff changeset
196 endfunction
619a98a67f67 commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents: 8246
diff changeset
197
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
198 let &cpo = s:cpo_save
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
199 unlet s:cpo_save