Skip to content

Commit

Permalink
fix for issue ecomba#23
Browse files Browse the repository at this point in the history
and setting back original register content
  • Loading branch information
despo committed Jun 1, 2011
1 parent 960fabb commit 02306c7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
16 changes: 16 additions & 0 deletions features/inline_temp.feature
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,19 @@ Feature: Inline Temp :RInlineTemp
puts 10
"""

Scenario: Inline a temporary variable to two variables on the same line
Given I have the following code:
"""
x = 5
y = x and z = x
"""
When I go to the line and execute:
"""
:RInlineTemp
"""
Then I should see:
"""
y = 5 and z = 5
"""
8 changes: 7 additions & 1 deletion plugin/refactorings/general/inlinetemp.vim
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
function! InlineTemp()
" Copy the variable under the cursor into the 'a' register
" XXX: How do I copy into a variable so I don't pollute the registers?
let original_a = @a
normal "ayiw

" It takes 4 diws to get the variable, equal sign, and surrounding
" whitespace. I'm not sure why. diw is different from dw in this
" respect.
normal 4diw
" Delete the expression into the 'b' register
let original_b = @b
normal "bd$

" Delete the remnants of the line
Expand All @@ -21,5 +23,9 @@ function! InlineTemp()
" Find the next occurence of the variable
exec '/\<' . @a . '\>'
" Replace that occurence with the text we yanked
exec ':.s/\<' . @a . '\>/' . @b
exec ':.s/\<' . @a . '\>/' . @b .'/g'

" Put bck original register contents
let @a = original_a
let @b = original_b
endfunction

0 comments on commit 02306c7

Please sign in to comment.