comparison runtime/indent/sh.vim @ 9407:619a98a67f67

commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Jul 2 21:42:23 2016 +0200 Updated runtime files.
author Christian Brabandt <cb@256bit.org>
date Sat, 02 Jul 2016 21:45:06 +0200
parents f16bfe02cef1
children d183d629509e
comparison
equal deleted inserted replaced
9406:4aa80bcc9a00 9407:619a98a67f67
1 " Vim indent file 1 " Vim indent file
2 " Language: Shell Script 2 " Language: Shell Script
3 " Maintainer: Christian Brabandt <cb@256bit.org> 3 " Maintainer: Christian Brabandt <cb@256bit.org>
4 " Previous Maintainer: Peter Aronoff <telemachus@arpinum.org> 4 " Previous Maintainer: Peter Aronoff <telemachus@arpinum.org>
5 " Original Author: Nikolai Weibull <now@bitwi.se> 5 " Original Author: Nikolai Weibull <now@bitwi.se>
6 " Latest Revision: 2016-02-15 6 " Latest Revision: 2016-06-27
7 " License: Vim (see :h license) 7 " License: Vim (see :h license)
8 " Repository: https://github.com/chrisbra/vim-sh-indent 8 " Repository: https://github.com/chrisbra/vim-sh-indent
9 " Changelog:
10 " 20160627: - detect heredocs correctly
11 " 20160213: - detect function definition correctly
12 " 20160202: - use shiftwidth() function
13 " 20151215: - set b:undo_indent variable
14 " 20150728: - add foreach detection for zsh
9 15
10 if exists("b:did_indent") 16 if exists("b:did_indent")
11 finish 17 finish
12 endif 18 endif
13 let b:did_indent = 1 19 let b:did_indent = 1
100 \ 0 : s:indent_value('case-statements')) - 106 \ 0 : s:indent_value('case-statements')) -
101 \ s:indent_value('case-breaks') 107 \ s:indent_value('case-breaks')
102 endif 108 endif
103 elseif s:is_case_break(line) 109 elseif s:is_case_break(line)
104 let ind -= s:indent_value('case-breaks') 110 let ind -= s:indent_value('case-breaks')
111 elseif s:is_here_doc(line)
112 let ind = 0
105 endif 113 endif
106 114
107 return ind 115 return ind
108 endfunction 116 endfunction
109 117
158 166
159 function! s:is_case_break(line) 167 function! s:is_case_break(line)
160 return a:line =~ '^\s*;[;&]' 168 return a:line =~ '^\s*;[;&]'
161 endfunction 169 endfunction
162 170
171 function! s:is_here_doc(line)
172 if a:line =~ '^\w\+$'
173 let here_pat = '<<-\?'. s:escape(a:line). '\$'
174 return search(here_pat, 'bnW') > 0
175 endif
176 return 0
177 endfunction
178
163 function! s:is_case_ended(line) 179 function! s:is_case_ended(line)
164 return s:is_case_break(a:line) || a:line =~ ';[;&]\s*\%(#.*\)\=$' 180 return s:is_case_break(a:line) || a:line =~ ';[;&]\s*\%(#.*\)\=$'
165 endfunction 181 endfunction
166 182
167 function! s:is_case_empty(line) 183 function! s:is_case_empty(line)
170 else 186 else
171 return a:line =~ '^\s*case\>' 187 return a:line =~ '^\s*case\>'
172 endif 188 endif
173 endfunction 189 endfunction
174 190
191 function! s:escape(pattern)
192 return '\V'. escape(a:pattern, '\\')
193 endfunction
194
175 let &cpo = s:cpo_save 195 let &cpo = s:cpo_save
176 unlet s:cpo_save 196 unlet s:cpo_save