Mercurial > vim
comparison runtime/ftplugin/ruby.vim @ 10048:43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Aug 30 23:26:57 2016 +0200
Updated runtime files. Remove version checks for Vim older than 6.0.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 30 Aug 2016 23:30:09 +0200 |
parents | a5352e73dc00 |
children | f0f06837a699 |
comparison
equal
deleted
inserted
replaced
10047:a62862410ca1 | 10048:43efa4f5a8ea |
---|---|
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 \ ',{:},\[:\],(:)' |
33 | 33 |
34 let b:match_skip = | 34 let b:match_skip = |
35 \ "synIDattr(synID(line('.'),col('.'),0),'name') =~ '" . | 35 \ "synIDattr(synID(line('.'),col('.'),0),'name') =~ '" . |
36 \ "\\<ruby\\%(String\\|StringDelimiter\\|ASCIICode\\|Escape\\|" . | 36 \ "\\<ruby\\%(String\\|StringDelimiter\\|ASCIICode\\|Escape\\|" . |
37 \ "Regexp\\|RegexpDelimiter\\|" . | |
37 \ "Interpolation\\|NoInterpolation\\|Comment\\|Documentation\\|" . | 38 \ "Interpolation\\|NoInterpolation\\|Comment\\|Documentation\\|" . |
38 \ "ConditionalModifier\\|RepeatModifier\\|OptionalDo\\|" . | 39 \ "ConditionalModifier\\|RepeatModifier\\|OptionalDo\\|" . |
39 \ "Function\\|BlockArgument\\|KeywordAsMethod\\|ClassVariable\\|" . | 40 \ "Function\\|BlockArgument\\|KeywordAsMethod\\|ClassVariable\\|" . |
40 \ "InstanceVariable\\|GlobalVariable\\|Symbol\\)\\>'" | 41 \ "InstanceVariable\\|GlobalVariable\\|Symbol\\)\\>'" |
41 endif | 42 endif |
42 | 43 |
43 setlocal formatoptions-=t formatoptions+=croql | 44 setlocal formatoptions-=t formatoptions+=croql |
44 | 45 |
45 setlocal include=^\\s*\\<\\(load\\>\\\|require\\>\\\|autoload\\s*:\\=[\"']\\=\\h\\w*[\"']\\=,\\) | 46 setlocal include=^\\s*\\<\\(load\\>\\\|require\\>\\\|autoload\\s*:\\=[\"']\\=\\h\\w*[\"']\\=,\\) |
46 setlocal includeexpr=substitute(substitute(v:fname,'::','/','g'),'$','.rb','') | 47 setlocal includeexpr=substitute(substitute(v:fname,'::','/','g'),'\%(\.rb\)\=$','.rb','') |
47 setlocal suffixesadd=.rb | 48 setlocal suffixesadd=.rb |
48 | 49 |
49 if exists("&ofu") && has("ruby") | 50 if exists("&ofu") && has("ruby") |
50 setlocal omnifunc=rubycomplete#Complete | 51 setlocal omnifunc=rubycomplete#Complete |
51 endif | 52 endif |
64 | 65 |
65 if !exists('g:ruby_version_paths') | 66 if !exists('g:ruby_version_paths') |
66 let g:ruby_version_paths = {} | 67 let g:ruby_version_paths = {} |
67 endif | 68 endif |
68 | 69 |
69 function! s:query_path(root) | 70 function! s:query_path(root) abort |
70 let code = "print $:.join %q{,}" | 71 let code = "print $:.join %q{,}" |
71 if &shell =~# 'sh' && $PATH !~# '\s' | 72 if &shell =~# 'sh' |
72 let prefix = 'env PATH='.$PATH.' ' | 73 let prefix = 'env PATH='.shellescape($PATH).' ' |
73 else | 74 else |
74 let prefix = '' | 75 let prefix = '' |
75 endif | 76 endif |
76 if &shellxquote == "'" | 77 if &shellxquote == "'" |
77 let path_check = prefix.'ruby -e "' . code . '"' | 78 let path_check = prefix.'ruby --disable-gems -e "' . code . '"' |
78 else | 79 else |
79 let path_check = prefix."ruby -e '" . code . "'" | 80 let path_check = prefix."ruby --disable-gems -e '" . code . "'" |
80 endif | 81 endif |
81 | 82 |
82 let cd = haslocaldir() ? 'lcd' : 'cd' | 83 let cd = haslocaldir() ? 'lcd' : 'cd' |
83 let cwd = getcwd() | 84 let cwd = fnameescape(getcwd()) |
84 try | 85 try |
85 exe cd fnameescape(a:root) | 86 exe cd fnameescape(a:root) |
86 let path = split(system(path_check),',') | 87 let path = split(system(path_check),',') |
87 exe cd fnameescape(cwd) | 88 exe cd cwd |
88 return path | 89 return path |
89 finally | 90 finally |
90 exe cd fnameescape(cwd) | 91 exe cd cwd |
91 endtry | 92 endtry |
92 endfunction | 93 endfunction |
93 | 94 |
94 function! s:build_path(path) | 95 function! s:build_path(path) abort |
95 let path = join(map(copy(a:path), 'v:val ==# "." ? "" : v:val'), ',') | 96 let path = join(map(copy(a:path), 'v:val ==# "." ? "" : v:val'), ',') |
96 if &g:path !~# '\v^\.%(,/%(usr|emx)/include)=,,$' | 97 if &g:path !~# '\v^\.%(,/%(usr|emx)/include)=,,$' |
97 let path = substitute(&g:path,',,$',',','') . ',' . path | 98 let path = substitute(&g:path,',,$',',','') . ',' . path |
98 endif | 99 endif |
99 return path | 100 return path |
100 endfunction | 101 endfunction |
101 | 102 |
102 if !exists('b:ruby_version') && !exists('g:ruby_path') && isdirectory(expand('%:p:h')) | 103 if !exists('b:ruby_version') && !exists('g:ruby_path') && isdirectory(expand('%:p:h')) |
103 let s:version_file = findfile('.ruby-version', '.;') | 104 let s:version_file = findfile('.ruby-version', '.;') |
104 if !empty(s:version_file) | 105 if !empty(s:version_file) && filereadable(s:version_file) |
105 let b:ruby_version = get(readfile(s:version_file, '', 1), '') | 106 let b:ruby_version = get(readfile(s:version_file, '', 1), '') |
106 if !has_key(g:ruby_version_paths, b:ruby_version) | 107 if !has_key(g:ruby_version_paths, b:ruby_version) |
107 let g:ruby_version_paths[b:ruby_version] = s:query_path(fnamemodify(s:version_file, ':p:h')) | 108 let g:ruby_version_paths[b:ruby_version] = s:query_path(fnamemodify(s:version_file, ':p:h')) |
108 endif | 109 endif |
109 endif | 110 endif |
133 endif | 134 endif |
134 if exists('s:ruby_paths') && stridx(&l:tags, join(map(copy(s:ruby_paths),'v:val."/tags"'),',')) == -1 | 135 if exists('s:ruby_paths') && stridx(&l:tags, join(map(copy(s:ruby_paths),'v:val."/tags"'),',')) == -1 |
135 let &l:tags = &tags . ',' . join(map(copy(s:ruby_paths),'v:val."/tags"'),',') | 136 let &l:tags = &tags . ',' . join(map(copy(s:ruby_paths),'v:val."/tags"'),',') |
136 endif | 137 endif |
137 | 138 |
138 if has("gui_win32") && !exists("b:browsefilter") | 139 if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter") |
139 let b:browsefilter = "Ruby Source Files (*.rb)\t*.rb\n" . | 140 let b:browsefilter = "Ruby Source Files (*.rb)\t*.rb\n" . |
140 \ "All Files (*.*)\t*.*\n" | 141 \ "All Files (*.*)\t*.*\n" |
141 endif | 142 endif |
142 | 143 |
143 let b:undo_ftplugin = "setl fo< inc< inex< sua< def< com< cms< path< tags< kp<" | 144 let b:undo_ftplugin = "setl fo< inc< inex< sua< def< com< cms< path< tags< kp<" |
144 \."| unlet! b:browsefilter b:match_ignorecase b:match_words b:match_skip" | 145 \."| unlet! b:browsefilter b:match_ignorecase b:match_words b:match_skip" |
145 \."| if exists('&ofu') && has('ruby') | setl ofu< | endif" | 146 \."| if exists('&ofu') && has('ruby') | setl ofu< | endif" |
146 \."| if has('balloon_eval') && exists('+bexpr') | setl bexpr< | endif" | 147 \."| if has('balloon_eval') && exists('+bexpr') | setl bexpr< | endif" |
147 | 148 |
149 function! s:map(mode, flags, map) abort | |
150 let from = matchstr(a:map, '\S\+') | |
151 if empty(mapcheck(from, a:mode)) | |
152 exe a:mode.'map' '<buffer>'.(a:0 ? a:1 : '') a:map | |
153 let b:undo_ftplugin .= '|sil! '.a:mode.'unmap <buffer> '.from | |
154 endif | |
155 endfunction | |
156 | |
157 cmap <buffer><script><expr> <Plug><cword> substitute(RubyCursorIdentifier(),'^$',"\022\027",'') | |
158 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>" | |
160 | |
148 if !exists("g:no_plugin_maps") && !exists("g:no_ruby_maps") | 161 if !exists("g:no_plugin_maps") && !exists("g:no_ruby_maps") |
162 nmap <buffer><script> <SID>: :<C-U> | |
163 nmap <buffer><script> <SID>c: :<C-U><C-R>=v:count ? v:count : ''<CR> | |
164 | |
149 nnoremap <silent> <buffer> [m :<C-U>call <SID>searchsyn('\<def\>','rubyDefine','b','n')<CR> | 165 nnoremap <silent> <buffer> [m :<C-U>call <SID>searchsyn('\<def\>','rubyDefine','b','n')<CR> |
150 nnoremap <silent> <buffer> ]m :<C-U>call <SID>searchsyn('\<def\>','rubyDefine','','n')<CR> | 166 nnoremap <silent> <buffer> ]m :<C-U>call <SID>searchsyn('\<def\>','rubyDefine','','n')<CR> |
151 nnoremap <silent> <buffer> [M :<C-U>call <SID>searchsyn('\<end\>','rubyDefine','b','n')<CR> | 167 nnoremap <silent> <buffer> [M :<C-U>call <SID>searchsyn('\<end\>','rubyDefine','b','n')<CR> |
152 nnoremap <silent> <buffer> ]M :<C-U>call <SID>searchsyn('\<end\>','rubyDefine','','n')<CR> | 168 nnoremap <silent> <buffer> ]M :<C-U>call <SID>searchsyn('\<end\>','rubyDefine','','n')<CR> |
153 xnoremap <silent> <buffer> [m :<C-U>call <SID>searchsyn('\<def\>','rubyDefine','b','v')<CR> | 169 xnoremap <silent> <buffer> [m :<C-U>call <SID>searchsyn('\<def\>','rubyDefine','b','v')<CR> |
166 | 182 |
167 let b:undo_ftplugin = b:undo_ftplugin | 183 let b:undo_ftplugin = b:undo_ftplugin |
168 \."| sil! exe 'unmap <buffer> [[' | sil! exe 'unmap <buffer> ]]' | sil! exe 'unmap <buffer> []' | sil! exe 'unmap <buffer> ]['" | 184 \."| sil! exe 'unmap <buffer> [[' | sil! exe 'unmap <buffer> ]]' | sil! exe 'unmap <buffer> []' | sil! exe 'unmap <buffer> ]['" |
169 \."| sil! exe 'unmap <buffer> [m' | sil! exe 'unmap <buffer> ]m' | sil! exe 'unmap <buffer> [M' | sil! exe 'unmap <buffer> ]M'" | 185 \."| sil! exe 'unmap <buffer> [m' | sil! exe 'unmap <buffer> ]m' | sil! exe 'unmap <buffer> [M' | sil! exe 'unmap <buffer> ]M'" |
170 | 186 |
171 if maparg('im','n') == '' | 187 if maparg('im','x') == '' && maparg('im','o') == '' && maparg('am','x') == '' && maparg('am','o') == '' |
172 onoremap <silent> <buffer> im :<C-U>call <SID>wrap_i('[m',']M')<CR> | 188 onoremap <silent> <buffer> im :<C-U>call <SID>wrap_i('[m',']M')<CR> |
173 onoremap <silent> <buffer> am :<C-U>call <SID>wrap_a('[m',']M')<CR> | 189 onoremap <silent> <buffer> am :<C-U>call <SID>wrap_a('[m',']M')<CR> |
174 xnoremap <silent> <buffer> im :<C-U>call <SID>wrap_i('[m',']M')<CR> | 190 xnoremap <silent> <buffer> im :<C-U>call <SID>wrap_i('[m',']M')<CR> |
175 xnoremap <silent> <buffer> am :<C-U>call <SID>wrap_a('[m',']M')<CR> | 191 xnoremap <silent> <buffer> am :<C-U>call <SID>wrap_a('[m',']M')<CR> |
176 let b:undo_ftplugin = b:undo_ftplugin | 192 let b:undo_ftplugin = b:undo_ftplugin |
177 \."| sil! exe 'ounmap <buffer> im' | sil! exe 'ounmap <buffer> am'" | 193 \."| sil! exe 'ounmap <buffer> im' | sil! exe 'ounmap <buffer> am'" |
178 \."| sil! exe 'xunmap <buffer> im' | sil! exe 'xunmap <buffer> am'" | 194 \."| sil! exe 'xunmap <buffer> im' | sil! exe 'xunmap <buffer> am'" |
179 endif | 195 endif |
180 | 196 |
181 if maparg('iM','n') == '' | 197 if maparg('iM','x') == '' && maparg('iM','o') == '' && maparg('aM','x') == '' && maparg('aM','o') == '' |
182 onoremap <silent> <buffer> iM :<C-U>call <SID>wrap_i('[[','][')<CR> | 198 onoremap <silent> <buffer> iM :<C-U>call <SID>wrap_i('[[','][')<CR> |
183 onoremap <silent> <buffer> aM :<C-U>call <SID>wrap_a('[[','][')<CR> | 199 onoremap <silent> <buffer> aM :<C-U>call <SID>wrap_a('[[','][')<CR> |
184 xnoremap <silent> <buffer> iM :<C-U>call <SID>wrap_i('[[','][')<CR> | 200 xnoremap <silent> <buffer> iM :<C-U>call <SID>wrap_i('[[','][')<CR> |
185 xnoremap <silent> <buffer> aM :<C-U>call <SID>wrap_a('[[','][')<CR> | 201 xnoremap <silent> <buffer> aM :<C-U>call <SID>wrap_a('[[','][')<CR> |
186 let b:undo_ftplugin = b:undo_ftplugin | 202 let b:undo_ftplugin = b:undo_ftplugin |
187 \."| sil! exe 'ounmap <buffer> iM' | sil! exe 'ounmap <buffer> aM'" | 203 \."| sil! exe 'ounmap <buffer> iM' | sil! exe 'ounmap <buffer> aM'" |
188 \."| sil! exe 'xunmap <buffer> iM' | sil! exe 'xunmap <buffer> aM'" | 204 \."| sil! exe 'xunmap <buffer> iM' | sil! exe 'xunmap <buffer> aM'" |
189 endif | 205 endif |
190 | 206 |
191 if maparg("\<C-]>",'n') == '' | 207 call s:map('c', '', '<C-R><C-W> <Plug><cword>') |
192 nnoremap <silent> <buffer> <C-]> :<C-U>exe v:count1."tag <C-R>=RubyCursorIdentifier()<CR>"<CR> | 208 call s:map('c', '', '<C-R><C-F> <Plug><cfile>') |
193 nnoremap <silent> <buffer> g<C-]> :<C-U>exe "tjump <C-R>=RubyCursorIdentifier()<CR>"<CR> | 209 |
194 nnoremap <silent> <buffer> g] :<C-U>exe "tselect <C-R>=RubyCursorIdentifier()<CR>"<CR> | 210 cmap <buffer><script><expr> <SID>tagzv &foldopen =~# 'tag' ? '<Bar>norm! zv' : '' |
195 nnoremap <silent> <buffer> <C-W>] :<C-U>exe v:count1."stag <C-R>=RubyCursorIdentifier()<CR>"<CR> | 211 call s:map('n', '<silent>', '<C-]> <SID>:exe v:count1."tag <Plug><cword>"<SID>tagzv<CR>') |
196 nnoremap <silent> <buffer> <C-W><C-]> :<C-U>exe v:count1."stag <C-R>=RubyCursorIdentifier()<CR>"<CR> | 212 call s:map('n', '<silent>', 'g<C-]> <SID>:exe "tjump <Plug><cword>"<SID>tagzv<CR>') |
197 nnoremap <silent> <buffer> <C-W>g<C-]> :<C-U>exe "stjump <C-R>=RubyCursorIdentifier()<CR>"<CR> | 213 call s:map('n', '<silent>', 'g] <SID>:exe "tselect <Plug><cword>"<SID>tagzv<CR>') |
198 nnoremap <silent> <buffer> <C-W>g] :<C-U>exe "stselect <C-R>=RubyCursorIdentifier()<CR>"<CR> | 214 call s:map('n', '<silent>', '<C-W>] <SID>:exe v:count1."stag <Plug><cword>"<SID>tagzv<CR>') |
199 nnoremap <silent> <buffer> <C-W>} :<C-U>exe "ptag <C-R>=RubyCursorIdentifier()<CR>"<CR> | 215 call s:map('n', '<silent>', '<C-W><C-]> <SID>:exe v:count1."stag <Plug><cword>"<SID>tagzv<CR>') |
200 nnoremap <silent> <buffer> <C-W>g} :<C-U>exe "ptjump <C-R>=RubyCursorIdentifier()<CR>"<CR> | 216 call s:map('n', '<silent>', '<C-W>g<C-]> <SID>:exe "stjump <Plug><cword>"<SID>tagzv<CR>') |
201 let b:undo_ftplugin = b:undo_ftplugin | 217 call s:map('n', '<silent>', '<C-W>g] <SID>:exe "stselect <Plug><cword>"<SID>tagzv<CR>') |
202 \."| sil! exe 'nunmap <buffer> <C-]>'| sil! exe 'nunmap <buffer> g<C-]>'| sil! exe 'nunmap <buffer> g]'" | 218 call s:map('n', '<silent>', '<C-W>} <SID>:exe v:count1."ptag <Plug><cword>"<CR>') |
203 \."| sil! exe 'nunmap <buffer> <C-W>]'| sil! exe 'nunmap <buffer> <C-W><C-]>'" | 219 call s:map('n', '<silent>', '<C-W>g} <SID>:exe "ptjump <Plug><cword>"<CR>') |
204 \."| sil! exe 'nunmap <buffer> <C-W>g<C-]>'| sil! exe 'nunmap <buffer> <C-W>g]'" | 220 |
205 \."| sil! exe 'nunmap <buffer> <C-W>}'| sil! exe 'nunmap <buffer> <C-W>g}'" | 221 call s:map('n', '<silent>', 'gf <SID>c:find <Plug><cfile><CR>') |
206 endif | 222 call s:map('n', '<silent>', '<C-W>f <SID>c:sfind <Plug><cfile><CR>') |
207 | 223 call s:map('n', '<silent>', '<C-W><C-F> <SID>c:sfind <Plug><cfile><CR>') |
208 if maparg("gf",'n') == '' | 224 call s:map('n', '<silent>', '<C-W>gf <SID>c:tabfind <Plug><cfile><CR>') |
209 " By using findfile() rather than gf's normal behavior, we prevent | |
210 " erroneously editing a directory. | |
211 nnoremap <silent> <buffer> gf :<C-U>exe <SID>gf(v:count1,"gf",'edit')<CR> | |
212 nnoremap <silent> <buffer> <C-W>f :<C-U>exe <SID>gf(v:count1,"\<Lt>C-W>f",'split')<CR> | |
213 nnoremap <silent> <buffer> <C-W><C-F> :<C-U>exe <SID>gf(v:count1,"\<Lt>C-W>\<Lt>C-F>",'split')<CR> | |
214 nnoremap <silent> <buffer> <C-W>gf :<C-U>exe <SID>gf(v:count1,"\<Lt>C-W>gf",'tabedit')<CR> | |
215 let b:undo_ftplugin = b:undo_ftplugin | |
216 \."| sil! exe 'nunmap <buffer> gf' | sil! exe 'nunmap <buffer> <C-W>f' | sil! exe 'nunmap <buffer> <C-W><C-F>' | sil! exe 'nunmap <buffer> <C-W>gf'" | |
217 endif | |
218 endif | 225 endif |
219 | 226 |
220 let &cpo = s:cpo_save | 227 let &cpo = s:cpo_save |
221 unlet s:cpo_save | 228 unlet s:cpo_save |
222 | 229 |
223 if exists("g:did_ruby_ftplugin_functions") | 230 if exists("g:did_ruby_ftplugin_functions") |
224 finish | 231 finish |
225 endif | 232 endif |
226 let g:did_ruby_ftplugin_functions = 1 | 233 let g:did_ruby_ftplugin_functions = 1 |
227 | 234 |
228 function! RubyBalloonexpr() | 235 function! RubyBalloonexpr() abort |
229 if !exists('s:ri_found') | 236 if !exists('s:ri_found') |
230 let s:ri_found = executable('ri') | 237 let s:ri_found = executable('ri') |
231 endif | 238 endif |
232 if s:ri_found | 239 if s:ri_found |
233 let line = getline(v:beval_lnum) | 240 let line = getline(v:beval_lnum) |
272 else | 279 else |
273 return "" | 280 return "" |
274 endif | 281 endif |
275 endfunction | 282 endfunction |
276 | 283 |
277 function! s:searchsyn(pattern,syn,flags,mode) | 284 function! s:searchsyn(pattern, syn, flags, mode) abort |
285 let cnt = v:count1 | |
278 norm! m' | 286 norm! m' |
279 if a:mode ==# 'v' | 287 if a:mode ==# 'v' |
280 norm! gv | 288 norm! gv |
281 endif | 289 endif |
282 let i = 0 | 290 let i = 0 |
283 let cnt = v:count ? v:count : 1 | |
284 while i < cnt | 291 while i < cnt |
285 let i = i + 1 | 292 let i = i + 1 |
286 let line = line('.') | 293 let line = line('.') |
287 let col = col('.') | 294 let col = col('.') |
288 let pos = search(a:pattern,'W'.a:flags) | 295 let pos = search(a:pattern,'W'.a:flags) |
294 return | 301 return |
295 endif | 302 endif |
296 endwhile | 303 endwhile |
297 endfunction | 304 endfunction |
298 | 305 |
299 function! s:synname() | 306 function! s:synname() abort |
300 return synIDattr(synID(line('.'),col('.'),0),'name') | 307 return synIDattr(synID(line('.'),col('.'),0),'name') |
301 endfunction | 308 endfunction |
302 | 309 |
303 function! s:wrap_i(back,forward) | 310 function! s:wrap_i(back,forward) abort |
304 execute 'norm k'.a:forward | 311 execute 'norm k'.a:forward |
305 let line = line('.') | 312 let line = line('.') |
306 execute 'norm '.a:back | 313 execute 'norm '.a:back |
307 if line('.') == line - 1 | 314 if line('.') == line - 1 |
308 return s:wrap_a(a:back,a:forward) | 315 return s:wrap_a(a:back,a:forward) |
309 endif | 316 endif |
310 execute 'norm jV'.a:forward.'k' | 317 execute 'norm jV'.a:forward.'k' |
311 endfunction | 318 endfunction |
312 | 319 |
313 function! s:wrap_a(back,forward) | 320 function! s:wrap_a(back,forward) abort |
314 execute 'norm '.a:forward | 321 execute 'norm '.a:forward |
315 if line('.') < line('$') && getline(line('.')+1) ==# '' | 322 if line('.') < line('$') && getline(line('.')+1) ==# '' |
316 let after = 1 | 323 let after = 1 |
317 endif | 324 endif |
318 execute 'norm '.a:back | 325 execute 'norm '.a:back |
326 else | 333 else |
327 execute 'norm V'.a:forward | 334 execute 'norm V'.a:forward |
328 endif | 335 endif |
329 endfunction | 336 endfunction |
330 | 337 |
331 function! RubyCursorIdentifier() | 338 function! RubyCursorIdentifier() abort |
332 let asciicode = '\%(\w\|[]})\"'."'".']\)\@<!\%(?\%(\\M-\\C-\|\\C-\\M-\|\\M-\\c\|\\c\\M-\|\\c\|\\C-\|\\M-\)\=\%(\\\o\{1,3}\|\\x\x\{1,2}\|\\\=\S\)\)' | 339 let asciicode = '\%(\w\|[]})\"'."'".']\)\@<!\%(?\%(\\M-\\C-\|\\C-\\M-\|\\M-\\c\|\\c\\M-\|\\c\|\\C-\|\\M-\)\=\%(\\\o\{1,3}\|\\x\x\{1,2}\|\\\=\S\)\)' |
333 let number = '\%(\%(\w\|[]})\"'."'".']\s*\)\@<!-\)\=\%(\<[[:digit:]_]\+\%(\.[[:digit:]_]\+\)\=\%([Ee][[:digit:]_]\+\)\=\>\|\<0[xXbBoOdD][[:xdigit:]_]\+\>\)\|'.asciicode | 340 let number = '\%(\%(\w\|[]})\"'."'".']\s*\)\@<!-\)\=\%(\<[[:digit:]_]\+\%(\.[[:digit:]_]\+\)\=\%([Ee][[:digit:]_]\+\)\=\>\|\<0[xXbBoOdD][[:xdigit:]_]\+\>\)\|'.asciicode |
334 let operator = '\%(\[\]\|<<\|<=>\|[!<>]=\=\|===\=\|[!=]\~\|>>\|\*\*\|\.\.\.\=\|=>\|[~^&|*/%+-]\)' | 341 let operator = '\%(\[\]\|<<\|<=>\|[!<>]=\=\|===\=\|[!=]\~\|>>\|\*\*\|\.\.\.\=\|=>\|[~^&|*/%+-]\)' |
335 let method = '\%(\<[_a-zA-Z]\w*\>\%([?!]\|\s*=>\@!\)\=\)' | 342 let method = '\%(\.[_a-zA-Z]\w*\s*=>\@!\|\<[_a-zA-Z]\w*\>[?!]\=\)' |
336 let global = '$\%([!$&"'."'".'*+,./:;<=>?@\`~]\|-\=\w\+\>\)' | 343 let global = '$\%([!$&"'."'".'*+,./:;<=>?@\`~]\|-\=\w\+\>\)' |
337 let symbolizable = '\%(\%(@@\=\)\w\+\>\|'.global.'\|'.method.'\|'.operator.'\)' | 344 let symbolizable = '\%(\%(@@\=\)\w\+\>\|'.global.'\|'.method.'\|'.operator.'\)' |
338 let pattern = '\C\s*\%('.number.'\|\%(:\@<!:\)\='.symbolizable.'\)' | 345 let pattern = '\C\s*\%('.number.'\|\%(:\@<!:\)\='.symbolizable.'\)' |
339 let [lnum, col] = searchpos(pattern,'bcn',line('.')) | 346 let [lnum, col] = searchpos(pattern,'bcn',line('.')) |
340 let raw = matchstr(getline('.')[col-1 : ],pattern) | 347 let raw = matchstr(getline('.')[col-1 : ],pattern) |
341 let stripped = substitute(substitute(raw,'\s\+=$','=',''),'^\s*:\=','','') | 348 let stripped = substitute(substitute(raw,'\s\+=$','=',''),'^\s*[:.]\=','','') |
342 return stripped == '' ? expand("<cword>") : stripped | 349 return stripped == '' ? expand("<cword>") : stripped |
343 endfunction | 350 endfunction |
344 | 351 |
345 function! s:gf(count,map,edit) abort | 352 function! RubyCursorFile() abort |
346 if getline('.') =~# '^\s*require_relative\s*\(["'']\).*\1\s*$' | 353 let isfname = &isfname |
347 let target = matchstr(getline('.'),'\(["'']\)\zs.\{-\}\ze\1') | 354 try |
348 return a:edit.' %:h/'.target.'.rb' | 355 set isfname+=: |
349 elseif getline('.') =~# '^\s*\%(require[( ]\|load[( ]\|autoload[( ]:\w\+,\)\s*\s*\%(::\)\=File\.expand_path(\(["'']\)\.\./.*\1,\s*__FILE__)\s*$' | 356 let cfile = expand('<cfile>') |
350 let target = matchstr(getline('.'),'\(["'']\)\.\./\zs.\{-\}\ze\1') | 357 finally |
351 return a:edit.' %:h/'.target.'.rb' | 358 let isfname = &isfname |
359 endtry | |
360 let pre = matchstr(strpart(getline('.'), 0, col('.')-1), '.*\f\@<!') | |
361 let post = matchstr(strpart(getline('.'), col('.')), '\f\@!.*') | |
362 let ext = getline('.') =~# '^\s*\%(require\%(_relative\)\=\|autoload\)\>' && cfile !~# '\.rb$' ? '.rb' : '' | |
363 if s:synname() ==# 'rubyConstant' | |
364 let cfile = substitute(cfile,'\.\w\+[?!=]\=$','','') | |
365 let cfile = substitute(cfile,'::','/','g') | |
366 let cfile = substitute(cfile,'\(\u\+\)\(\u\l\)','\1_\2', 'g') | |
367 let cfile = substitute(cfile,'\(\l\|\d\)\(\u\)','\1_\2', 'g') | |
368 return tolower(cfile) . '.rb' | |
369 elseif getline('.') =~# '^\s*require_relative\s*\(["'']\).*\1\s*$' | |
370 let cfile = expand('%:p:h') . '/' . matchstr(getline('.'),'\(["'']\)\zs.\{-\}\ze\1') . ext | |
371 elseif getline('.') =~# '^\s*\%(require[( ]\|load[( ]\|autoload[( ]:\w\+,\)\s*\%(::\)\=File\.expand_path(\(["'']\)\.\./.*\1,\s*__FILE__)\s*$' | |
372 let target = matchstr(getline('.'),'\(["'']\)\.\.\zs/.\{-\}\ze\1') | |
373 let cfile = expand('%:p:h') . target . ext | |
352 elseif getline('.') =~# '^\s*\%(require \|load \|autoload :\w\+,\)\s*\(["'']\).*\1\s*$' | 374 elseif getline('.') =~# '^\s*\%(require \|load \|autoload :\w\+,\)\s*\(["'']\).*\1\s*$' |
353 let target = matchstr(getline('.'),'\(["'']\)\zs.\{-\}\ze\1') | 375 let cfile = matchstr(getline('.'),'\(["'']\)\zs.\{-\}\ze\1') . ext |
354 else | 376 elseif pre.post =~# '\<File.expand_path[( ].*[''"]\{2\}, *__FILE__\>' && cfile =~# '^\.\.' |
355 let target = expand('<cfile>') | 377 let cfile = expand('%:p:h') . strpart(cfile, 2) |
356 endif | 378 else |
357 let found = findfile(target, &path, a:count) | 379 return substitute(cfile, '\C\v^(.*):(\d+)%(:in)=$', '+\2 \1', '') |
358 if found ==# '' | 380 endif |
359 return 'norm! '.a:count.a:map | 381 let cwdpat = '^\M' . substitute(getcwd(), '[\/]', '\\[\\/]', 'g').'\ze\[\/]' |
360 else | 382 let cfile = substitute(cfile, cwdpat, '.', '') |
361 return a:edit.' '.fnameescape(found) | 383 if fnameescape(cfile) !=# cfile |
384 return '+ '.fnameescape(cfile) | |
385 else | |
386 return cfile | |
362 endif | 387 endif |
363 endfunction | 388 endfunction |
364 | 389 |
365 " | 390 " |
366 " Instructions for enabling "matchit" support: | 391 " Instructions for enabling "matchit" support: |