Skip to content

Commit f5feb62

Browse files
committed
:1R filename calls :Rfind filename
1 parent 770889a commit f5feb62

File tree

1 file changed

+41
-28
lines changed

1 file changed

+41
-28
lines changed

autoload/rails.vim

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -208,21 +208,21 @@ function! s:endof(lnum)
208208
return 0
209209
endfunction
210210

211-
function! s:lastopeningline(pattern,limit,...)
212-
let line = a:0 ? a:1 : line(".")
211+
function! s:lastopeningline(pattern,limit,start)
212+
let line = a:start
213213
while line > a:limit && getline(line) !~ a:pattern
214214
let line -= 1
215215
endwhile
216216
let lend = s:endof(line)
217-
if line > a:limit && (lend < 0 || lend >= (a:0 ? a:1 : line(".")))
217+
if line > a:limit && (lend < 0 || lend >= a:start)
218218
return line
219219
else
220220
return -1
221221
endif
222222
endfunction
223223

224-
function! s:lastmethodline(...)
225-
return s:lastopeningline(&l:define,0,a:0 ? a:1 : line("."))
224+
function! s:lastmethodline(start)
225+
return s:lastopeningline(&l:define,0,a:start)
226226
endfunction
227227

228228
function! s:lastmethod(...)
@@ -234,15 +234,15 @@ function! s:lastmethod(...)
234234
endif
235235
endfunction
236236

237-
function! s:lastrespondtoline(...)
238-
return s:lastopeningline('\C^\s*respond_to\s*\%(\<do\)\s*|\zs\h\k*\ze|',s:lastmethodline(), a:0 ? a:1 : line("."))
237+
function! s:lastrespondtoline(start)
238+
return s:lastopeningline('\C^\s*respond_to\s*\%(\<do\)\s*|\zs\h\k*\ze|',s:lastmethodline(a:start),a:start)
239239
endfunction
240240

241-
function! s:lastformat()
242-
let rline = s:lastrespondtoline()
241+
function! s:lastformat(start)
242+
let rline = s:lastrespondtoline(a:start)
243243
if rline
244244
let variable = matchstr(getline(rline),'\C^\s*respond_to\s*\%(\<do\|{\)\s*|\zs\h\k*\ze|')
245-
let line = line('.')
245+
let line = a:start
246246
while line > rline
247247
let match = matchstr(getline(line),'\C^\s*'.variable.'\s*\.\s*\zs\h\k*')
248248
if match != ''
@@ -258,7 +258,7 @@ function! s:format(...)
258258
if RailsFileType() =~ '^view\>'
259259
let format = fnamemodify(RailsFilePath(),':r:e')
260260
else
261-
let format = s:lastformat()
261+
let format = s:lastformat(a:0 > 1 ? a:2 : line("."))
262262
endif
263263
if format == ''
264264
return get({'rhtml': 'html', 'rxml': 'xml', 'rjs': 'js'},fnamemodify(RailsFilePath(),':e'),a:0 ? a:1 : '')
@@ -1502,13 +1502,13 @@ function! s:BufNavCommands()
15021502
command! -buffer -bar -nargs=* -complete=customlist,s:Complete_find AV :call s:Alternate('V<bang>',<f-args>)
15031503
command! -buffer -bar -nargs=* -complete=customlist,s:Complete_find AT :call s:Alternate('T<bang>',<f-args>)
15041504
command! -buffer -bar -nargs=* -range=0 -complete=customlist,s:Complete_find AD :call s:Alternate('<line1>D<bang>',<f-args>)
1505-
command! -buffer -bar -nargs=* -complete=customlist,s:Complete_edit AN :call s:Related('<bang>' ,<f-args>)
1506-
command! -buffer -bar -nargs=* -complete=customlist,s:Complete_edit R :call s:Related('<bang>' ,<f-args>)
1507-
command! -buffer -bar -nargs=* -complete=customlist,s:Complete_edit RE :call s:Related('E<bang>',<f-args>)
1508-
command! -buffer -bar -nargs=* -complete=customlist,s:Complete_edit RS :call s:Related('S<bang>',<f-args>)
1509-
command! -buffer -bar -nargs=* -complete=customlist,s:Complete_edit RV :call s:Related('V<bang>',<f-args>)
1510-
command! -buffer -bar -nargs=* -complete=customlist,s:Complete_edit RT :call s:Related('T<bang>',<f-args>)
1511-
command! -buffer -bar -nargs=* -range=0 -complete=customlist,s:Complete_edit RD :call s:Related('<line1>D<bang>',<f-args>)
1505+
command! -buffer -bar -nargs=* -range=0 -complete=customlist,s:Complete_related AN :call s:Related('<bang>' ,<line1>,<line2>,<count>,<f-args>)
1506+
command! -buffer -bar -nargs=* -range=0 -complete=customlist,s:Complete_related R :call s:Related('<bang>' ,<line1>,<line2>,<count>,<f-args>)
1507+
command! -buffer -bar -nargs=* -range=0 -complete=customlist,s:Complete_related RE :call s:Related('E<bang>',<line1>,<line2>,<count>,<f-args>)
1508+
command! -buffer -bar -nargs=* -range=0 -complete=customlist,s:Complete_related RS :call s:Related('S<bang>',<line1>,<line2>,<count>,<f-args>)
1509+
command! -buffer -bar -nargs=* -range=0 -complete=customlist,s:Complete_related RV :call s:Related('V<bang>',<line1>,<line2>,<count>,<f-args>)
1510+
command! -buffer -bar -nargs=* -range=0 -complete=customlist,s:Complete_related RT :call s:Related('T<bang>',<line1>,<line2>,<count>,<f-args>)
1511+
command! -buffer -bar -nargs=* -range=0 -complete=customlist,s:Complete_related RD :call s:Related('D<bang>',<line1>,<line2>,<count>,<f-args>)
15121512
endfunction
15131513

