1

Possible Duplicate:
Using Emacs to recursively find and replace in text files not already open

Duplicate: using-emacs-to-recursively-find-and-replace-in-text-files-not-already-open

I need to to regexp search and replace on a list of files. Is there an emacs command (command combo) for that? Or maybe you have a better way to do c++ refactoring on linux?

Community
  • 1
  • 1
Łukasz Lew
  • 48,526
  • 41
  • 139
  • 208
  • 1
    Look at Using Emacs to recursively find and replace in text files not already open (http://stackoverflow.com/questions/270930/using-emacs-to-recursively-find-and-replace-in-text-files-not-already-open). – Blair Conrad Jun 03 '09 at 11:07
  • 1
    Is there a reason why this needs to be done in emacs as opposed to another tool, such as sed? – Dan Moulding Jun 03 '09 at 11:33
  • 2
    Because everything is better when it is done in emacs. – Cheeso Jun 03 '09 at 12:11

2 Answers2

3

You can mark files in dired or ibuffer and query-replace-regexp on them. Otherwise why not use the shell with some find and sed magic, a la:

for f in $(find . -name "*.cpp"); do
    mv $f $f.bak
    sed -e "s/old/new/g" $f.bak > $f
done
danielpoe
  • 3,756
  • 23
  • 18
  • Seriously? you can do query-replace-regexp on marked files in dired? Good to know! – Cheeso Jun 03 '09 at 12:09
  • 2
    yes just mark the files you want to work on with `m` and then run query-replace-regexp using `Q`. Quite cool :) – danielpoe Jun 03 '09 at 13:14
  • You can also iterate over marked files in a dired buffer using dired-get-marked-files. I show an example in this blog post: http://justinsboringpage.blogspot.com/2009/04/running-elisp-function-on-each-marked.html – justinhj Jun 03 '09 at 16:29
2

Have you looked into XRefactory?

Hank Gay
  • 70,339
  • 36
  • 160
  • 222