Skip to content

Instantly share code, notes, and snippets.

@Sodaware
Created March 7, 2013 01:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sodaware/5104696 to your computer and use it in GitHub Desktop.
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.
(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