Skip to content

Commit

Permalink
fix for variables within the context of a method
Browse files Browse the repository at this point in the history
also fixes issue ecomba#24
  • Loading branch information
despo committed Jun 1, 2011
1 parent a429761 commit d86f9e0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
4 changes: 2 additions & 2 deletions features/inline_temp.feature
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ Feature: Inline Temp :RInlineTemp
"""

@issues @wip
Scenario: Inline a temporary variable to all variables within the context of a method
Given I have the following code:
"""
Expand Down Expand Up @@ -67,9 +66,9 @@ Feature: Inline Temp :RInlineTemp
x = 2
y = x + 1
end
"""

@issues
Scenario: Inline a temporary variable to all variables within the context of a method
Given I have the following code:
"""
Expand All @@ -87,4 +86,5 @@ Feature: Inline Temp :RInlineTemp
foo = 5 + 10
x = 10
bar = x + 10
"""
15 changes: 7 additions & 8 deletions plugin/refactorings/general/inlinetemp.vim
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@ function! InlineTemp()

" Delete the remnants of the line
normal dd
" Go to the end of the previous line so we can start our search for the
" usage of the variable to replace. Doing '0' instead of 'k$' doesn't
" work; I'm not sure why.
normal k$
" Find the next occurence of the variable
exec '/\<' . @a . '\>'
" Replace that occurence with the text we yanked
exec ':.s/\<' . @a . '\>/' . @b .'/g'

" Find the start and end of the current block
" TODO: tidy up if no matching 'def' found (start would be 0 atm)
let [block_start, block_end] = common#get_range_for_block('\<def\>','Wb')

" Rename the variable within the range of the block
call common#gsub_all_in_range(block_start, block_end, '\<' . @a . '\>', @b)

" Put bck original register contents
let @a = original_a
Expand Down

0 comments on commit d86f9e0

Please sign in to comment.