After reading this thread, I hooked up a small Devel::Refactor script to emacs at the weekend. It works, but I haven't used it seriously, and I'm not convinced it provides a huge productivity leap
Anyway, here's how...
in your .emacs:
(defun refactor-extract ()
"Change region into a subroutine"
(interactive)
(shell-command-on-region (point) (mark) "./refactor-extract" t)
)
and some Perl in refactor-extract:
#!/usr/bin/perl
### Rewrite code block as a subroutine
# This is mostly intended to be used through emacs'
# shell-command-on-region
#
#(defun refactor-extract ()
# "Change region in to a subroutine"
# (interactive)
# (shell-command-on-region (point) (mark) "./refactor-extract" t))
#
#Based on a Perlmonks node: http://www.perlmonks.org/?node_id=622772
use strict;
use warnings FATAL => 'all';
use Devel::Refactor;
my $code = join '', <>;
my $name = "refactored_" . sprintf( "%04d", rand() * 10000 );
print join "\n", Devel::Refactor->new->extract_subroutine( $name, $cod
+e );
use Disclaimer::Std;
This was a quick hack, quickly hacked. Use at your peril. |