I've been doing a lot of manual patching of baselines at work recently. It has become apparent that emacs is a lot better at patching code than the venerable patch program. However after two aborted baselines that seem to have suffered from me not noticing when C-c C-a fails I though I'd better take advantage of the programmable nature of my editor. It actually took me about 5 minutes to prototype the function. It took a little longer to get a bullet-proof function I could include in my .emacs (including accidentally shutting down emacs twice with an unsaved *scratch* buffer). Although I'm sure it's not the neatest code I think I'm well over the learning hump required for knocking simple stuff up.