Skip to content

Commit

Permalink
:Rplugin is now officially a navigation command.
Browse files Browse the repository at this point in the history
Added some helper functions to determine the current format in a controller.
  • Loading branch information
tpope committed Apr 25, 2007
1 parent 35c2004 commit a708e52
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 16 deletions.
14 changes: 7 additions & 7 deletions doc/rails.txt
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ The following commands are not clearly associated with models or controllers.

:Rstylesheet |rails-:Rstylesheet|
:Rjavascript |rails-:Rjavascript|
:Rplugin |rails-:Rplugin|
:Rlib |rails-:Rlib|
:Rtask |rails-:Rtask|
:Rintegrationtest |rails-:Rintegrationtest|
Expand All @@ -421,8 +422,13 @@ The following commands are not clearly associated with models or controllers.
:Rjavascript [{name}] Edit the javascript for the specified name, defaulting
to the current controller's name.

*rails-:Rplugin*
:Rplugin {plugin}[/{path}]
Edits a file within a plugin. If the path to the file
is omitted, it defaults to init.rb.

*rails-:Rlib*
:Rlib [{name}] Edit the library from the lib directory for the
:Rlib {name} Edit the library from the lib directory for the
specified name. If the current file is part of a
plugin, the libraries from that plugin can be
specified as well.
Expand Down Expand Up @@ -513,12 +519,6 @@ A limited amount of completion with <Tab> is supported.
:Rdestroy {options} Calls script/destroy {options}. Respects
|g:rails_subversion|.

*rails-:Rplugin*
:Rplugin {options} Calls script/plugin {options}. Respects
|g:rails_subversion|. Deprecated: use :Rscript plugin
instead (and specify -x yourself if you want a
subversion external).

*rails-:Rserver*
:Rserver {options} Launches script/server {options} in the background.
On win32, this means |!start|. On other systems, this
Expand Down
54 changes: 45 additions & 9 deletions plugin/rails.vim
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ function! s:lastmethodline(...)
let line = line - 1
endwhile
let lend = s:endof(line)
if lend >= line(".")
if lend >= (a:0 ? a:1 : line("."))
return line
else
return 0
Expand All @@ -186,12 +186,46 @@ endfunction
function! s:lastmethod()
let line = s:lastmethodline()
if line
return matchstr(getline(line),'\%('.&define.'\)\zs\k\%(\k\|[:.]\)*[?!=]\=')
return matchstr(getline(line),'\%('.&define.'\)\zs\h\%(\k\|[:.]\)*[?!=]\=')
else
return ""
endif
endfunction

function! s:lastrespondtoline(...)
let mline = s:lastmethodline()
if a:0
let line = a:1
else
let line = line(".")
endif
while line > mline && getline(line) !~ '\C^\s*respond_to\s*\%(\<do\)\s*|\zs\h\k*\ze|'
let line = line - 1
endwhile
let lend = s:endof(line)
if lend >= (a:0 ? a:1 : line("."))
return line
else
return 0
endif
endfunction

function! s:lastformat()
let rline = s:lastrespondtoline()
if rline
let variable = matchstr(getline(rline),'\C^\s*respond_to\s*\%(\<do\|{\)\s*|\zs\h\k*\ze|')
let line = line('.')
while line > rline
let match = matchstr(getline(line),'\C^\s*'.variable.'\s*\.\s*\zs\h\k*')
if match != ''
return match
endif
let line = line - 1
endwhile
endif
return ""
endfunction

function! s:controller(...)
let t = RailsFileType()
let f = RailsFilePath()
Expand Down Expand Up @@ -1222,7 +1256,7 @@ function! s:DestroyComplete(A,L,P)
endfunction

function! s:PluginComplete(A,L,P)
if a:L =~ '^R\%[plugin]\s*\w\+[_/]'
if a:L =~ '^R\%[plugin]\s*[^ ]*\)$'
return s:pluginList(a:A,a:L,a:P)
else
return s:CustomComplete(a:A,a:L,a:P,"plugin")
Expand Down Expand Up @@ -1286,7 +1320,7 @@ function! s:Find(bang,count,arg,...)
let file = s:sub(file,'[@#].*$','')
endif
if file != ""
let file = s:RailsIncludefind(file,1)
let file = s:RailsIncludefind(file)
endif
else
let file = s:RailsFind()
Expand All @@ -1302,7 +1336,7 @@ function! s:Find(bang,count,arg,...)
exe fcmd.' '.str.s:escarg(file)
endif
if tail != ""
silent! exe "djump ".matchstr(tail,'[@#]\zs.*$')
silent! exe "djump ".matchstr(tail,'[@#]\zs[^.]*')
endif
endif
endfunction
Expand Down Expand Up @@ -2231,7 +2265,7 @@ function! s:findedit(cmd,file,...) abort
"silent! file %:~:.
"silent! lcd .
if djump != ''
silent! exe 'djump '.djump
silent! exe 'djump '.matchstr(djump,'[^.]*')
endif
endif
endfunction
Expand Down Expand Up @@ -2298,7 +2332,7 @@ function! s:AlternateFile()
return helper
elseif filereadable(RailsRoot()."/".controller)
let jumpto = expand("%:t:r")
return controller.'@'.jumpto
return controller.'#'.jumpto
"exe "silent! djump ".jumpto
elseif filereadable(RailsRoot()."/".model)
return model
Expand Down Expand Up @@ -2413,8 +2447,10 @@ function! s:RelatedFile()
elseif t =~ '^controller-api\>'
return s:sub(s:sub(f,'/controllers/','/apis/'),'_controller\.rb$','_api.rb')
elseif t =~ '^controller\>'
if s:lastmethod() != ""
return s:sub(s:sub(s:sub(f,'/application\.rb$','/shared_controller.rb'),'/controllers/','/views/'),'_controller\.rb$','/'.s:lastmethod())
let lastmethod = s:lastmethod()
if lastmethod != ""
let root = s:sub(s:sub(s:sub(f,'/application\.rb$','/shared_controller.rb'),'\<app/controllers/','app/views/'),'_controller\.rb$','/'.lastmethod)
return root
else
return s:sub(s:sub(f,'/controllers/','/helpers/'),'\%(_controller\)\=\.rb$','_helper.rb')
endif
Expand Down

0 comments on commit a708e52

Please sign in to comment.