Mercurial > vim
annotate runtime/ftplugin/ruby.vim @ 21005:3f0abea9bed2
Added tag v8.2.1053 for changeset 0650d220f7422f96aed6270c055ad7e7a357af28
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 25 Jun 2020 19:15:26 +0200 |
parents | 70ce979e76bc |
children | 43593a5d873f |
rev | line source |
---|---|
7 | 1 " Vim filetype plugin |
831 | 2 " Language: Ruby |
4869 | 3 " Maintainer: Tim Pope <vimNOSPAM@tpope.org> |
4 " URL: https://github.com/vim-ruby/vim-ruby | |
15512 | 5 " Release Coordinator: Doug Kearns <dougkearns@gmail.com> |
18857
70ce979e76bc
Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
15512
diff
changeset
|
6 " Last Change: 2019 Nov 06 |
7 | 7 |
8 if (exists("b:did_ftplugin")) | |
530 | 9 finish |
7 | 10 endif |
11 let b:did_ftplugin = 1 | |
12 | |
530 | 13 let s:cpo_save = &cpo |
14 set cpo&vim | |
15 | |
1123 | 16 if has("gui_running") && !has("gui_win32") |
4869 | 17 setlocal keywordprg=ri\ -T\ -f\ bs |
1123 | 18 else |
19 setlocal keywordprg=ri | |
20 endif | |
21 | |
530 | 22 " Matchit support |
23 if exists("loaded_matchit") && !exists("b:match_words") | |
24 let b:match_ignorecase = 0 | |
25 | |
1123 | 26 let b:match_words = |
18857
70ce979e76bc
Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
15512
diff
changeset
|
27 \ '{\|\<\%(if\|unless\|case\|while\|until\|for\|do\|class\|module\|def\|=\@<!begin\)\>=\@!' . |
1123 | 28 \ ':' . |
1215 | 29 \ '\<\%(else\|elsif\|ensure\|when\|rescue\|break\|redo\|next\|retry\)\>' . |
1123 | 30 \ ':' . |
18857
70ce979e76bc
Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
15512
diff
changeset
|
31 \ '}\|\%(^\|[^.\:@$=]\)\@<=\<end\:\@!\>' . |
70ce979e76bc
Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
15512
diff
changeset
|
32 \ ',^=begin\>:^=end\>,' . |
70ce979e76bc
Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
15512
diff
changeset
|
33 \ ',\[:\],(:)' |
530 | 34 |
35 let b:match_skip = | |
1123 | 36 \ "synIDattr(synID(line('.'),col('.'),0),'name') =~ '" . |
18857
70ce979e76bc
Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
15512
diff
changeset
|
37 \ "\\<ruby\\%(String\\|.\+Delimiter\\|Character\\|.\+Escape\\|" . |
70ce979e76bc
Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
15512
diff
changeset
|
38 \ "Regexp\\|Interpolation\\|Comment\\|Documentation\\|" . |
70ce979e76bc
Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
15512
diff
changeset
|
39 \ "ConditionalModifier\\|RepeatModifier\\|RescueModifier\\|OptionalDo\\|" . |
70ce979e76bc
Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
15512
diff
changeset
|
40 \ "MethodName\\|BlockArgument\\|KeywordAsMethod\\|ClassVariable\\|" . |
1215 | 41 \ "InstanceVariable\\|GlobalVariable\\|Symbol\\)\\>'" |
530 | 42 endif |
43 | |
44 setlocal formatoptions-=t formatoptions+=croql | |
45 | |
4869 | 46 setlocal include=^\\s*\\<\\(load\\>\\\|require\\>\\\|autoload\\s*:\\=[\"']\\=\\h\\w*[\"']\\=,\\) |
530 | 47 setlocal suffixesadd=.rb |
831 | 48 |
1123 | 49 if exists("&ofu") && has("ruby") |
831 | 50 setlocal omnifunc=rubycomplete#Complete |
51 endif | |
530 | 52 |
53 " TODO: | |
54 "setlocal define=^\\s*def | |
55 | |
56 setlocal comments=:# | |
57 setlocal commentstring=#\ %s | |
58 | |
4869 | 59 if !exists('g:ruby_version_paths') |
60 let g:ruby_version_paths = {} | |
61 endif | |
62 | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
63 function! s:query_path(root) abort |
4869 | 64 let code = "print $:.join %q{,}" |
15512 | 65 if &shell =~# 'sh' && empty(&shellxquote) |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
66 let prefix = 'env PATH='.shellescape($PATH).' ' |
4869 | 67 else |
68 let prefix = '' | |
69 endif | |
70 if &shellxquote == "'" | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
71 let path_check = prefix.'ruby --disable-gems -e "' . code . '"' |
4869 | 72 else |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
73 let path_check = prefix."ruby --disable-gems -e '" . code . "'" |
4869 | 74 endif |
75 | |
76 let cd = haslocaldir() ? 'lcd' : 'cd' | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
77 let cwd = fnameescape(getcwd()) |
4869 | 78 try |
79 exe cd fnameescape(a:root) | |
80 let path = split(system(path_check),',') | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
81 exe cd cwd |
4869 | 82 return path |
83 finally | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
84 exe cd cwd |
4869 | 85 endtry |
86 endfunction | |
87 | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
88 function! s:build_path(path) abort |
4869 | 89 let path = join(map(copy(a:path), 'v:val ==# "." ? "" : v:val'), ',') |
18857
70ce979e76bc
Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
15512
diff
changeset
|
90 if &g:path !~# '\v^%(\.,)=%(/%(usr|emx)/include,)=,$' |
4869 | 91 let path = substitute(&g:path,',,$',',','') . ',' . path |
92 endif | |
93 return path | |
94 endfunction | |
95 | |
96 if !exists('b:ruby_version') && !exists('g:ruby_path') && isdirectory(expand('%:p:h')) | |
97 let s:version_file = findfile('.ruby-version', '.;') | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
98 if !empty(s:version_file) && filereadable(s:version_file) |
4869 | 99 let b:ruby_version = get(readfile(s:version_file, '', 1), '') |
100 if !has_key(g:ruby_version_paths, b:ruby_version) | |
101 let g:ruby_version_paths[b:ruby_version] = s:query_path(fnamemodify(s:version_file, ':p:h')) | |
530 | 102 endif |
103 endif | |
104 endif | |
105 | |
4869 | 106 if exists("g:ruby_path") |
107 let s:ruby_path = type(g:ruby_path) == type([]) ? join(g:ruby_path, ',') : g:ruby_path | |
108 elseif has_key(g:ruby_version_paths, get(b:, 'ruby_version', '')) | |
109 let s:ruby_paths = g:ruby_version_paths[b:ruby_version] | |
110 let s:ruby_path = s:build_path(s:ruby_paths) | |
111 else | |
112 if !exists('g:ruby_default_path') | |
113 if has("ruby") && has("win32") | |
114 ruby ::VIM::command( 'let g:ruby_default_path = split("%s",",")' % $:.join(%q{,}) ) | |
115 elseif executable('ruby') | |
116 let g:ruby_default_path = s:query_path($HOME) | |
117 else | |
118 let g:ruby_default_path = map(split($RUBYLIB,':'), 'v:val ==# "." ? "" : v:val') | |
119 endif | |
120 endif | |
121 let s:ruby_paths = g:ruby_default_path | |
122 let s:ruby_path = s:build_path(s:ruby_paths) | |
123 endif | |
124 | |
125 if stridx(&l:path, s:ruby_path) == -1 | |
126 let &l:path = s:ruby_path | |
127 endif | |
128 if exists('s:ruby_paths') && stridx(&l:tags, join(map(copy(s:ruby_paths),'v:val."/tags"'),',')) == -1 | |
129 let &l:tags = &tags . ',' . join(map(copy(s:ruby_paths),'v:val."/tags"'),',') | |
130 endif | |
530 | 131 |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
132 if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter") |
530 | 133 let b:browsefilter = "Ruby Source Files (*.rb)\t*.rb\n" . |
1123 | 134 \ "All Files (*.*)\t*.*\n" |
530 | 135 endif |
136 | |
15512 | 137 let b:undo_ftplugin = "setl inc= sua= path= tags= fo< com< cms< kp=" |
1215 | 138 \."| unlet! b:browsefilter b:match_ignorecase b:match_words b:match_skip" |
139 \."| if exists('&ofu') && has('ruby') | setl ofu< | endif" | |
15512 | 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 | |
1215 | 151 |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
152 function! s:map(mode, flags, map) abort |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
153 let from = matchstr(a:map, '\S\+') |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
154 if empty(mapcheck(from, a:mode)) |
18857
70ce979e76bc
Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
15512
diff
changeset
|
155 exe a:mode.'map' '<buffer>' a:flags a:map |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
156 let b:undo_ftplugin .= '|sil! '.a:mode.'unmap <buffer> '.from |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
157 endif |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
158 endfunction |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
159 |
15512 | 160 cmap <buffer><script><expr> <Plug><ctag> substitute(RubyCursorTag(),'^$',"\022\027",'') |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
161 cmap <buffer><script><expr> <Plug><cfile> substitute(RubyCursorFile(),'^$',"\022\006",'') |
15512 | 162 let b:undo_ftplugin .= "| sil! cunmap <buffer> <Plug><ctag>| sil! cunmap <buffer> <Plug><cfile>" |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
163 |
1215 | 164 if !exists("g:no_plugin_maps") && !exists("g:no_ruby_maps") |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
165 nmap <buffer><script> <SID>: :<C-U> |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
166 nmap <buffer><script> <SID>c: :<C-U><C-R>=v:count ? v:count : ''<CR> |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
167 |
15512 | 168 nnoremap <silent> <buffer> [m :<C-U>call <SID>searchsyn('\<def\>',['rubyDefine'],'b','n')<CR> |
169 nnoremap <silent> <buffer> ]m :<C-U>call <SID>searchsyn('\<def\>',['rubyDefine'],'','n')<CR> | |
170 nnoremap <silent> <buffer> [M :<C-U>call <SID>searchsyn('\<end\>',['rubyDefine'],'b','n')<CR> | |
171 nnoremap <silent> <buffer> ]M :<C-U>call <SID>searchsyn('\<end\>',['rubyDefine'],'','n')<CR> | |
172 xnoremap <silent> <buffer> [m :<C-U>call <SID>searchsyn('\<def\>',['rubyDefine'],'b','v')<CR> | |
173 xnoremap <silent> <buffer> ]m :<C-U>call <SID>searchsyn('\<def\>',['rubyDefine'],'','v')<CR> | |
174 xnoremap <silent> <buffer> [M :<C-U>call <SID>searchsyn('\<end\>',['rubyDefine'],'b','v')<CR> | |
175 xnoremap <silent> <buffer> ]M :<C-U>call <SID>searchsyn('\<end\>',['rubyDefine'],'','v')<CR> | |
1215 | 176 |
15512 | 177 nnoremap <silent> <buffer> [[ :<C-U>call <SID>searchsyn('\<\%(class\<Bar>module\)\>',['rubyModule','rubyClass'],'b','n')<CR> |
178 nnoremap <silent> <buffer> ]] :<C-U>call <SID>searchsyn('\<\%(class\<Bar>module\)\>',['rubyModule','rubyClass'],'','n')<CR> | |
179 nnoremap <silent> <buffer> [] :<C-U>call <SID>searchsyn('\<end\>',['rubyModule','rubyClass'],'b','n')<CR> | |
180 nnoremap <silent> <buffer> ][ :<C-U>call <SID>searchsyn('\<end\>',['rubyModule','rubyClass'],'','n')<CR> | |
181 xnoremap <silent> <buffer> [[ :<C-U>call <SID>searchsyn('\<\%(class\<Bar>module\)\>',['rubyModule','rubyClass'],'b','v')<CR> | |
182 xnoremap <silent> <buffer> ]] :<C-U>call <SID>searchsyn('\<\%(class\<Bar>module\)\>',['rubyModule','rubyClass'],'','v')<CR> | |
183 xnoremap <silent> <buffer> [] :<C-U>call <SID>searchsyn('\<end\>',['rubyModule','rubyClass'],'b','v')<CR> | |
184 xnoremap <silent> <buffer> ][ :<C-U>call <SID>searchsyn('\<end\>',['rubyModule','rubyClass'],'','v')<CR> | |
1215 | 185 |
186 let b:undo_ftplugin = b:undo_ftplugin | |
187 \."| sil! exe 'unmap <buffer> [[' | sil! exe 'unmap <buffer> ]]' | sil! exe 'unmap <buffer> []' | sil! exe 'unmap <buffer> ]['" | |
188 \."| sil! exe 'unmap <buffer> [m' | sil! exe 'unmap <buffer> ]m' | sil! exe 'unmap <buffer> [M' | sil! exe 'unmap <buffer> ]M'" | |
2225 | 189 |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
190 if maparg('im','x') == '' && maparg('im','o') == '' && maparg('am','x') == '' && maparg('am','o') == '' |
4869 | 191 onoremap <silent> <buffer> im :<C-U>call <SID>wrap_i('[m',']M')<CR> |
192 onoremap <silent> <buffer> am :<C-U>call <SID>wrap_a('[m',']M')<CR> | |
193 xnoremap <silent> <buffer> im :<C-U>call <SID>wrap_i('[m',']M')<CR> | |
194 xnoremap <silent> <buffer> am :<C-U>call <SID>wrap_a('[m',']M')<CR> | |
195 let b:undo_ftplugin = b:undo_ftplugin | |
196 \."| sil! exe 'ounmap <buffer> im' | sil! exe 'ounmap <buffer> am'" | |
197 \."| sil! exe 'xunmap <buffer> im' | sil! exe 'xunmap <buffer> am'" | |
198 endif | |
199 | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
200 if maparg('iM','x') == '' && maparg('iM','o') == '' && maparg('aM','x') == '' && maparg('aM','o') == '' |
4869 | 201 onoremap <silent> <buffer> iM :<C-U>call <SID>wrap_i('[[','][')<CR> |
202 onoremap <silent> <buffer> aM :<C-U>call <SID>wrap_a('[[','][')<CR> | |
203 xnoremap <silent> <buffer> iM :<C-U>call <SID>wrap_i('[[','][')<CR> | |
204 xnoremap <silent> <buffer> aM :<C-U>call <SID>wrap_a('[[','][')<CR> | |
205 let b:undo_ftplugin = b:undo_ftplugin | |
206 \."| sil! exe 'ounmap <buffer> iM' | sil! exe 'ounmap <buffer> aM'" | |
207 \."| sil! exe 'xunmap <buffer> iM' | sil! exe 'xunmap <buffer> aM'" | |
208 endif | |
209 | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
210 call s:map('c', '', '<C-R><C-F> <Plug><cfile>') |
4869 | 211 |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
212 cmap <buffer><script><expr> <SID>tagzv &foldopen =~# 'tag' ? '<Bar>norm! zv' : '' |
15512 | 213 call s:map('n', '<silent>', '<C-]> <SID>:exe v:count1."tag <Plug><ctag>"<SID>tagzv<CR>') |
214 call s:map('n', '<silent>', 'g<C-]> <SID>:exe "tjump <Plug><ctag>"<SID>tagzv<CR>') | |
215 call s:map('n', '<silent>', 'g] <SID>:exe "tselect <Plug><ctag>"<SID>tagzv<CR>') | |
216 call s:map('n', '<silent>', '<C-W>] <SID>:exe v:count1."stag <Plug><ctag>"<SID>tagzv<CR>') | |
217 call s:map('n', '<silent>', '<C-W><C-]> <SID>:exe v:count1."stag <Plug><ctag>"<SID>tagzv<CR>') | |
218 call s:map('n', '<silent>', '<C-W>g<C-]> <SID>:exe "stjump <Plug><ctag>"<SID>tagzv<CR>') | |
219 call s:map('n', '<silent>', '<C-W>g] <SID>:exe "stselect <Plug><ctag>"<SID>tagzv<CR>') | |
220 call s:map('n', '<silent>', '<C-W>} <SID>:exe v:count1."ptag <Plug><ctag>"<CR>') | |
221 call s:map('n', '<silent>', '<C-W>g} <SID>:exe "ptjump <Plug><ctag>"<CR>') | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
222 |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
223 call s:map('n', '<silent>', 'gf <SID>c:find <Plug><cfile><CR>') |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
224 call s:map('n', '<silent>', '<C-W>f <SID>c:sfind <Plug><cfile><CR>') |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
225 call s:map('n', '<silent>', '<C-W><C-F> <SID>c:sfind <Plug><cfile><CR>') |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
226 call s:map('n', '<silent>', '<C-W>gf <SID>c:tabfind <Plug><cfile><CR>') |
1215 | 227 endif |
530 | 228 |
229 let &cpo = s:cpo_save | |
230 unlet s:cpo_save | |
231 | |
1123 | 232 if exists("g:did_ruby_ftplugin_functions") |
233 finish | |
234 endif | |
235 let g:did_ruby_ftplugin_functions = 1 | |
236 | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
237 function! RubyBalloonexpr() abort |
1123 | 238 if !exists('s:ri_found') |
239 let s:ri_found = executable('ri') | |
240 endif | |
241 if s:ri_found | |
242 let line = getline(v:beval_lnum) | |
243 let b = matchstr(strpart(line,0,v:beval_col),'\%(\w\|[:.]\)*$') | |
244 let a = substitute(matchstr(strpart(line,v:beval_col),'^\w*\%([?!]\|\s*=\)\?'),'\s\+','','g') | |
245 let str = b.a | |
246 let before = strpart(line,0,v:beval_col-strlen(b)) | |
247 let after = strpart(line,v:beval_col+strlen(a)) | |
248 if str =~ '^\.' | |
249 let str = substitute(str,'^\.','#','g') | |
250 if before =~ '\]\s*$' | |
251 let str = 'Array'.str | |
252 elseif before =~ '}\s*$' | |
253 " False positives from blocks here | |
254 let str = 'Hash'.str | |
255 elseif before =~ "[\"'`]\\s*$" || before =~ '\$\d\+\s*$' | |
256 let str = 'String'.str | |
257 elseif before =~ '\$\d\+\.\d\+\s*$' | |
258 let str = 'Float'.str | |
259 elseif before =~ '\$\d\+\s*$' | |
260 let str = 'Integer'.str | |
261 elseif before =~ '/\s*$' | |
262 let str = 'Regexp'.str | |
263 else | |
264 let str = substitute(str,'^#','.','') | |
265 endif | |
266 endif | |
267 let str = substitute(str,'.*\.\s*to_f\s*\.\s*','Float#','') | |
268 let str = substitute(str,'.*\.\s*to_i\%(nt\)\=\s*\.\s*','Integer#','') | |
269 let str = substitute(str,'.*\.\s*to_s\%(tr\)\=\s*\.\s*','String#','') | |
270 let str = substitute(str,'.*\.\s*to_sym\s*\.\s*','Symbol#','') | |
271 let str = substitute(str,'.*\.\s*to_a\%(ry\)\=\s*\.\s*','Array#','') | |
272 let str = substitute(str,'.*\.\s*to_proc\s*\.\s*','Proc#','') | |
273 if str !~ '^\w' | |
274 return '' | |
275 endif | |
4869 | 276 silent! let res = substitute(system("ri -f rdoc -T \"".str.'"'),'\n$','','') |
1215 | 277 if res =~ '^Nothing known about' || res =~ '^Bad argument:' || res =~ '^More than one method' |
1123 | 278 return '' |
279 endif | |
280 return res | |
281 else | |
282 return "" | |
283 endif | |
284 endfunction | |
285 | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
286 function! s:searchsyn(pattern, syn, flags, mode) abort |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
287 let cnt = v:count1 |
4869 | 288 norm! m' |
289 if a:mode ==# 'v' | |
290 norm! gv | |
291 endif | |
292 let i = 0 | |
15512 | 293 call map(a:syn, 'hlID(v:val)') |
4869 | 294 while i < cnt |
295 let i = i + 1 | |
296 let line = line('.') | |
297 let col = col('.') | |
298 let pos = search(a:pattern,'W'.a:flags) | |
15512 | 299 while pos != 0 && index(a:syn, s:synid()) < 0 |
4869 | 300 let pos = search(a:pattern,'W'.a:flags) |
301 endwhile | |
302 if pos == 0 | |
303 call cursor(line,col) | |
304 return | |
2225 | 305 endif |
4869 | 306 endwhile |
1215 | 307 endfunction |
308 | |
15512 | 309 function! s:synid() abort |
310 return synID(line('.'),col('.'),0) | |
4869 | 311 endfunction |
312 | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
313 function! s:wrap_i(back,forward) abort |
18857
70ce979e76bc
Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
15512
diff
changeset
|
314 execute 'norm! k' |
70ce979e76bc
Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
15512
diff
changeset
|
315 execute 'norm '.a:forward |
4869 | 316 let line = line('.') |
317 execute 'norm '.a:back | |
318 if line('.') == line - 1 | |
319 return s:wrap_a(a:back,a:forward) | |
320 endif | |
18857
70ce979e76bc
Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
15512
diff
changeset
|
321 execute 'norm! jV' |
70ce979e76bc
Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
15512
diff
changeset
|
322 execute 'norm '.a:forward |
70ce979e76bc
Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
15512
diff
changeset
|
323 execute 'norm! k' |
4869 | 324 endfunction |
325 | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
326 function! s:wrap_a(back,forward) abort |
4869 | 327 execute 'norm '.a:forward |
328 if line('.') < line('$') && getline(line('.')+1) ==# '' | |
329 let after = 1 | |
330 endif | |
331 execute 'norm '.a:back | |
332 while getline(line('.')-1) =~# '^\s*#' && line('.') | |
333 - | |
334 endwhile | |
335 if exists('after') | |
18857
70ce979e76bc
Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
15512
diff
changeset
|
336 execute 'norm! V' |
70ce979e76bc
Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
15512
diff
changeset
|
337 execute 'norm '.a:forward |
70ce979e76bc
Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
15512
diff
changeset
|
338 execute 'norm! j' |
4869 | 339 elseif line('.') > 1 && getline(line('.')-1) =~# '^\s*$' |
18857
70ce979e76bc
Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
15512
diff
changeset
|
340 execute 'norm! kV' |
70ce979e76bc
Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
15512
diff
changeset
|
341 execute 'norm '.a:forward |
4869 | 342 else |
18857
70ce979e76bc
Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
15512
diff
changeset
|
343 execute 'norm! V' |
70ce979e76bc
Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
15512
diff
changeset
|
344 execute 'norm '.a:forward |
4869 | 345 endif |
1215 | 346 endfunction |
1123 | 347 |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
348 function! RubyCursorIdentifier() abort |
2225 | 349 let asciicode = '\%(\w\|[]})\"'."'".']\)\@<!\%(?\%(\\M-\\C-\|\\C-\\M-\|\\M-\\c\|\\c\\M-\|\\c\|\\C-\|\\M-\)\=\%(\\\o\{1,3}\|\\x\x\{1,2}\|\\\=\S\)\)' |
350 let number = '\%(\%(\w\|[]})\"'."'".']\s*\)\@<!-\)\=\%(\<[[:digit:]_]\+\%(\.[[:digit:]_]\+\)\=\%([Ee][[:digit:]_]\+\)\=\>\|\<0[xXbBoOdD][[:xdigit:]_]\+\>\)\|'.asciicode | |
351 let operator = '\%(\[\]\|<<\|<=>\|[!<>]=\=\|===\=\|[!=]\~\|>>\|\*\*\|\.\.\.\=\|=>\|[~^&|*/%+-]\)' | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
352 let method = '\%(\.[_a-zA-Z]\w*\s*=>\@!\|\<[_a-zA-Z]\w*\>[?!]\=\)' |
2225 | 353 let global = '$\%([!$&"'."'".'*+,./:;<=>?@\`~]\|-\=\w\+\>\)' |
354 let symbolizable = '\%(\%(@@\=\)\w\+\>\|'.global.'\|'.method.'\|'.operator.'\)' | |
355 let pattern = '\C\s*\%('.number.'\|\%(:\@<!:\)\='.symbolizable.'\)' | |
356 let [lnum, col] = searchpos(pattern,'bcn',line('.')) | |
357 let raw = matchstr(getline('.')[col-1 : ],pattern) | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
358 let stripped = substitute(substitute(raw,'\s\+=$','=',''),'^\s*[:.]\=','','') |
2225 | 359 return stripped == '' ? expand("<cword>") : stripped |
360 endfunction | |
361 | |
15512 | 362 function! RubyCursorTag() abort |
363 return substitute(RubyCursorIdentifier(), '^[$@]*', '', '') | |
364 endfunction | |
365 | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
366 function! RubyCursorFile() abort |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
367 let isfname = &isfname |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
368 try |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
369 set isfname+=: |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
370 let cfile = expand('<cfile>') |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
371 finally |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
372 let isfname = &isfname |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
373 endtry |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
374 let pre = matchstr(strpart(getline('.'), 0, col('.')-1), '.*\f\@<!') |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
375 let post = matchstr(strpart(getline('.'), col('.')), '\f\@!.*') |
15512 | 376 if s:synid() ==# hlID('rubyConstant') |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
377 let cfile = substitute(cfile,'\.\w\+[?!=]\=$','','') |
15512 | 378 let cfile = substitute(cfile,'^::','','') |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
379 let cfile = substitute(cfile,'::','/','g') |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
380 let cfile = substitute(cfile,'\(\u\+\)\(\u\l\)','\1_\2', 'g') |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
381 let cfile = substitute(cfile,'\(\l\|\d\)\(\u\)','\1_\2', 'g') |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
382 return tolower(cfile) . '.rb' |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
383 elseif getline('.') =~# '^\s*require_relative\s*\(["'']\).*\1\s*$' |
18857
70ce979e76bc
Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
15512
diff
changeset
|
384 let cfile = expand('%:p:h') . '/' . matchstr(getline('.'),'\(["'']\)\zs.\{-\}\ze\1') |
70ce979e76bc
Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
15512
diff
changeset
|
385 let cfile .= cfile !~# '\.rb$' ? '.rb' : '' |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
386 elseif getline('.') =~# '^\s*\%(require[( ]\|load[( ]\|autoload[( ]:\w\+,\)\s*\%(::\)\=File\.expand_path(\(["'']\)\.\./.*\1,\s*__FILE__)\s*$' |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
387 let target = matchstr(getline('.'),'\(["'']\)\.\.\zs/.\{-\}\ze\1') |
18857
70ce979e76bc
Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
15512
diff
changeset
|
388 let cfile = expand('%:p:h') . target |
70ce979e76bc
Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
15512
diff
changeset
|
389 let cfile .= cfile !~# '\.rb$' ? '.rb' : '' |
4869 | 390 elseif getline('.') =~# '^\s*\%(require \|load \|autoload :\w\+,\)\s*\(["'']\).*\1\s*$' |
18857
70ce979e76bc
Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
15512
diff
changeset
|
391 let cfile = matchstr(getline('.'),'\(["'']\)\zs.\{-\}\ze\1') |
70ce979e76bc
Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
15512
diff
changeset
|
392 let cfile .= cfile !~# '\.rb$' ? '.rb' : '' |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
393 elseif pre.post =~# '\<File.expand_path[( ].*[''"]\{2\}, *__FILE__\>' && cfile =~# '^\.\.' |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
394 let cfile = expand('%:p:h') . strpart(cfile, 2) |
4869 | 395 else |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
396 return substitute(cfile, '\C\v^(.*):(\d+)%(:in)=$', '+\2 \1', '') |
4869 | 397 endif |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
398 let cwdpat = '^\M' . substitute(getcwd(), '[\/]', '\\[\\/]', 'g').'\ze\[\/]' |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
399 let cfile = substitute(cfile, cwdpat, '.', '') |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
400 if fnameescape(cfile) !=# cfile |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
401 return '+ '.fnameescape(cfile) |
4869 | 402 else |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
403 return cfile |
4869 | 404 endif |
405 endfunction | |
406 | |
530 | 407 " |
408 " Instructions for enabling "matchit" support: | |
409 " | |
410 " 1. Look for the latest "matchit" plugin at | |
411 " | |
1123 | 412 " http://www.vim.org/scripts/script.php?script_id=39 |
530 | 413 " |
414 " It is also packaged with Vim, in the $VIMRUNTIME/macros directory. | |
415 " | |
416 " 2. Copy "matchit.txt" into a "doc" directory (e.g. $HOME/.vim/doc). | |
417 " | |
418 " 3. Copy "matchit.vim" into a "plugin" directory (e.g. $HOME/.vim/plugin). | |
419 " | |
420 " 4. Ensure this file (ftplugin/ruby.vim) is installed. | |
421 " | |
422 " 5. Ensure you have this line in your $HOME/.vimrc: | |
1123 | 423 " filetype plugin on |
530 | 424 " |
425 " 6. Restart Vim and create the matchit documentation: | |
426 " | |
1123 | 427 " :helptags ~/.vim/doc |
530 | 428 " |
429 " Now you can do ":help matchit", and you should be able to use "%" on Ruby | |
1123 | 430 " keywords. Try ":echo b:match_words" to be sure. |
530 | 431 " |
1123 | 432 " Thanks to Mark J. Reed for the instructions. See ":help vimrc" for the |
530 | 433 " locations of plugin directories, etc., as there are several options, and it |
434 " differs on Windows. Email gsinclair@soyabean.com.au if you need help. | |
435 " | |
436 | |
1621 | 437 " vim: nowrap sw=2 sts=2 ts=8: |