Skip to content

Commit 5f895ff

Browse files
committed
Refactor s:Alternate to return command to execute
1 parent 7e85bb3 commit 5f895ff

File tree

1 file changed

+28
-37
lines changed

1 file changed

+28
-37
lines changed

autoload/rails.vim

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1979,19 +1979,19 @@ function! s:BufNavCommands()
19791979
command! -buffer -bar -nargs=? -complete=customlist,s:Complete_cd Lcd :lcd `=rails#app().path(<q-args>)`
19801980
command! -buffer -bar -nargs=? -complete=customlist,s:Complete_cd Rcd :cd `=rails#app().path(<q-args>)`
19811981
command! -buffer -bar -nargs=? -complete=customlist,s:Complete_cd Rlcd :lcd `=rails#app().path(<q-args>)`
1982-
command! -buffer -bar -nargs=* -range=0 -complete=customlist,s:Complete_related A :call s:Alternate('<bang>', <line1>,<line2>,<count>,<f-args>)
1983-
command! -buffer -bar -nargs=* -range=0 -complete=customlist,s:Complete_related AE :call s:Alternate('E<bang>',<line1>,<line2>,<count>,<f-args>)
1984-
command! -buffer -bar -nargs=* -range=0 -complete=customlist,s:Complete_related AS :call s:Alternate('S<bang>',<line1>,<line2>,<count>,<f-args>)
1985-
command! -buffer -bar -nargs=* -range=0 -complete=customlist,s:Complete_related AV :call s:Alternate('V<bang>',<line1>,<line2>,<count>,<f-args>)
1986-
command! -buffer -bar -nargs=* -range=0 -complete=customlist,s:Complete_related AT :call s:Alternate('T<bang>',<line1>,<line2>,<count>,<f-args>)
1987-
command! -buffer -bar -nargs=* -range=0 -complete=customlist,s:Complete_related AD :call s:Alternate('D<bang>',<line1>,<line2>,<count>,<f-args>)
1988-
command! -buffer -bar -nargs=* -range=0 -complete=customlist,s:Complete_related AR :call s:Alternate('D<bang>',<line1>,<line2>,<count>,<f-args>)
1989-
command! -buffer -bar -nargs=* -range=0 -complete=customlist,s:Complete_related R :call s:Related('<bang>' ,<line1>,<line2>,<count>,<f-args>)
1990-
command! -buffer -bar -nargs=* -range=0 -complete=customlist,s:Complete_related RE :call s:Related('E<bang>',<line1>,<line2>,<count>,<f-args>)
1991-
command! -buffer -bar -nargs=* -range=0 -complete=customlist,s:Complete_related RS :call s:Related('S<bang>',<line1>,<line2>,<count>,<f-args>)
1992-
command! -buffer -bar -nargs=* -range=0 -complete=customlist,s:Complete_related RV :call s:Related('V<bang>',<line1>,<line2>,<count>,<f-args>)
1993-
command! -buffer -bar -nargs=* -range=0 -complete=customlist,s:Complete_related RT :call s:Related('T<bang>',<line1>,<line2>,<count>,<f-args>)
1994-
command! -buffer -bar -nargs=* -range=0 -complete=customlist,s:Complete_related RD :call s:Related('D<bang>',<line1>,<line2>,<count>,<f-args>)
1982+
command! -buffer -bar -nargs=* -range=0 -complete=customlist,s:Complete_related A :exe s:Alternate('E<bang>',<line1>,<line2>,<count>,<f-args>)
1983+
command! -buffer -bar -nargs=* -range=0 -complete=customlist,s:Complete_related AE :exe s:Alternate('E<bang>',<line1>,<line2>,<count>,<f-args>)
1984+
command! -buffer -bar -nargs=* -range=0 -complete=customlist,s:Complete_related AS :exe s:Alternate('S<bang>',<line1>,<line2>,<count>,<f-args>)
1985+
command! -buffer -bar -nargs=* -range=0 -complete=customlist,s:Complete_related AV :exe s:Alternate('V<bang>',<line1>,<line2>,<count>,<f-args>)
1986+
command! -buffer -bar -nargs=* -range=0 -complete=customlist,s:Complete_related AT :exe s:Alternate('T<bang>',<line1>,<line2>,<count>,<f-args>)
1987+
command! -buffer -bar -nargs=* -range=0 -complete=customlist,s:Complete_related AD :exe s:Alternate('D<bang>',<line1>,<line2>,<count>,<f-args>)
1988+
command! -buffer -bar -nargs=* -range=0 -complete=customlist,s:Complete_related AR :exe s:Alternate('D<bang>',<line1>,<line2>,<count>,<f-args>)
1989+
command! -buffer -bar -nargs=* -range=0 -complete=customlist,s:Complete_related R :exe s:Related('E<bang>',<line1>,<line2>,<count>,<f-args>)
1990+
command! -buffer -bar -nargs=* -range=0 -complete=customlist,s:Complete_related RE :exe s:Related('E<bang>',<line1>,<line2>,<count>,<f-args>)
1991+
command! -buffer -bar -nargs=* -range=0 -complete=customlist,s:Complete_related RS :exe s:Related('S<bang>',<line1>,<line2>,<count>,<f-args>)
1992+
command! -buffer -bar -nargs=* -range=0 -complete=customlist,s:Complete_related RV :exe s:Related('V<bang>',<line1>,<line2>,<count>,<f-args>)
1993+
command! -buffer -bar -nargs=* -range=0 -complete=customlist,s:Complete_related RT :exe s:Related('T<bang>',<line1>,<line2>,<count>,<f-args>)
1994+
command! -buffer -bar -nargs=* -range=0 -complete=customlist,s:Complete_related RD :exe s:Related('D<bang>',<line1>,<line2>,<count>,<f-args>)
19951995
endfunction
19961996

