@@ -146,6 +146,14 @@ let b:undo_ftplugin = "setl fo< inc< inex< sua< def< com< cms< path< tags< kp<"
146146 \. " | if exists('&ofu') && has('ruby') | setl ofu< | endif"
147147 \. " | if has('balloon_eval') && exists('+bexpr') | setl bexpr< | endif"
148148
149+ function ! s: silmap (mode , map ) abort
150+ let from = matchstr (a: map , ' \S\+' )
151+ if empty (maparg (from, a: mode ))
152+ exe a: mode .' noremap <silent><buffer><script>' a: map
153+ let b: undo_ftplugin .= ' | ' .a: mode .' unmap <buffer> ' .from
154+ endif
155+ endfunction
156+
149157if ! exists (" g:no_plugin_maps" ) && ! exists (" g:no_ruby_maps" )
150158 nnoremap <silent> <buffer> [m :<C-U> call <SID> searchsyn('\<def\> ','rubyDefine','b','n')<CR>
151159 nnoremap <silent> <buffer> ]m :<C-U> call <SID> searchsyn('\<def\> ','rubyDefine','','n')<CR>
@@ -189,34 +197,23 @@ if !exists("g:no_plugin_maps") && !exists("g:no_ruby_maps")
189197 \. " | sil! exe 'xunmap <buffer> iM' | sil! exe 'xunmap <buffer> aM'"
190198 endif
191199
192- if maparg (" \<C-]> " ,' n' ) == ' '
193- cnoremap <buffer> <SID> foldopen <Bar> if &foldopen =~# 'tag'<Bar> exe 'norm! zv'<Bar> endif
194- nnoremap <silent> <script> <buffer> <C-]> :<C-U> exe v:count1."tag <C-R> =RubyCursorIdentifier()<CR> "<SID> foldopen<CR>
195- nnoremap <silent> <script> <buffer> g<C-]> :<C-U> exe "tjump <C-R> =RubyCursorIdentifier()<CR> "<SID> foldopen<CR>
196- nnoremap <silent> <script> <buffer> g] :<C-U> exe "tselect <C-R> =RubyCursorIdentifier()<CR> "<SID> foldopen<CR>
197- nnoremap <silent> <script> <buffer> <C-W> ] :<C-U> exe v:count1."stag <C-R> =RubyCursorIdentifier()<CR> "<SID> foldopen<CR>
198- nnoremap <silent> <script> <buffer> <C-W><C-]> :<C-U> exe v:count1."stag <C-R> =RubyCursorIdentifier()<CR> "<SID> foldopen<CR>
199- nnoremap <silent> <script> <buffer> <C-W> g<C-]> :<C-U> exe "stjump <C-R> =RubyCursorIdentifier()<CR> "<SID> foldopen<CR>
200- nnoremap <silent> <script> <buffer> <C-W> g] :<C-U> exe "stselect <C-R> =RubyCursorIdentifier()<CR> "<SID> foldopen<CR>
201- nnoremap <silent> <script> <buffer> <C-W> } :<C-U> exe "ptag <C-R> =RubyCursorIdentifier()<CR> "<CR>
202- nnoremap <silent> <script> <buffer> <C-W> g} :<C-U> exe "ptjump <C-R> =RubyCursorIdentifier()<CR> "<CR>
203- let b: undo_ftplugin = b: undo_ftplugin
204- \. " | sil! exe 'nunmap <buffer> <C-]>'| sil! exe 'nunmap <buffer> g<C-]>'| sil! exe 'nunmap <buffer> g]'"
205- \. " | sil! exe 'nunmap <buffer> <C-W>]'| sil! exe 'nunmap <buffer> <C-W><C-]>'"
206- \. " | sil! exe 'nunmap <buffer> <C-W>g<C-]>'| sil! exe 'nunmap <buffer> <C-W>g]'"
207- \. " | sil! exe 'nunmap <buffer> <C-W>}'| sil! exe 'nunmap <buffer> <C-W>g}'"
208- endif
209-
210- if maparg (" gf" ,' n' ) == ' '
211- " By using findfile() rather than gf's normal behavior, we prevent
212- " erroneously editing a directory.
213- nnoremap <silent> <buffer> gf :<C-U> exe <SID> gf(v:count1,"gf",'edit')<CR>
214- nnoremap <silent> <buffer> <C-W> f :<C-U> exe <SID> gf(v:count1,"\<Lt> C-W>f",'split')<CR>
215- nnoremap <silent> <buffer> <C-W><C-F> :<C-U> exe <SID> gf(v:count1,"\<Lt> C-W>\<Lt> C-F>",'split')<CR>
216- nnoremap <silent> <buffer> <C-W> gf :<C-U> exe <SID> gf(v:count1,"\<Lt> C-W>gf",'tabedit')<CR>
217- let b: undo_ftplugin = b: undo_ftplugin
218- \. " | 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'"
219- endif
200+ cnoremap <buffer> <SID> foldopen <Bar> if &foldopen =~# 'tag'<Bar> exe 'norm! zv'<Bar> endif
201+ call s: silmap (' n' , ' <C-]> :<C-U>exe v:count1."tag <C-R>=RubyCursorIdentifier()<CR>"<SID>foldopen<CR>' )
202+ call s: silmap (' n' , ' g<C-]> :<C-U>exe "tjump <C-R>=RubyCursorIdentifier()<CR>"<SID>foldopen<CR>' )
203+ call s: silmap (' n' , ' g] :<C-U>exe "tselect <C-R>=RubyCursorIdentifier()<CR>"<SID>foldopen<CR>' )
204+ call s: silmap (' n' , ' <C-W>] :<C-U>exe v:count1."stag <C-R>=RubyCursorIdentifier()<CR>"<SID>foldopen<CR>' )
205+ call s: silmap (' n' , ' <C-W><C-]> :<C-U>exe v:count1."stag <C-R>=RubyCursorIdentifier()<CR>"<SID>foldopen<CR>' )
206+ call s: silmap (' n' , ' <C-W>g<C-]> :<C-U>exe "stjump <C-R>=RubyCursorIdentifier()<CR>"<SID>foldopen<CR>' )
207+ call s: silmap (' n' , ' <C-W>g] :<C-U>exe "stselect <C-R>=RubyCursorIdentifier()<CR>"<SID>foldopen<CR>' )
208+ call s: silmap (' n' , ' <C-W>} :<C-U>exe "ptag <C-R>=RubyCursorIdentifier()<CR>"<CR>' )
209+ call s: silmap (' n' , ' <C-W>g} :<C-U>exe "ptjump <C-R>=RubyCursorIdentifier()<CR>"<CR>' )
210+
211+ " By using findfile() rather than gf's normal behavior, we prevent
212+ " erroneously editing a directory.
213+ call s: silmap (' n' , ' gf :<C-U>exe <SID>gf(v:count1,"gf","edit")<CR>' )
214+ call s: silmap (' n' , ' <C-W>f :<C-U>exe <SID>gf(v:count1,"\<Lt>C-W>f","split")<CR>' )
215+ call s: silmap (' n' , ' <C-W><C-F> :<C-U>exe <SID>gf(v:count1,"\<Lt>C-W>\<Lt>C-F>","split")<CR>' )
216+ call s: silmap (' n' , ' <C-W>gf :<C-U>exe <SID>gf(v:count1,"\<Lt>C-W>gf","tabedit")<CR>' )
220217endif
221218
222219let &cpo = s: cpo_save
0 commit comments