Mercurial > vim
annotate runtime/ftplugin/ruby.vim @ 28739:40b087823dc7 v8.2.4894
patch 8.2.4894: MS-Windows: not using italics
Commit: https://github.com/vim/vim/commit/5a7b6dc23cd16450b5773849520d513de56bccbf
Author: LemonBoy <thatlemon@gmail.com>
Date: Fri May 6 18:38:41 2022 +0100
patch 8.2.4894: MS-Windows: not using italics
Problem: MS-Windows: not using italics.
Solution: Use italics. Simplify the code. (closes https://github.com/vim/vim/issues/10359)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 06 May 2022 19:45:02 +0200 |
parents | e3d6184b89fa |
children | 828bcb1a37e7 |
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> |
28246 | 6 " Last Change: 2022 Mar 21 |
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 | |
28246 | 56 setlocal comments=b:# |
530 | 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'), ',') |
28246 | 90 if &g:path =~# '\v^%(\.,)=%(/%(usr|emx)/include,)=,$' |
91 let path = path . ',.,,' | |
92 elseif &g:path =~# ',\.,,$' | |
93 let path = &g:path[0:-4] . path . ',.,,' | |
94 elseif &g:path =~# ',,$' | |
95 let path = &g:path[0:-2] . path . ',,' | |
96 else | |
97 let path = substitute(&g:path, '[^,]\zs$', ',', '') . path | |
4869 | 98 endif |
99 return path | |
100 endfunction | |
101 | |
102 if !exists('b:ruby_version') && !exists('g:ruby_path') && isdirectory(expand('%:p:h')) | |
103 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
|
104 if !empty(s:version_file) && filereadable(s:version_file) |
4869 | 105 let b:ruby_version = get(readfile(s:version_file, '', 1), '') |
106 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')) | |
530 | 108 endif |
109 endif | |
110 endif | |
111 | |
4869 | 112 if exists("g:ruby_path") |
113 let s:ruby_path = type(g:ruby_path) == type([]) ? join(g:ruby_path, ',') : g:ruby_path | |
114 elseif has_key(g:ruby_version_paths, get(b:, 'ruby_version', '')) | |
115 let s:ruby_paths = g:ruby_version_paths[b:ruby_version] | |
116 let s:ruby_path = s:build_path(s:ruby_paths) | |
117 else | |
118 if !exists('g:ruby_default_path') | |
119 if has("ruby") && has("win32") | |
120 ruby ::VIM::command( 'let g:ruby_default_path = split("%s",",")' % $:.join(%q{,}) ) | |
25056 | 121 elseif executable('ruby') && !empty($HOME) |
4869 | 122 let g:ruby_default_path = s:query_path($HOME) |
123 else | |
124 let g:ruby_default_path = map(split($RUBYLIB,':'), 'v:val ==# "." ? "" : v:val') | |
125 endif | |
126 endif | |
127 let s:ruby_paths = g:ruby_default_path | |
128 let s:ruby_path = s:build_path(s:ruby_paths) | |
129 endif | |
130 | |
131 if stridx(&l:path, s:ruby_path) == -1 | |
132 let &l:path = s:ruby_path | |
133 endif | |
134 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 endif | |
530 | 137 |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
138 if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter") |
530 | 139 let b:browsefilter = "Ruby Source Files (*.rb)\t*.rb\n" . |
1123 | 140 \ "All Files (*.*)\t*.*\n" |
530 | 141 endif |
142 | |
15512 | 143 let b:undo_ftplugin = "setl inc= sua= path= tags= fo< com< cms< kp=" |
1215 | 144 \."| unlet! b:browsefilter b:match_ignorecase b:match_words b:match_skip" |
145 \."| if exists('&ofu') && has('ruby') | setl ofu< | endif" | |
15512 | 146 |
147 if get(g:, 'ruby_recommended_style', 1) | |
148 setlocal shiftwidth=2 softtabstop=2 expandtab | |
149 let b:undo_ftplugin .= ' | setl sw< sts< et<' | |
150 endif | |
151 | |
152 " To activate, :set ballooneval | |
153 if exists('+balloonexpr') && get(g:, 'ruby_balloonexpr') | |
154 setlocal balloonexpr=RubyBalloonexpr() | |
155 let b:undo_ftplugin .= "| setl bexpr=" | |
156 endif | |
1215 | 157 |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
158 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
|
159 let from = matchstr(a:map, '\S\+') |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
160 if empty(mapcheck(from, a:mode)) |
18857
70ce979e76bc
Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
15512
diff
changeset
|
161 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
|
162 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
|
163 endif |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
164 endfunction |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
165 |
15512 | 166 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
|
167 cmap <buffer><script><expr> <Plug><cfile> substitute(RubyCursorFile(),'^$',"\022\006",'') |
15512 | 168 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
|
169 |
1215 | 170 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
|
171 nmap <buffer><script> <SID>: :<C-U> |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
172 nmap <buffer><script> <SID>c: :<C-U><C-R>=v:count ? v:count : ''<CR> |
28246 | 173 cmap <buffer> <SID><cfile> <Plug><cfile> |
174 cmap <buffer> <SID><ctag> <Plug><ctag> | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
175 |
15512 | 176 nnoremap <silent> <buffer> [m :<C-U>call <SID>searchsyn('\<def\>',['rubyDefine'],'b','n')<CR> |
177 nnoremap <silent> <buffer> ]m :<C-U>call <SID>searchsyn('\<def\>',['rubyDefine'],'','n')<CR> | |
178 nnoremap <silent> <buffer> [M :<C-U>call <SID>searchsyn('\<end\>',['rubyDefine'],'b','n')<CR> | |
179 nnoremap <silent> <buffer> ]M :<C-U>call <SID>searchsyn('\<end\>',['rubyDefine'],'','n')<CR> | |
180 xnoremap <silent> <buffer> [m :<C-U>call <SID>searchsyn('\<def\>',['rubyDefine'],'b','v')<CR> | |
181 xnoremap <silent> <buffer> ]m :<C-U>call <SID>searchsyn('\<def\>',['rubyDefine'],'','v')<CR> | |
182 xnoremap <silent> <buffer> [M :<C-U>call <SID>searchsyn('\<end\>',['rubyDefine'],'b','v')<CR> | |
183 xnoremap <silent> <buffer> ]M :<C-U>call <SID>searchsyn('\<end\>',['rubyDefine'],'','v')<CR> | |
1215 | 184 |
15512 | 185 nnoremap <silent> <buffer> [[ :<C-U>call <SID>searchsyn('\<\%(class\<Bar>module\)\>',['rubyModule','rubyClass'],'b','n')<CR> |
186 nnoremap <silent> <buffer> ]] :<C-U>call <SID>searchsyn('\<\%(class\<Bar>module\)\>',['rubyModule','rubyClass'],'','n')<CR> | |
187 nnoremap <silent> <buffer> [] :<C-U>call <SID>searchsyn('\<end\>',['rubyModule','rubyClass'],'b','n')<CR> | |
188 nnoremap <silent> <buffer> ][ :<C-U>call <SID>searchsyn('\<end\>',['rubyModule','rubyClass'],'','n')<CR> | |
189 xnoremap <silent> <buffer> [[ :<C-U>call <SID>searchsyn('\<\%(class\<Bar>module\)\>',['rubyModule','rubyClass'],'b','v')<CR> | |
190 xnoremap <silent> <buffer> ]] :<C-U>call <SID>searchsyn('\<\%(class\<Bar>module\)\>',['rubyModule','rubyClass'],'','v')<CR> | |
191 xnoremap <silent> <buffer> [] :<C-U>call <SID>searchsyn('\<end\>',['rubyModule','rubyClass'],'b','v')<CR> | |
192 xnoremap <silent> <buffer> ][ :<C-U>call <SID>searchsyn('\<end\>',['rubyModule','rubyClass'],'','v')<CR> | |
1215 | 193 |
194 let b:undo_ftplugin = b:undo_ftplugin | |
195 \."| sil! exe 'unmap <buffer> [[' | sil! exe 'unmap <buffer> ]]' | sil! exe 'unmap <buffer> []' | sil! exe 'unmap <buffer> ]['" | |
196 \."| sil! exe 'unmap <buffer> [m' | sil! exe 'unmap <buffer> ]m' | sil! exe 'unmap <buffer> [M' | sil! exe 'unmap <buffer> ]M'" | |
2225 | 197 |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
198 if maparg('im','x') == '' && maparg('im','o') == '' && maparg('am','x') == '' && maparg('am','o') == '' |
4869 | 199 onoremap <silent> <buffer> im :<C-U>call <SID>wrap_i('[m',']M')<CR> |
200 onoremap <silent> <buffer> am :<C-U>call <SID>wrap_a('[m',']M')<CR> | |
201 xnoremap <silent> <buffer> im :<C-U>call <SID>wrap_i('[m',']M')<CR> | |
202 xnoremap <silent> <buffer> am :<C-U>call <SID>wrap_a('[m',']M')<CR> | |
203 let b:undo_ftplugin = b:undo_ftplugin | |
204 \."| sil! exe 'ounmap <buffer> im' | sil! exe 'ounmap <buffer> am'" | |
205 \."| sil! exe 'xunmap <buffer> im' | sil! exe 'xunmap <buffer> am'" | |
206 endif | |
207 | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
208 if maparg('iM','x') == '' && maparg('iM','o') == '' && maparg('aM','x') == '' && maparg('aM','o') == '' |
4869 | 209 onoremap <silent> <buffer> iM :<C-U>call <SID>wrap_i('[[','][')<CR> |
210 onoremap <silent> <buffer> aM :<C-U>call <SID>wrap_a('[[','][')<CR> | |
211 xnoremap <silent> <buffer> iM :<C-U>call <SID>wrap_i('[[','][')<CR> | |
212 xnoremap <silent> <buffer> aM :<C-U>call <SID>wrap_a('[[','][')<CR> | |
213 let b:undo_ftplugin = b:undo_ftplugin | |
214 \."| sil! exe 'ounmap <buffer> iM' | sil! exe 'ounmap <buffer> aM'" | |
215 \."| sil! exe 'xunmap <buffer> iM' | sil! exe 'xunmap <buffer> aM'" | |
216 endif | |
217 | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
218 call s:map('c', '', '<C-R><C-F> <Plug><cfile>') |
4869 | 219 |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
220 cmap <buffer><script><expr> <SID>tagzv &foldopen =~# 'tag' ? '<Bar>norm! zv' : '' |
28246 | 221 call s:map('n', '<script><silent>', '<C-]> <SID>:exe v:count1."tag <SID><ctag>"<SID>tagzv<CR>') |
222 call s:map('n', '<script><silent>', 'g<C-]> <SID>:exe "tjump <SID><ctag>"<SID>tagzv<CR>') | |
223 call s:map('n', '<script><silent>', 'g] <SID>:exe "tselect <SID><ctag>"<SID>tagzv<CR>') | |
224 call s:map('n', '<script><silent>', '<C-W>] <SID>:exe v:count1."stag <SID><ctag>"<SID>tagzv<CR>') | |
225 call s:map('n', '<script><silent>', '<C-W><C-]> <SID>:exe v:count1."stag <SID><ctag>"<SID>tagzv<CR>') | |
226 call s:map('n', '<script><silent>', '<C-W>g<C-]> <SID>:exe "stjump <SID><ctag>"<SID>tagzv<CR>') | |
227 call s:map('n', '<script><silent>', '<C-W>g] <SID>:exe "stselect <SID><ctag>"<SID>tagzv<CR>') | |
228 call s:map('n', '<script><silent>', '<C-W>} <SID>:exe v:count1."ptag <SID><ctag>"<CR>') | |
229 call s:map('n', '<script><silent>', '<C-W>g} <SID>:exe "ptjump <SID><ctag>"<CR>') | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
230 |
28246 | 231 call s:map('n', '<script><silent>', 'gf <SID>c:find <SID><cfile><CR>') |
232 call s:map('n', '<script><silent>', '<C-W>f <SID>c:sfind <SID><cfile><CR>') | |
233 call s:map('n', '<script><silent>', '<C-W><C-F> <SID>c:sfind <SID><cfile><CR>') | |
234 call s:map('n', '<script><silent>', '<C-W>gf <SID>c:tabfind <SID><cfile><CR>') | |
1215 | 235 endif |
530 | 236 |
237 let &cpo = s:cpo_save | |
238 unlet s:cpo_save | |
239 | |
1123 | 240 if exists("g:did_ruby_ftplugin_functions") |
241 finish | |
242 endif | |
243 let g:did_ruby_ftplugin_functions = 1 | |
244 | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
245 function! RubyBalloonexpr() abort |
1123 | 246 if !exists('s:ri_found') |
247 let s:ri_found = executable('ri') | |
248 endif | |
249 if s:ri_found | |
250 let line = getline(v:beval_lnum) | |
251 let b = matchstr(strpart(line,0,v:beval_col),'\%(\w\|[:.]\)*$') | |
252 let a = substitute(matchstr(strpart(line,v:beval_col),'^\w*\%([?!]\|\s*=\)\?'),'\s\+','','g') | |
253 let str = b.a | |
254 let before = strpart(line,0,v:beval_col-strlen(b)) | |
255 let after = strpart(line,v:beval_col+strlen(a)) | |
256 if str =~ '^\.' | |
257 let str = substitute(str,'^\.','#','g') | |
258 if before =~ '\]\s*$' | |
259 let str = 'Array'.str | |
260 elseif before =~ '}\s*$' | |
261 " False positives from blocks here | |
262 let str = 'Hash'.str | |
263 elseif before =~ "[\"'`]\\s*$" || before =~ '\$\d\+\s*$' | |
264 let str = 'String'.str | |
265 elseif before =~ '\$\d\+\.\d\+\s*$' | |
266 let str = 'Float'.str | |
267 elseif before =~ '\$\d\+\s*$' | |
268 let str = 'Integer'.str | |
269 elseif before =~ '/\s*$' | |
270 let str = 'Regexp'.str | |
271 else | |
272 let str = substitute(str,'^#','.','') | |
273 endif | |
274 endif | |
275 let str = substitute(str,'.*\.\s*to_f\s*\.\s*','Float#','') | |
276 let str = substitute(str,'.*\.\s*to_i\%(nt\)\=\s*\.\s*','Integer#','') | |
277 let str = substitute(str,'.*\.\s*to_s\%(tr\)\=\s*\.\s*','String#','') | |
278 let str = substitute(str,'.*\.\s*to_sym\s*\.\s*','Symbol#','') | |
279 let str = substitute(str,'.*\.\s*to_a\%(ry\)\=\s*\.\s*','Array#','') | |
280 let str = substitute(str,'.*\.\s*to_proc\s*\.\s*','Proc#','') | |
281 if str !~ '^\w' | |
282 return '' | |
283 endif | |
4869 | 284 silent! let res = substitute(system("ri -f rdoc -T \"".str.'"'),'\n$','','') |
1215 | 285 if res =~ '^Nothing known about' || res =~ '^Bad argument:' || res =~ '^More than one method' |
1123 | 286 return '' |
287 endif | |
288 return res | |
289 else | |
290 return "" | |
291 endif | |
292 endfunction | |
293 | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
294 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
|
295 let cnt = v:count1 |
4869 | 296 norm! m' |
297 if a:mode ==# 'v' | |
298 norm! gv | |
299 endif | |
300 let i = 0 | |
15512 | 301 call map(a:syn, 'hlID(v:val)') |
4869 | 302 while i < cnt |
303 let i = i + 1 | |
304 let line = line('.') | |
305 let col = col('.') | |
306 let pos = search(a:pattern,'W'.a:flags) | |
15512 | 307 while pos != 0 && index(a:syn, s:synid()) < 0 |
4869 | 308 let pos = search(a:pattern,'W'.a:flags) |
309 endwhile | |
310 if pos == 0 | |
311 call cursor(line,col) | |
312 return | |
2225 | 313 endif |
4869 | 314 endwhile |
1215 | 315 endfunction |
316 | |
15512 | 317 function! s:synid() abort |
318 return synID(line('.'),col('.'),0) | |
4869 | 319 endfunction |
320 | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
321 function! s:wrap_i(back,forward) abort |
18857
70ce979e76bc
Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
15512
diff
changeset
|
322 execute 'norm! k' |
70ce979e76bc
Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
15512
diff
changeset
|
323 execute 'norm '.a:forward |
4869 | 324 let line = line('.') |
325 execute 'norm '.a:back | |
326 if line('.') == line - 1 | |
327 return s:wrap_a(a:back,a:forward) | |
328 endif | |
18857
70ce979e76bc
Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
15512
diff
changeset
|
329 execute 'norm! jV' |
70ce979e76bc
Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
15512
diff
changeset
|
330 execute 'norm '.a:forward |
70ce979e76bc
Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
15512
diff
changeset
|
331 execute 'norm! k' |
4869 | 332 endfunction |
333 | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
334 function! s:wrap_a(back,forward) abort |
4869 | 335 execute 'norm '.a:forward |
336 if line('.') < line('$') && getline(line('.')+1) ==# '' | |
337 let after = 1 | |
338 endif | |
339 execute 'norm '.a:back | |
340 while getline(line('.')-1) =~# '^\s*#' && line('.') | |
341 - | |
342 endwhile | |
343 if exists('after') | |
18857
70ce979e76bc
Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
15512
diff
changeset
|
344 execute 'norm! V' |
70ce979e76bc
Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
15512
diff
changeset
|
345 execute 'norm '.a:forward |
70ce979e76bc
Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
15512
diff
changeset
|
346 execute 'norm! j' |
4869 | 347 elseif line('.') > 1 && getline(line('.')-1) =~# '^\s*$' |
18857
70ce979e76bc
Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
15512
diff
changeset
|
348 execute 'norm! kV' |
70ce979e76bc
Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
15512
diff
changeset
|
349 execute 'norm '.a:forward |
4869 | 350 else |
18857
70ce979e76bc
Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
15512
diff
changeset
|
351 execute 'norm! V' |
70ce979e76bc
Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
15512
diff
changeset
|
352 execute 'norm '.a:forward |
4869 | 353 endif |
1215 | 354 endfunction |
1123 | 355 |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
356 function! RubyCursorIdentifier() abort |
2225 | 357 let asciicode = '\%(\w\|[]})\"'."'".']\)\@<!\%(?\%(\\M-\\C-\|\\C-\\M-\|\\M-\\c\|\\c\\M-\|\\c\|\\C-\|\\M-\)\=\%(\\\o\{1,3}\|\\x\x\{1,2}\|\\\=\S\)\)' |
358 let number = '\%(\%(\w\|[]})\"'."'".']\s*\)\@<!-\)\=\%(\<[[:digit:]_]\+\%(\.[[:digit:]_]\+\)\=\%([Ee][[:digit:]_]\+\)\=\>\|\<0[xXbBoOdD][[:xdigit:]_]\+\>\)\|'.asciicode | |
359 let operator = '\%(\[\]\|<<\|<=>\|[!<>]=\=\|===\=\|[!=]\~\|>>\|\*\*\|\.\.\.\=\|=>\|[~^&|*/%+-]\)' | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
360 let method = '\%(\.[_a-zA-Z]\w*\s*=>\@!\|\<[_a-zA-Z]\w*\>[?!]\=\)' |
2225 | 361 let global = '$\%([!$&"'."'".'*+,./:;<=>?@\`~]\|-\=\w\+\>\)' |
362 let symbolizable = '\%(\%(@@\=\)\w\+\>\|'.global.'\|'.method.'\|'.operator.'\)' | |
363 let pattern = '\C\s*\%('.number.'\|\%(:\@<!:\)\='.symbolizable.'\)' | |
364 let [lnum, col] = searchpos(pattern,'bcn',line('.')) | |
365 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
|
366 let stripped = substitute(substitute(raw,'\s\+=$','=',''),'^\s*[:.]\=','','') |
2225 | 367 return stripped == '' ? expand("<cword>") : stripped |
368 endfunction | |
369 | |
15512 | 370 function! RubyCursorTag() abort |
371 return substitute(RubyCursorIdentifier(), '^[$@]*', '', '') | |
372 endfunction | |
373 | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
374 function! RubyCursorFile() abort |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
375 let isfname = &isfname |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
376 try |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
377 set isfname+=: |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
378 let cfile = expand('<cfile>') |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
379 finally |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
380 let isfname = &isfname |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
381 endtry |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
382 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
|
383 let post = matchstr(strpart(getline('.'), col('.')), '\f\@!.*') |
15512 | 384 if s:synid() ==# hlID('rubyConstant') |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
385 let cfile = substitute(cfile,'\.\w\+[?!=]\=$','','') |
15512 | 386 let cfile = substitute(cfile,'^::','','') |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
387 let cfile = substitute(cfile,'::','/','g') |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
388 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
|
389 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
|
390 return tolower(cfile) . '.rb' |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
391 elseif getline('.') =~# '^\s*require_relative\s*\(["'']\).*\1\s*$' |
18857
70ce979e76bc
Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
15512
diff
changeset
|
392 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
|
393 let cfile .= cfile !~# '\.rb$' ? '.rb' : '' |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
394 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
|
395 let target = matchstr(getline('.'),'\(["'']\)\.\.\zs/.\{-\}\ze\1') |
18857
70ce979e76bc
Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
15512
diff
changeset
|
396 let cfile = expand('%:p:h') . target |
70ce979e76bc
Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
15512
diff
changeset
|
397 let cfile .= cfile !~# '\.rb$' ? '.rb' : '' |
4869 | 398 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
|
399 let cfile = matchstr(getline('.'),'\(["'']\)\zs.\{-\}\ze\1') |
70ce979e76bc
Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
15512
diff
changeset
|
400 let cfile .= cfile !~# '\.rb$' ? '.rb' : '' |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
401 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
|
402 let cfile = expand('%:p:h') . strpart(cfile, 2) |
4869 | 403 else |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
404 return substitute(cfile, '\C\v^(.*):(\d+)%(:in)=$', '+\2 \1', '') |
4869 | 405 endif |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
406 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
|
407 let cfile = substitute(cfile, cwdpat, '.', '') |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
408 if fnameescape(cfile) !=# cfile |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
409 return '+ '.fnameescape(cfile) |
4869 | 410 else |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
411 return cfile |
4869 | 412 endif |
413 endfunction | |
414 | |
530 | 415 " |
416 " Instructions for enabling "matchit" support: | |
417 " | |
418 " 1. Look for the latest "matchit" plugin at | |
419 " | |
1123 | 420 " http://www.vim.org/scripts/script.php?script_id=39 |
530 | 421 " |
422 " It is also packaged with Vim, in the $VIMRUNTIME/macros directory. | |
423 " | |
424 " 2. Copy "matchit.txt" into a "doc" directory (e.g. $HOME/.vim/doc). | |
425 " | |
426 " 3. Copy "matchit.vim" into a "plugin" directory (e.g. $HOME/.vim/plugin). | |
427 " | |
428 " 4. Ensure this file (ftplugin/ruby.vim) is installed. | |
429 " | |
430 " 5. Ensure you have this line in your $HOME/.vimrc: | |
1123 | 431 " filetype plugin on |
530 | 432 " |
433 " 6. Restart Vim and create the matchit documentation: | |
434 " | |
1123 | 435 " :helptags ~/.vim/doc |
530 | 436 " |
437 " Now you can do ":help matchit", and you should be able to use "%" on Ruby | |
1123 | 438 " keywords. Try ":echo b:match_words" to be sure. |
530 | 439 " |
1123 | 440 " Thanks to Mark J. Reed for the instructions. See ":help vimrc" for the |
530 | 441 " locations of plugin directories, etc., as there are several options, and it |
442 " differs on Windows. Email gsinclair@soyabean.com.au if you need help. | |
443 " | |
444 | |
1621 | 445 " vim: nowrap sw=2 sts=2 ts=8: |