19971997
function! s:djump(def)
@@ -2057,22 +2057,7 @@ function! s:Find(count,cmd,...)
20572057
let file = s:RailsFind()
20582058
let tail = ""
20592059
endif
2060-
call s:findedit((a:count==1?'' : a:count).a:cmd,file.tail,str)
2061-
endfunction
2062-
2063-
function! s:Edit(count,cmd,...)
2064-
if a:0
2065-
let str = ""
2066-
let i = 1
2067-
while i < a:0
2068-
let str .= s:escarg(a:{i}) . " "
2069-
let i += 1
2070-
endwhile
2071-
let file = a:{i}
2072-
call s:findedit(s:editcmdfor(a:cmd),file,str)
2073-
else
2074-
exe s:editcmdfor(a:cmd)
2075-
endif
2060+
return s:findedit((a:count==1?'' : a:count).a:cmd,file.tail,str)
20762061
endfunction
20772062

20782063
function! s:fuzzyglob(arg)
@@ -3245,20 +3230,26 @@ function! s:Alternate(cmd,line1,line2,count,...)
32453230
if a:0
32463231
if a:count && a:cmd !~# 'D'
32473232
return call('s:Find',[1,a:line1.a:cmd]+a:000)
3248-
elseif a:count
3249-
return call('s:Edit',[1,a:line1.a:cmd]+a:000)
32503233
else
3251-
return call('s:Edit',[1,a:cmd]+a:000)
3234+
let str = ""
3235+
let i = 1
3236+
while i < a:0
3237+
let str .= s:escarg(a:{i}) . " "
3238+
let i += 1
3239+
endwhile
3240+
let file = a:{i}
3241+
return s:findedit(s:editcmdfor((a:count ? a:count : '').a:cmd), file, str)
32523242
endif
32533243
else
32543244
let file = get(b:, a:count ? 'rails_related' : 'rails_alternate')
32553245
if empty(file)
32563246
let file = rails#buffer().alternate(a:count)
32573247
endif
32583248
if !empty(file)
3259-
call s:findedit(a:cmd,file)
3249+
return s:findedit(a:cmd, file)
32603250
else
32613251
call s:warn("No alternate file is defined")
3252+
return ''
32623253
endif
32633254
endif
32643255
endfunction
@@ -4064,10 +4055,10 @@ endfunction
40644055
" Mappings {{{1
40654056

40664057
function! s:BufMappings()
4067-
nnoremap <buffer> <silent> <Plug>RailsFind :<C-U>call <SID>Find(v:count1,'E')<CR>
4068-
nnoremap <buffer> <silent> <Plug>RailsSplitFind :<C-U>call <SID>Find(v:count1,'S')<CR>
4069-
nnoremap <buffer> <silent> <Plug>RailsVSplitFind :<C-U>call <SID>Find(v:count1,'V')<CR>
4070-
nnoremap <buffer> <silent> <Plug>RailsTabFind :<C-U>call <SID>Find(v:count1,'T')<CR>
4058+
nnoremap <buffer> <silent> <Plug>RailsFind :<C-U>exe <SID>Find(v:count1,'E')<CR>
4059+
nnoremap <buffer> <silent> <Plug>RailsSplitFind :<C-U>exe <SID>Find(v:count1,'S')<CR>
4060+
nnoremap <buffer> <silent> <Plug>RailsVSplitFind :<C-U>exe <SID>Find(v:count1,'V')<CR>
4061+
nnoremap <buffer> <silent> <Plug>RailsTabFind :<C-U>exe <SID>Find(v:count1,'T')<CR>
40714062
if !hasmapto("<Plug>RailsFind")
40724063
nmap <buffer> gf <Plug>RailsFind
40734064
endif

0 commit comments

Comments
 (0)