@@ -46,23 +46,22 @@ func! PhpRefactorExtractMethod()
46
46
return
47
47
endif
48
48
49
- let startLine= line (' v' )
50
- let endLine= line (' .' )
51
- let method= input (' Enter extracted method name: ' )
49
+ let startLine = line (' v' )
50
+ let endLine = line (' .' )
51
+ let method = input (' Enter extracted method name: ' )
52
52
53
53
" check line numbers are the right way around
54
54
if startLine > endLine
55
- let temp= startLine
56
- let startLine= endLine
57
- let endLine= temp
55
+ let temp = startLine
56
+ let startLine = endLine
57
+ let endLine = temp
58
58
endif
59
59
60
- exec ' :!' .g: php_refactor_command
61
- \ .' extract-method'
62
- \ .' %'
63
- \ .' ' .startLine.' -' .endLine
64
- \ .' ' .method
65
- \ .' | ' .g: php_refactor_patch_command
60
+ let range = startLine . ' -' . endLine
61
+
62
+ let args = [range , method]
63
+
64
+ call PhpRefactorRunCommand (' extract-method' , args )
66
65
67
66
" todo : exit visual mode
68
67
endfunc
@@ -74,15 +73,12 @@ func! PhpRefactorLocalVariableToInstanceVariable()
74
73
return
75
74
endif
76
75
77
- let variable= expand (' <cword>' )
78
- let lineNo= line (' .' )
76
+ let variable = expand (' <cword>' )
77
+ let lineNo = line (' .' )
78
+
79
+ let args = [lineNo, variable]
79
80
80
- exec ' :!' .g: php_refactor_command
81
- \ .' convert-local-to-instance-variable'
82
- \ .' %'
83
- \ .' ' .lineNo
84
- \ .' ' .variable
85
- \ .' | ' .g: php_refactor_patch_command
81
+ call PhpRefactorRunCommand (' convert-local-to-instance-variable' , args )
86
82
endfunc
87
83
88
84
func ! PhpRefactorRenameLocalVariable ()
@@ -92,18 +88,13 @@ func! PhpRefactorRenameLocalVariable()
92
88
return
93
89
endif
94
90
95
- let oldName= expand (' <cword>' )
96
- let lineNo= line (' .' )
97
- let newName= input (' Enter new variable name: ' )
91
+ let oldName = expand (' <cword>' )
92
+ let lineNo = line (' .' )
93
+ let newName = input (' Enter new variable name: ' )
98
94
95
+ let args = [lineNo, oldName, newName]
99
96
100
- exec ' :!' .g: php_refactor_command
101
- \ .' rename-local-variable'
102
- \ .' %'
103
- \ .' ' .lineNo
104
- \ .' ' .oldName
105
- \ .' ' .newName
106
- \ .' | ' .g: php_refactor_patch_command
97
+ call PhpRefactorRunCommand (' rename-local-variable' , args )
107
98
endfunc
108
99
109
100
func ! PhpRefactorOptimizeUse ()
@@ -113,10 +104,23 @@ func! PhpRefactorOptimizeUse()
113
104
return
114
105
endif
115
106
116
- exec ' :!' .g: php_refactor_command
117
- \ .' optimize-use'
118
- \ .' %'
119
- \ .' | ' .g: php_refactor_patch_command
107
+ call PhpRefactorRunCommand (' optimize-use' , [])
108
+ endfunc
109
+
110
+ func ! PhpRefactorRunCommand (refactoring, args )
111
+ " Enable autoread to stop prompting for reload
112
+ setlocal autoread
113
+
114
+ let command = ' :!' . g: php_refactor_command
115
+ \ . ' ' . a: refactoring . ' %'
116
+
117
+ for arg in a: args
118
+ let command = command . ' ' . arg
119
+ endfor
120
+
121
+ exec command .' | ' .g: php_refactor_patch_command
122
+
123
+ setlocal noautoread
120
124
endfunc
121
125
122
126
vnoremap <expr> <Leader> rem PhpRefactorExtractMethod()
0 commit comments