Created
March 7, 2013 01:05
-
-
Save Sodaware/5104696 to your computer and use it in GitHub Desktop.
A function for refactoring PHP code. Extracts the currently marked region and moves it to a new function.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun php-extract-function (start end name) | |
"Moves the currently marked text to a new function" | |
;; Prompt for new method name | |
(interactive "r\nsNew Function Name: ") | |
;; Kill selected region | |
(kill-region start end) | |
;; Insert call to new function | |
(insert "\n" name "();\n") | |
;; Set a marker so we can jump back to this line | |
(point-to-register 1) | |
;; Move to end of current function | |
(php-end-of-defun) | |
;; Insert new function | |
(insert "\n\nfunction " name "()\n{\n" | |
(car kill-ring-yank-pointer) | |
"\n}\n") | |
;; Jump back to where function was snipped from | |
(jump-to-register 1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment