Skip to content

Commit 2c355fd

Browse files
committed
Allow deeper projections to override built-in navigation commands
References tpope#505
1 parent 113151e commit 2c355fd

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

autoload/rails.vim

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2755,26 +2755,31 @@ endfunction
27552755

27562756
call s:add_methods('app', ['commands'])
27572757

2758-
function! s:addfilecmds(type) abort
2758+
function! s:addfilecmds(type, defer) abort
27592759
let l = s:sub(a:type,'^.','\l&')
27602760
let cplt = " -complete=customlist,".s:sid.l."List"
2761+
if a:defer && exists(':E' . l) == 2
2762+
return
2763+
endif
27612764
for prefix in ['E', 'S', 'V', 'T', 'D']
27622765
exe "command! -buffer -bar ".(prefix =~# 'D' ? '-range=0 ' : '')."-nargs=*".cplt." ".prefix.l." :execute s:".l.'Edit("<mods> '.(prefix =~# 'D' ? '<line1>' : '').s:sub(prefix, '^R', '').'<bang>",<f-args>)'
27632766
endfor
27642767
endfunction
27652768

27662769
function! s:BufProjectionCommands() abort
2767-
call s:addfilecmds("view")
2768-
call s:addfilecmds("migration")
2769-
call s:addfilecmds("schema")
2770-
call s:addfilecmds("layout")
2771-
call s:addfilecmds("fixtures")
2772-
call s:addfilecmds("locale")
2770+
let deepest = get(sort(keys(get(b:, 'projectionist', {})), 'rails#lencmp'), -1, '')
2771+
let defer = len(deepest) > len(rails#app().path())
2772+
call s:addfilecmds("view", defer)
2773+
call s:addfilecmds("migration", defer)
2774+
call s:addfilecmds("schema", defer)
2775+
call s:addfilecmds("layout", defer)
2776+
call s:addfilecmds("fixtures", defer)
2777+
call s:addfilecmds("locale", defer)
27732778
if rails#app().has('spec')
2774-
call s:addfilecmds("spec")
2779+
call s:addfilecmds("spec", defer)
27752780
endif
2776-
call s:addfilecmds("stylesheet")
2777-
call s:addfilecmds("javascript")
2781+
call s:addfilecmds("stylesheet", defer)
2782+
call s:addfilecmds("javascript", defer)
27782783
for [name, command] in items(rails#app().commands())
27792784
call s:define_navcommand(name, command)
27802785
endfor
@@ -2904,7 +2909,7 @@ function! s:specList(A,L,P)
29042909
return s:completion_filter(rails#app().relglob("spec/","**/*","_spec.rb"),a:A)
29052910
endfunction
29062911

2907-
function! s:define_navcommand(name, projection, ...) abort
2912+
function! s:define_navcommand(name, projection) abort
29082913
if empty(a:projection)
29092914
return
29102915
endif
@@ -2918,8 +2923,7 @@ function! s:define_navcommand(name, projection, ...) abort
29182923
\ '-complete=customlist,'.s:sid.'CommandList ' .
29192924
\ prefix . name . ' :execute s:CommandEdit(' .
29202925
\ string('<mods> '.(prefix =~# 'D' ? '<line1>' : '') . prefix . "<bang>") . ',' .
2921-
\ string(a:name) . ',' . string(a:projection) . ',<f-args>)' .
2922-
\ (a:0 ? '|' . a:1 : '')
2926+
\ string(a:name) . ',' . string(a:projection) . ',<f-args>)'
29232927
endfor
29242928
endfunction
29252929

0 commit comments

Comments
 (0)