comparison runtime/ftplugin/ruby.vim @ 18857:70ce979e76bc

Update a few runtime files. Commit: https://github.com/vim/vim/commit/2ed639abdc4000436115f378e28320b7bee38a6e Author: Bram Moolenaar <Bram@vim.org> Date: Mon Dec 9 23:11:18 2019 +0100 Update a few runtime files.
author Bram Moolenaar <Bram@vim.org>
date Mon, 09 Dec 2019 23:15:04 +0100
parents f0f06837a699
children 43593a5d873f
comparison
equal deleted inserted replaced
18856:00ef17508280 18857:70ce979e76bc
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 " Last Change: 2019 Jan 06 6 " Last Change: 2019 Nov 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
22 " Matchit support 22 " Matchit support
23 if exists("loaded_matchit") && !exists("b:match_words") 23 if exists("loaded_matchit") && !exists("b:match_words")
24 let b:match_ignorecase = 0 24 let b:match_ignorecase = 0
25 25
26 let b:match_words = 26 let b:match_words =
27 \ '\<\%(if\|unless\|case\|while\|until\|for\|do\|class\|module\|def\|begin\)\>=\@!' . 27 \ '{\|\<\%(if\|unless\|case\|while\|until\|for\|do\|class\|module\|def\|=\@<!begin\)\>=\@!' .
28 \ ':' . 28 \ ':' .
29 \ '\<\%(else\|elsif\|ensure\|when\|rescue\|break\|redo\|next\|retry\)\>' . 29 \ '\<\%(else\|elsif\|ensure\|when\|rescue\|break\|redo\|next\|retry\)\>' .
30 \ ':' . 30 \ ':' .
31 \ '\%(^\|[^.\:@$]\)\@<=\<end\:\@!\>' . 31 \ '}\|\%(^\|[^.\:@$=]\)\@<=\<end\:\@!\>' .
32 \ ',{:},\[:\],(:)' 32 \ ',^=begin\>:^=end\>,' .
33 \ ',\[:\],(:)'
33 34
34 let b:match_skip = 35 let b:match_skip =
35 \ "synIDattr(synID(line('.'),col('.'),0),'name') =~ '" . 36 \ "synIDattr(synID(line('.'),col('.'),0),'name') =~ '" .
36 \ "\\<ruby\\%(String\\|StringDelimiter\\|ASCIICode\\|Escape\\|" . 37 \ "\\<ruby\\%(String\\|.\+Delimiter\\|Character\\|.\+Escape\\|" .
37 \ "Regexp\\|RegexpDelimiter\\|" . 38 \ "Regexp\\|Interpolation\\|Comment\\|Documentation\\|" .
38 \ "Interpolation\\|NoInterpolation\\|Comment\\|Documentation\\|" . 39 \ "ConditionalModifier\\|RepeatModifier\\|RescueModifier\\|OptionalDo\\|" .
39 \ "ConditionalModifier\\|RepeatModifier\\|OptionalDo\\|" . 40 \ "MethodName\\|BlockArgument\\|KeywordAsMethod\\|ClassVariable\\|" .
40 \ "Function\\|BlockArgument\\|KeywordAsMethod\\|ClassVariable\\|" .
41 \ "InstanceVariable\\|GlobalVariable\\|Symbol\\)\\>'" 41 \ "InstanceVariable\\|GlobalVariable\\|Symbol\\)\\>'"
42 endif 42 endif
43 43
44 setlocal formatoptions-=t formatoptions+=croql 44 setlocal formatoptions-=t formatoptions+=croql
45 45
85 endtry 85 endtry
86 endfunction 86 endfunction
87 87
88 function! s:build_path(path) abort 88 function! s:build_path(path) abort
89 let path = join(map(copy(a:path), 'v:val ==# "." ? "" : v:val'), ',') 89 let path = join(map(copy(a:path), 'v:val ==# "." ? "" : v:val'), ',')
90 if &g:path !~# '\v^\.%(,/%(usr|emx)/include)=,,$' 90 if &g:path !~# '\v^%(\.,)=%(/%(usr|emx)/include,)=,$'
91 let path = substitute(&g:path,',,$',',','') . ',' . path 91 let path = substitute(&g:path,',,$',',','') . ',' . path
92 endif 92 endif
93 return path 93 return path
94 endfunction 94 endfunction
95 95
150 endif 150 endif
151 151
152 function! s:map(mode, flags, map) abort 152 function! s:map(mode, flags, map) abort
153 let from = matchstr(a:map, '\S\+') 153 let from = matchstr(a:map, '\S\+')
154 if empty(mapcheck(from, a:mode)) 154 if empty(mapcheck(from, a:mode))
155 exe a:mode.'map' '<buffer>' a:map 155 exe a:mode.'map' '<buffer>' a:flags a:map
156 let b:undo_ftplugin .= '|sil! '.a:mode.'unmap <buffer> '.from 156 let b:undo_ftplugin .= '|sil! '.a:mode.'unmap <buffer> '.from
157 endif 157 endif
158 endfunction 158 endfunction
159 159
160 cmap <buffer><script><expr> <Plug><ctag> substitute(RubyCursorTag(),'^$',"\022\027",'') 160 cmap <buffer><script><expr> <Plug><ctag> substitute(RubyCursorTag(),'^$',"\022\027",'')
309 function! s:synid() abort 309 function! s:synid() abort
310 return synID(line('.'),col('.'),0) 310 return synID(line('.'),col('.'),0)
311 endfunction 311 endfunction
312 312
313 function! s:wrap_i(back,forward) abort 313 function! s:wrap_i(back,forward) abort
314 execute 'norm k'.a:forward 314 execute 'norm! k'
315 execute 'norm '.a:forward
315 let line = line('.') 316 let line = line('.')
316 execute 'norm '.a:back 317 execute 'norm '.a:back
317 if line('.') == line - 1 318 if line('.') == line - 1
318 return s:wrap_a(a:back,a:forward) 319 return s:wrap_a(a:back,a:forward)
319 endif 320 endif
320 execute 'norm jV'.a:forward.'k' 321 execute 'norm! jV'
322 execute 'norm '.a:forward
323 execute 'norm! k'
321 endfunction 324 endfunction
322 325
323 function! s:wrap_a(back,forward) abort 326 function! s:wrap_a(back,forward) abort
324 execute 'norm '.a:forward 327 execute 'norm '.a:forward
325 if line('.') < line('$') && getline(line('.')+1) ==# '' 328 if line('.') < line('$') && getline(line('.')+1) ==# ''
328 execute 'norm '.a:back 331 execute 'norm '.a:back
329 while getline(line('.')-1) =~# '^\s*#' && line('.') 332 while getline(line('.')-1) =~# '^\s*#' && line('.')
330 - 333 -
331 endwhile 334 endwhile
332 if exists('after') 335 if exists('after')
333 execute 'norm V'.a:forward.'j' 336 execute 'norm! V'
337 execute 'norm '.a:forward
338 execute 'norm! j'
334 elseif line('.') > 1 && getline(line('.')-1) =~# '^\s*$' 339 elseif line('.') > 1 && getline(line('.')-1) =~# '^\s*$'
335 execute 'norm kV'.a:forward 340 execute 'norm! kV'
336 else 341 execute 'norm '.a:forward
337 execute 'norm V'.a:forward 342 else
343 execute 'norm! V'
344 execute 'norm '.a:forward
338 endif 345 endif
339 endfunction 346 endfunction
340 347
341 function! RubyCursorIdentifier() abort 348 function! RubyCursorIdentifier() abort
342 let asciicode = '\%(\w\|[]})\"'."'".']\)\@<!\%(?\%(\\M-\\C-\|\\C-\\M-\|\\M-\\c\|\\c\\M-\|\\c\|\\C-\|\\M-\)\=\%(\\\o\{1,3}\|\\x\x\{1,2}\|\\\=\S\)\)' 349 let asciicode = '\%(\w\|[]})\"'."'".']\)\@<!\%(?\%(\\M-\\C-\|\\C-\\M-\|\\M-\\c\|\\c\\M-\|\\c\|\\C-\|\\M-\)\=\%(\\\o\{1,3}\|\\x\x\{1,2}\|\\\=\S\)\)'
364 finally 371 finally
365 let isfname = &isfname 372 let isfname = &isfname
366 endtry 373 endtry
367 let pre = matchstr(strpart(getline('.'), 0, col('.')-1), '.*\f\@<!') 374 let pre = matchstr(strpart(getline('.'), 0, col('.')-1), '.*\f\@<!')
368 let post = matchstr(strpart(getline('.'), col('.')), '\f\@!.*') 375 let post = matchstr(strpart(getline('.'), col('.')), '\f\@!.*')
369 let ext = getline('.') =~# '^\s*\%(require\%(_relative\)\=\|autoload\)\>' && cfile !~# '\.rb$' ? '.rb' : ''
370 if s:synid() ==# hlID('rubyConstant') 376 if s:synid() ==# hlID('rubyConstant')
371 let cfile = substitute(cfile,'\.\w\+[?!=]\=$','','') 377 let cfile = substitute(cfile,'\.\w\+[?!=]\=$','','')
372 let cfile = substitute(cfile,'^::','','') 378 let cfile = substitute(cfile,'^::','','')
373 let cfile = substitute(cfile,'::','/','g') 379 let cfile = substitute(cfile,'::','/','g')
374 let cfile = substitute(cfile,'\(\u\+\)\(\u\l\)','\1_\2', 'g') 380 let cfile = substitute(cfile,'\(\u\+\)\(\u\l\)','\1_\2', 'g')
375 let cfile = substitute(cfile,'\(\l\|\d\)\(\u\)','\1_\2', 'g') 381 let cfile = substitute(cfile,'\(\l\|\d\)\(\u\)','\1_\2', 'g')
376 return tolower(cfile) . '.rb' 382 return tolower(cfile) . '.rb'
377 elseif getline('.') =~# '^\s*require_relative\s*\(["'']\).*\1\s*$' 383 elseif getline('.') =~# '^\s*require_relative\s*\(["'']\).*\1\s*$'
378 let cfile = expand('%:p:h') . '/' . matchstr(getline('.'),'\(["'']\)\zs.\{-\}\ze\1') . ext 384 let cfile = expand('%:p:h') . '/' . matchstr(getline('.'),'\(["'']\)\zs.\{-\}\ze\1')
385 let cfile .= cfile !~# '\.rb$' ? '.rb' : ''
379 elseif getline('.') =~# '^\s*\%(require[( ]\|load[( ]\|autoload[( ]:\w\+,\)\s*\%(::\)\=File\.expand_path(\(["'']\)\.\./.*\1,\s*__FILE__)\s*$' 386 elseif getline('.') =~# '^\s*\%(require[( ]\|load[( ]\|autoload[( ]:\w\+,\)\s*\%(::\)\=File\.expand_path(\(["'']\)\.\./.*\1,\s*__FILE__)\s*$'
380 let target = matchstr(getline('.'),'\(["'']\)\.\.\zs/.\{-\}\ze\1') 387 let target = matchstr(getline('.'),'\(["'']\)\.\.\zs/.\{-\}\ze\1')
381 let cfile = expand('%:p:h') . target . ext 388 let cfile = expand('%:p:h') . target
389 let cfile .= cfile !~# '\.rb$' ? '.rb' : ''
382 elseif getline('.') =~# '^\s*\%(require \|load \|autoload :\w\+,\)\s*\(["'']\).*\1\s*$' 390 elseif getline('.') =~# '^\s*\%(require \|load \|autoload :\w\+,\)\s*\(["'']\).*\1\s*$'
383 let cfile = matchstr(getline('.'),'\(["'']\)\zs.\{-\}\ze\1') . ext 391 let cfile = matchstr(getline('.'),'\(["'']\)\zs.\{-\}\ze\1')
392 let cfile .= cfile !~# '\.rb$' ? '.rb' : ''
384 elseif pre.post =~# '\<File.expand_path[( ].*[''"]\{2\}, *__FILE__\>' && cfile =~# '^\.\.' 393 elseif pre.post =~# '\<File.expand_path[( ].*[''"]\{2\}, *__FILE__\>' && cfile =~# '^\.\.'
385 let cfile = expand('%:p:h') . strpart(cfile, 2) 394 let cfile = expand('%:p:h') . strpart(cfile, 2)
386 else 395 else
387 return substitute(cfile, '\C\v^(.*):(\d+)%(:in)=$', '+\2 \1', '') 396 return substitute(cfile, '\C\v^(.*):(\d+)%(:in)=$', '+\2 \1', '')
388 endif 397 endif