15141514
function! s:djump(def)
@@ -2289,7 +2289,7 @@ function! s:viewEdit(cmd,...)
22892289
if a:0 && a:1 =~ '^[^!#:]'
22902290
let view = matchstr(a:1,'[^!#:]*')
22912291
elseif RailsFileType() == 'controller'
2292-
let view = s:lastmethod()
2292+
let view = s:lastmethod(line('.'))
22932293
else
22942294
let view = ''
22952295
endif
@@ -2783,11 +2783,25 @@ function! s:AlternateFile()
27832783
endif
27842784
endfunction
27852785

2786-
function! s:Related(cmd,...)
2786+
function! s:Complete_related(A,L,P)
2787+
if a:L =~# '^[[:alpha:]]'
2788+
return s:Complete_edit(a:A,a:L,a:P)
2789+
else
2790+
return s:Complete_find(a:A,a:L,a:P)
2791+
endif
2792+
endfunction
2793+
2794+
function! s:Related(cmd,line1,line2,count,...)
27872795
if a:0
2788-
return call('s:Edit',[1,a:cmd]+a:000)
2796+
if a:count && a:cmd !~# 'D'
2797+
return call('s:Find',[1,a:line1.a:cmd]+a:000)
2798+
elseif a:count
2799+
return call('s:Edit',[1,a:line1.a:cmd]+a:000)
2800+
else
2801+
return call('s:Edit',[1,a:cmd]+a:000)
2802+
endif
27892803
else
2790-
let file = s:RelatedFile()
2804+
let file = s:RelatedFile(a:line1)
27912805
if file != ""
27922806
call s:findedit(a:cmd,file)
27932807
else
@@ -2796,15 +2810,15 @@ function! s:Related(cmd,...)
27962810
endif
27972811
endfunction
27982812

2799-
function! s:RelatedFile()
2813+
function! s:RelatedFile(line)
28002814
let f = RailsFilePath()
28012815
let t = RailsFileType()
2802-
let lastmethod = s:lastmethod()
2816+
let lastmethod = a:line ? s:lastmethod(a:line) : ''
28032817
if s:getopt("related","l") != ""
28042818
return s:getopt("related","l")
28052819
elseif t =~ '^\%(controller\|model-mailer\)\>' && lastmethod != ""
28062820
let root = s:sub(s:sub(s:sub(f,'/application\.rb$','/shared_controller.rb'),'/%(controllers|models)/','/views/'),'%(_controller)=\.rb$','/'.lastmethod)
2807-
let format = s:format('html')
2821+
let format = s:format('html',a:line)
28082822
if glob(rails#app().path().'/'.root.'.'.format.'.*[^~]') != ''
28092823
return root . '.' . format
28102824
else
@@ -2817,9 +2831,8 @@ function! s:RelatedFile()
28172831
elseif f == 'README'
28182832
return "config/database.yml"
28192833
elseif f =~ '\<config/database\.yml$'
2820-
let lm = s:lastmethod()
2821-
if lm != ""
2822-
return "config/environments/".lm.".rb\nconfig/environment.rb"
2834+
if lastmethod != ""
2835+
return "config/environments/".lastmethod.".rb"
28232836
else
28242837
return "config/environment.rb"
28252838
endif

0 commit comments

Comments
 (0)