comparison runtime/ftplugin/ruby.vim @ 15512:f0f06837a699

Update runtime files. commit https://github.com/vim/vim/commit/d09091d4955c5f41de69928f2db85611ed54ed23 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Jan 17 16:07:22 2019 +0100 Update runtime files.
author Bram Moolenaar <Bram@vim.org>
date Thu, 17 Jan 2019 16:15:08 +0100
parents 43efa4f5a8ea
children 70ce979e76bc
comparison
equal deleted inserted replaced
15511:f41122780189 15512:f0f06837a699
1 " Vim filetype plugin 1 " Vim filetype plugin
2 " Language: Ruby 2 " Language: Ruby
3 " Maintainer: Tim Pope <vimNOSPAM@tpope.org> 3 " Maintainer: Tim Pope <vimNOSPAM@tpope.org>
4 " URL: https://github.com/vim-ruby/vim-ruby 4 " URL: https://github.com/vim-ruby/vim-ruby
5 " Release Coordinator: Doug Kearns <dougkearns@gmail.com> 5 " Release Coordinator: Doug Kearns <dougkearns@gmail.com>
6 " ---------------------------------------------------------------------------- 6 " Last Change: 2019 Jan 06
7 7
8 if (exists("b:did_ftplugin")) 8 if (exists("b:did_ftplugin"))
9 finish 9 finish
10 endif 10 endif
11 let b:did_ftplugin = 1 11 let b:did_ftplugin = 1
42 endif 42 endif
43 43
44 setlocal formatoptions-=t formatoptions+=croql 44 setlocal formatoptions-=t formatoptions+=croql
45 45
46 setlocal include=^\\s*\\<\\(load\\>\\\|require\\>\\\|autoload\\s*:\\=[\"']\\=\\h\\w*[\"']\\=,\\) 46 setlocal include=^\\s*\\<\\(load\\>\\\|require\\>\\\|autoload\\s*:\\=[\"']\\=\\h\\w*[\"']\\=,\\)
47 setlocal includeexpr=substitute(substitute(v:fname,'::','/','g'),'\%(\.rb\)\=$','.rb','')
48 setlocal suffixesadd=.rb 47 setlocal suffixesadd=.rb
49 48
50 if exists("&ofu") && has("ruby") 49 if exists("&ofu") && has("ruby")
51 setlocal omnifunc=rubycomplete#Complete 50 setlocal omnifunc=rubycomplete#Complete
52 endif 51 endif
53 52
54 " To activate, :set ballooneval
55 if has('balloon_eval') && exists('+balloonexpr')
56 setlocal balloonexpr=RubyBalloonexpr()
57 endif
58
59
60 " TODO: 53 " TODO:
61 "setlocal define=^\\s*def 54 "setlocal define=^\\s*def
62 55
63 setlocal comments=:# 56 setlocal comments=:#
64 setlocal commentstring=#\ %s 57 setlocal commentstring=#\ %s
67 let g:ruby_version_paths = {} 60 let g:ruby_version_paths = {}
68 endif 61 endif
69 62
70 function! s:query_path(root) abort 63 function! s:query_path(root) abort
71 let code = "print $:.join %q{,}" 64 let code = "print $:.join %q{,}"
72 if &shell =~# 'sh' 65 if &shell =~# 'sh' && empty(&shellxquote)
73 let prefix = 'env PATH='.shellescape($PATH).' ' 66 let prefix = 'env PATH='.shellescape($PATH).' '
74 else 67 else
75 let prefix = '' 68 let prefix = ''
76 endif 69 endif
77 if &shellxquote == "'" 70 if &shellxquote == "'"
139 if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter") 132 if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
140 let b:browsefilter = "Ruby Source Files (*.rb)\t*.rb\n" . 133 let b:browsefilter = "Ruby Source Files (*.rb)\t*.rb\n" .
141 \ "All Files (*.*)\t*.*\n" 134 \ "All Files (*.*)\t*.*\n"
142 endif 135 endif
143 136
144 let b:undo_ftplugin = "setl fo< inc< inex< sua< def< com< cms< path< tags< kp<" 137 let b:undo_ftplugin = "setl inc= sua= path= tags= fo< com< cms< kp="
145 \."| unlet! b:browsefilter b:match_ignorecase b:match_words b:match_skip" 138 \."| unlet! b:browsefilter b:match_ignorecase b:match_words b:match_skip"
146 \."| if exists('&ofu') && has('ruby') | setl ofu< | endif" 139 \."| if exists('&ofu') && has('ruby') | setl ofu< | endif"
147 \."| if has('balloon_eval') && exists('+bexpr') | setl bexpr< | endif" 140
141 if get(g:, 'ruby_recommended_style', 1)
142 setlocal shiftwidth=2 softtabstop=2 expandtab
143 let b:undo_ftplugin .= ' | setl sw< sts< et<'
144 endif
145
146 " To activate, :set ballooneval
147 if exists('+balloonexpr') && get(g:, 'ruby_balloonexpr')
148 setlocal balloonexpr=RubyBalloonexpr()
149 let b:undo_ftplugin .= "| setl bexpr="
150 endif
148 151
149 function! s:map(mode, flags, map) abort 152 function! s:map(mode, flags, map) abort
150 let from = matchstr(a:map, '\S\+') 153 let from = matchstr(a:map, '\S\+')
151 if empty(mapcheck(from, a:mode)) 154 if empty(mapcheck(from, a:mode))
152 exe a:mode.'map' '<buffer>'.(a:0 ? a:1 : '') a:map 155 exe a:mode.'map' '<buffer>' a:map
153 let b:undo_ftplugin .= '|sil! '.a:mode.'unmap <buffer> '.from 156 let b:undo_ftplugin .= '|sil! '.a:mode.'unmap <buffer> '.from
154 endif 157 endif
155 endfunction 158 endfunction
156 159
157 cmap <buffer><script><expr> <Plug><cword> substitute(RubyCursorIdentifier(),'^$',"\022\027",'') 160 cmap <buffer><script><expr> <Plug><ctag> substitute(RubyCursorTag(),'^$',"\022\027",'')
158 cmap <buffer><script><expr> <Plug><cfile> substitute(RubyCursorFile(),'^$',"\022\006",'') 161 cmap <buffer><script><expr> <Plug><cfile> substitute(RubyCursorFile(),'^$',"\022\006",'')
159 let b:undo_ftplugin .= "| sil! cunmap <buffer> <Plug><cword>| sil! cunmap <buffer> <Plug><cfile>" 162 let b:undo_ftplugin .= "| sil! cunmap <buffer> <Plug><ctag>| sil! cunmap <buffer> <Plug><cfile>"
160 163
161 if !exists("g:no_plugin_maps") && !exists("g:no_ruby_maps") 164 if !exists("g:no_plugin_maps") && !exists("g:no_ruby_maps")
162 nmap <buffer><script> <SID>: :<C-U> 165 nmap <buffer><script> <SID>: :<C-U>
163 nmap <buffer><script> <SID>c: :<C-U><C-R>=v:count ? v:count : ''<CR> 166 nmap <buffer><script> <SID>c: :<C-U><C-R>=v:count ? v:count : ''<CR>
164 167
165 nnoremap <silent> <buffer> [m :<C-U>call <SID>searchsyn('\<def\>','rubyDefine','b','n')<CR> 168 nnoremap <silent> <buffer> [m :<C-U>call <SID>searchsyn('\<def\>',['rubyDefine'],'b','n')<CR>
166 nnoremap <silent> <buffer> ]m :<C-U>call <SID>searchsyn('\<def\>','rubyDefine','','n')<CR> 169 nnoremap <silent> <buffer> ]m :<C-U>call <SID>searchsyn('\<def\>',['rubyDefine'],'','n')<CR>
167 nnoremap <silent> <buffer> [M :<C-U>call <SID>searchsyn('\<end\>','rubyDefine','b','n')<CR> 170 nnoremap <silent> <buffer> [M :<C-U>call <SID>searchsyn('\<end\>',['rubyDefine'],'b','n')<CR>
168 nnoremap <silent> <buffer> ]M :<C-U>call <SID>searchsyn('\<end\>','rubyDefine','','n')<CR> 171 nnoremap <silent> <buffer> ]M :<C-U>call <SID>searchsyn('\<end\>',['rubyDefine'],'','n')<CR>
169 xnoremap <silent> <buffer> [m :<C-U>call <SID>searchsyn('\<def\>','rubyDefine','b','v')<CR> 172 xnoremap <silent> <buffer> [m :<C-U>call <SID>searchsyn('\<def\>',['rubyDefine'],'b','v')<CR>
170 xnoremap <silent> <buffer> ]m :<C-U>call <SID>searchsyn('\<def\>','rubyDefine','','v')<CR> 173 xnoremap <silent> <buffer> ]m :<C-U>call <SID>searchsyn('\<def\>',['rubyDefine'],'','v')<CR>
171 xnoremap <silent> <buffer> [M :<C-U>call <SID>searchsyn('\<end\>','rubyDefine','b','v')<CR> 174 xnoremap <silent> <buffer> [M :<C-U>call <SID>searchsyn('\<end\>',['rubyDefine'],'b','v')<CR>
172 xnoremap <silent> <buffer> ]M :<C-U>call <SID>searchsyn('\<end\>','rubyDefine','','v')<CR> 175 xnoremap <silent> <buffer> ]M :<C-U>call <SID>searchsyn('\<end\>',['rubyDefine'],'','v')<CR>
173 176
174 nnoremap <silent> <buffer> [[ :<C-U>call <SID>searchsyn('\<\%(class\<Bar>module\)\>','rubyModule\<Bar>rubyClass','b','n')<CR> 177 nnoremap <silent> <buffer> [[ :<C-U>call <SID>searchsyn('\<\%(class\<Bar>module\)\>',['rubyModule','rubyClass'],'b','n')<CR>
175 nnoremap <silent> <buffer> ]] :<C-U>call <SID>searchsyn('\<\%(class\<Bar>module\)\>','rubyModule\<Bar>rubyClass','','n')<CR> 178 nnoremap <silent> <buffer> ]] :<C-U>call <SID>searchsyn('\<\%(class\<Bar>module\)\>',['rubyModule','rubyClass'],'','n')<CR>
176 nnoremap <silent> <buffer> [] :<C-U>call <SID>searchsyn('\<end\>','rubyModule\<Bar>rubyClass','b','n')<CR> 179 nnoremap <silent> <buffer> [] :<C-U>call <SID>searchsyn('\<end\>',['rubyModule','rubyClass'],'b','n')<CR>
177 nnoremap <silent> <buffer> ][ :<C-U>call <SID>searchsyn('\<end\>','rubyModule\<Bar>rubyClass','','n')<CR> 180 nnoremap <silent> <buffer> ][ :<C-U>call <SID>searchsyn('\<end\>',['rubyModule','rubyClass'],'','n')<CR>
178 xnoremap <silent> <buffer> [[ :<C-U>call <SID>searchsyn('\<\%(class\<Bar>module\)\>','rubyModule\<Bar>rubyClass','b','v')<CR> 181 xnoremap <silent> <buffer> [[ :<C-U>call <SID>searchsyn('\<\%(class\<Bar>module\)\>',['rubyModule','rubyClass'],'b','v')<CR>
179 xnoremap <silent> <buffer> ]] :<C-U>call <SID>searchsyn('\<\%(class\<Bar>module\)\>','rubyModule\<Bar>rubyClass','','v')<CR> 182 xnoremap <silent> <buffer> ]] :<C-U>call <SID>searchsyn('\<\%(class\<Bar>module\)\>',['rubyModule','rubyClass'],'','v')<CR>
180 xnoremap <silent> <buffer> [] :<C-U>call <SID>searchsyn('\<end\>','rubyModule\<Bar>rubyClass','b','v')<CR> 183 xnoremap <silent> <buffer> [] :<C-U>call <SID>searchsyn('\<end\>',['rubyModule','rubyClass'],'b','v')<CR>
181 xnoremap <silent> <buffer> ][ :<C-U>call <SID>searchsyn('\<end\>','rubyModule\<Bar>rubyClass','','v')<CR> 184 xnoremap <silent> <buffer> ][ :<C-U>call <SID>searchsyn('\<end\>',['rubyModule','rubyClass'],'','v')<CR>
182 185
183 let b:undo_ftplugin = b:undo_ftplugin 186 let b:undo_ftplugin = b:undo_ftplugin
184 \."| sil! exe 'unmap <buffer> [[' | sil! exe 'unmap <buffer> ]]' | sil! exe 'unmap <buffer> []' | sil! exe 'unmap <buffer> ]['" 187 \."| sil! exe 'unmap <buffer> [[' | sil! exe 'unmap <buffer> ]]' | sil! exe 'unmap <buffer> []' | sil! exe 'unmap <buffer> ]['"
185 \."| sil! exe 'unmap <buffer> [m' | sil! exe 'unmap <buffer> ]m' | sil! exe 'unmap <buffer> [M' | sil! exe 'unmap <buffer> ]M'" 188 \."| sil! exe 'unmap <buffer> [m' | sil! exe 'unmap <buffer> ]m' | sil! exe 'unmap <buffer> [M' | sil! exe 'unmap <buffer> ]M'"
186 189
202 let b:undo_ftplugin = b:undo_ftplugin 205 let b:undo_ftplugin = b:undo_ftplugin
203 \."| sil! exe 'ounmap <buffer> iM' | sil! exe 'ounmap <buffer> aM'" 206 \."| sil! exe 'ounmap <buffer> iM' | sil! exe 'ounmap <buffer> aM'"
204 \."| sil! exe 'xunmap <buffer> iM' | sil! exe 'xunmap <buffer> aM'" 207 \."| sil! exe 'xunmap <buffer> iM' | sil! exe 'xunmap <buffer> aM'"
205 endif 208 endif
206 209
207 call s:map('c', '', '<C-R><C-W> <Plug><cword>')
208 call s:map('c', '', '<C-R><C-F> <Plug><cfile>') 210 call s:map('c', '', '<C-R><C-F> <Plug><cfile>')
209 211
210 cmap <buffer><script><expr> <SID>tagzv &foldopen =~# 'tag' ? '<Bar>norm! zv' : '' 212 cmap <buffer><script><expr> <SID>tagzv &foldopen =~# 'tag' ? '<Bar>norm! zv' : ''
211 call s:map('n', '<silent>', '<C-]> <SID>:exe v:count1."tag <Plug><cword>"<SID>tagzv<CR>') 213 call s:map('n', '<silent>', '<C-]> <SID>:exe v:count1."tag <Plug><ctag>"<SID>tagzv<CR>')
212 call s:map('n', '<silent>', 'g<C-]> <SID>:exe "tjump <Plug><cword>"<SID>tagzv<CR>') 214 call s:map('n', '<silent>', 'g<C-]> <SID>:exe "tjump <Plug><ctag>"<SID>tagzv<CR>')
213 call s:map('n', '<silent>', 'g] <SID>:exe "tselect <Plug><cword>"<SID>tagzv<CR>') 215 call s:map('n', '<silent>', 'g] <SID>:exe "tselect <Plug><ctag>"<SID>tagzv<CR>')
214 call s:map('n', '<silent>', '<C-W>] <SID>:exe v:count1."stag <Plug><cword>"<SID>tagzv<CR>') 216 call s:map('n', '<silent>', '<C-W>] <SID>:exe v:count1."stag <Plug><ctag>"<SID>tagzv<CR>')
215 call s:map('n', '<silent>', '<C-W><C-]> <SID>:exe v:count1."stag <Plug><cword>"<SID>tagzv<CR>') 217 call s:map('n', '<silent>', '<C-W><C-]> <SID>:exe v:count1."stag <Plug><ctag>"<SID>tagzv<CR>')
216 call s:map('n', '<silent>', '<C-W>g<C-]> <SID>:exe "stjump <Plug><cword>"<SID>tagzv<CR>') 218 call s:map('n', '<silent>', '<C-W>g<C-]> <SID>:exe "stjump <Plug><ctag>"<SID>tagzv<CR>')
217 call s:map('n', '<silent>', '<C-W>g] <SID>:exe "stselect <Plug><cword>"<SID>tagzv<CR>') 219 call s:map('n', '<silent>', '<C-W>g] <SID>:exe "stselect <Plug><ctag>"<SID>tagzv<CR>')
218 call s:map('n', '<silent>', '<C-W>} <SID>:exe v:count1."ptag <Plug><cword>"<CR>') 220 call s:map('n', '<silent>', '<C-W>} <SID>:exe v:count1."ptag <Plug><ctag>"<CR>')
219 call s:map('n', '<silent>', '<C-W>g} <SID>:exe "ptjump <Plug><cword>"<CR>') 221 call s:map('n', '<silent>', '<C-W>g} <SID>:exe "ptjump <Plug><ctag>"<CR>')
220 222
221 call s:map('n', '<silent>', 'gf <SID>c:find <Plug><cfile><CR>') 223 call s:map('n', '<silent>', 'gf <SID>c:find <Plug><cfile><CR>')
222 call s:map('n', '<silent>', '<C-W>f <SID>c:sfind <Plug><cfile><CR>') 224 call s:map('n', '<silent>', '<C-W>f <SID>c:sfind <Plug><cfile><CR>')
223 call s:map('n', '<silent>', '<C-W><C-F> <SID>c:sfind <Plug><cfile><CR>') 225 call s:map('n', '<silent>', '<C-W><C-F> <SID>c:sfind <Plug><cfile><CR>')
224 call s:map('n', '<silent>', '<C-W>gf <SID>c:tabfind <Plug><cfile><CR>') 226 call s:map('n', '<silent>', '<C-W>gf <SID>c:tabfind <Plug><cfile><CR>')
286 norm! m' 288 norm! m'
287 if a:mode ==# 'v' 289 if a:mode ==# 'v'
288 norm! gv 290 norm! gv
289 endif 291 endif
290 let i = 0 292 let i = 0
293 call map(a:syn, 'hlID(v:val)')
291 while i < cnt 294 while i < cnt
292 let i = i + 1 295 let i = i + 1
293 let line = line('.') 296 let line = line('.')
294 let col = col('.') 297 let col = col('.')
295 let pos = search(a:pattern,'W'.a:flags) 298 let pos = search(a:pattern,'W'.a:flags)
296 while pos != 0 && s:synname() !~# a:syn 299 while pos != 0 && index(a:syn, s:synid()) < 0
297 let pos = search(a:pattern,'W'.a:flags) 300 let pos = search(a:pattern,'W'.a:flags)
298 endwhile 301 endwhile
299 if pos == 0 302 if pos == 0
300 call cursor(line,col) 303 call cursor(line,col)
301 return 304 return
302 endif 305 endif
303 endwhile 306 endwhile
304 endfunction 307 endfunction
305 308
306 function! s:synname() abort 309 function! s:synid() abort
307 return synIDattr(synID(line('.'),col('.'),0),'name') 310 return synID(line('.'),col('.'),0)
308 endfunction 311 endfunction
309 312
310 function! s:wrap_i(back,forward) abort 313 function! s:wrap_i(back,forward) abort
311 execute 'norm k'.a:forward 314 execute 'norm k'.a:forward
312 let line = line('.') 315 let line = line('.')
347 let raw = matchstr(getline('.')[col-1 : ],pattern) 350 let raw = matchstr(getline('.')[col-1 : ],pattern)
348 let stripped = substitute(substitute(raw,'\s\+=$','=',''),'^\s*[:.]\=','','') 351 let stripped = substitute(substitute(raw,'\s\+=$','=',''),'^\s*[:.]\=','','')
349 return stripped == '' ? expand("<cword>") : stripped 352 return stripped == '' ? expand("<cword>") : stripped
350 endfunction 353 endfunction
351 354
355 function! RubyCursorTag() abort
356 return substitute(RubyCursorIdentifier(), '^[$@]*', '', '')
357 endfunction
358
352 function! RubyCursorFile() abort 359 function! RubyCursorFile() abort
353 let isfname = &isfname 360 let isfname = &isfname
354 try 361 try
355 set isfname+=: 362 set isfname+=:
356 let cfile = expand('<cfile>') 363 let cfile = expand('<cfile>')
358 let isfname = &isfname 365 let isfname = &isfname
359 endtry 366 endtry
360 let pre = matchstr(strpart(getline('.'), 0, col('.')-1), '.*\f\@<!') 367 let pre = matchstr(strpart(getline('.'), 0, col('.')-1), '.*\f\@<!')
361 let post = matchstr(strpart(getline('.'), col('.')), '\f\@!.*') 368 let post = matchstr(strpart(getline('.'), col('.')), '\f\@!.*')
362 let ext = getline('.') =~# '^\s*\%(require\%(_relative\)\=\|autoload\)\>' && cfile !~# '\.rb$' ? '.rb' : '' 369 let ext = getline('.') =~# '^\s*\%(require\%(_relative\)\=\|autoload\)\>' && cfile !~# '\.rb$' ? '.rb' : ''
363 if s:synname() ==# 'rubyConstant' 370 if s:synid() ==# hlID('rubyConstant')
364 let cfile = substitute(cfile,'\.\w\+[?!=]\=$','','') 371 let cfile = substitute(cfile,'\.\w\+[?!=]\=$','','')
372 let cfile = substitute(cfile,'^::','','')
365 let cfile = substitute(cfile,'::','/','g') 373 let cfile = substitute(cfile,'::','/','g')
366 let cfile = substitute(cfile,'\(\u\+\)\(\u\l\)','\1_\2', 'g') 374 let cfile = substitute(cfile,'\(\u\+\)\(\u\l\)','\1_\2', 'g')
367 let cfile = substitute(cfile,'\(\l\|\d\)\(\u\)','\1_\2', 'g') 375 let cfile = substitute(cfile,'\(\l\|\d\)\(\u\)','\1_\2', 'g')
368 return tolower(cfile) . '.rb' 376 return tolower(cfile) . '.rb'
369 elseif getline('.') =~# '^\s*require_relative\s*\(["'']\).*\1\s*$' 377 elseif getline('.') =~# '^\s*require_relative\s*\(["'']\).*\1\s*$'