Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re^2: Refactoring copy-pasted code

by jvector (Friar)
on May 07, 2009 at 16:46 UTC ( [id://762662] : note . print w/replies, xml ) Need Help??

in reply to Re: Refactoring copy-pasted code
in thread Refactoring copy-pasted code

I have found the 'ediff' code-merging tools within Emacs useful for situations that are kind of like yours. There is an 'ediff-buffers' command that splits the screen highlighting the detected differences between the code in two edit buffers, and allows you to step through the list of differences. Single keystrokes 'a','b' will put what is in buffer A into the corresponding difference in buffer B, and vice versa. There are many other things you can do in this mode as well. Emacs also provides 'ediff-buffers3' which does 3 files at once, and 'ediff-directories' which sets up a 'session' going through all the files in a pair of directories. I might feel inclined to load up scripts A and B, copy one of them to a new file AB, and manually construct AB to be an abstracted union of the two. You could then do the same with script C, then D...

Hey!! Wait! This isn't my signature!!