Skip to content

Commit

Permalink
Some fixes searching for Ruby patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
taq committed Nov 17, 2010
1 parent 1b16b97 commit 7702319
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions plugin/vim-refact.vim
Expand Up @@ -7,6 +7,7 @@
"

let b:outside_pattern = ""
let b:check_outside = 0
let b:inside_pattern = ""
let b:start_pattern = ""
let b:end_pattern = ""
Expand All @@ -27,7 +28,8 @@ augroup END

function! s:VimRefactLoadRuby()
let b:outside_pattern = '^\s*\%(def\|class\|module\) '
let b:inside_pattern = '^\s*\%(def\|class\|module\|while\|for\) '
let b:check_outside = 1
let b:inside_pattern = '^\s*\%(def\|class\|module\|while\|for\|do\) '
let b:start_pattern = ''
let b:end_pattern = 'end'
let b:method_pattern = '^\s*def '
Expand Down Expand Up @@ -71,9 +73,14 @@ function! s:VimRefactGetScope()
if strlen(b:outside_pattern)<1
return
endif
let l:ppos = searchpairpos(b:outside_pattern,'',b:end_pattern,"bW")
let l:expr = b:check_outside ? 'getline(".") !~ b:outside_pattern' : 0
let l:ppos = searchpairpos(b:inside_pattern,'',b:end_pattern,"bW",l:expr)
let l:npos = searchpairpos(b:inside_pattern ,'',b:end_pattern,"W")
let l:type = substitute(matchlist(getbufline("%",l:ppos[0])[0],b:outside_pattern)[0]," ","","")
if l:ppos[0]>0 && l:ppos[1]>0 && l:npos[0]>0 && l:npos[1]>0
let l:type = substitute(matchlist(getbufline("%",l:ppos[0])[0],b:outside_pattern)[0]," ","","")
else
let l:type = -1
endif
return [l:ppos,l:npos,l:type]
endfunction

Expand All @@ -91,6 +98,9 @@ function! s:VimRefactExtractMethod(...) range

" get some info
let l:scope = s:VimRefactGetScope()
if l:scope[2]==-1
return
end
let l:size = l:scope[1][0]-l:scope[0][0]
let l:argx = ""
let l:imeth = getbufline("%",l:scope[0][0])[0] =~ b:method_pattern
Expand Down

0 comments on commit 7702319

Please sign in to comment.