views:

2261

answers:

4

I'm interested mostly in C++ and method/class name/signature automatic changes.

+2  A: 

A friend of mine was playing with xrefactory and said it worked pretty well. It isn't cheap though.

Greg Rogers
It's not gratis and it's not libre. :(
ashawley
+8  A: 

I do this a lot, so I'm axiously awaiting other replies too.

The only tricks I know are really basic. Here are my best friends in Emacs when refactoring code:

M-x query-replace

This allows you to do a global search and replace. You'll be doing this a ton when you move methods and commonly-accessed data to other classes or namespaces.

C-x 3

This gives you a display with two buffers side-by side. You can then proceed to load different files in them, and move your cursor from one to the other with C-x o. This is pretty basic stuff, but I mention it because of how powerful it makes the next one...

C-x (
(type any amount of stuff and/or emacs commands here)
C-x )

This is how you define a macro in emacs. Any time you find yourself needing to do the same thing over and over to a bunch of code (and it is too complex for query-replace), this is a lifesaver. If you mess up, you can hit C-g to stop the macro definition, and then undo (C-_) until you are back to where you started. The keys to invoke the macro are C-x e. If you want to do it a bunch of times, you can hit Esc and type in a number first. Eg: Esc 100 C-x e will try to invoke your macro 100 times.

(Note: On Windows you can get "Meta" by hitting the Esc key, or holding down Alt).

T.E.D.
There are lots of other good tools as well. See the answer mentioning CEDET. Also, I frequently use TAGS and M-x tags-query-replace to rename all matches to a tags search, which can span source files. See also M-x grep-find, which makes it easy to find all occurrances of a symbol to replace.
slacy
I've tried mucking with tags before. It seemed way more trouble than it was worth. Perhaps during a refactor it would be worth it though?
T.E.D.
But this isn't refactoring. This is manually going through and editing your entire program.
vy32
+10  A: 

If you can program in elisp, you can look to combination of cedet + srecode from CEDET libraries - it provide all instruments for this task - find callers of functions, get signature, etc. But you need to create refactory tool yourself, using these instruments

Alex Ott
Just looking at the CEDET page, this appears to be a much better answer than the one selected...
Jared Oberhaus
(Edited to add the CEDET page link). I'm not sure I disagree with Jared, but I'd have to try it. The "you need to create refactory tool yourself" bit looks kinda omnious though...
T.E.D.
Currently nobody tried to implement refactory tools using Cedet...May be somebody will write them in near future
Alex Ott
+3  A: 

For somewhere in between refactoring tools and simple regex, since Emacs 22 you can embed arbitrary elisp expressions in your replacement text, which allows you to do incredibly powerful text manipulation. Steve Yegge wrote a good article on this a while ago.

jamesnvc
Wow. That totally rocks. I've been using emacs for so long, I never realised they added that.
T.E.D.
Yes, but this isn't refactoring.
vy32