"I have a mind like a steel... uh... thingy." Patrick Logan's weblog.

Search This Blog

Sunday, October 19, 2008

Emacs: Query Replace Over Multiple Files

I've received a number of comments on my earlier Query Replace post. Today Kaom Te asked about query replace over multiple files.

One of my favorite shell commands is "find" and in particular, emacs supports "find" as part of its "dired" mode. (dired == directory editing)

Type "meta-x find-dired" and emacs will prompt you through the arguments to "find" multiple files in various ways. The result is a dired buffer listing all the matching files, which you can operate on as with any dired buffer, including query/replace.

The other common way to query and replace over multiple files is to use "tags". Tag files are like indexes you build over various kinds of sources. Tag files can be built for multiple source directories and files in C, Java, Lisp, Erlang, HTML, etc.

Then, of course, there is an emacs function called "tags-query-replace" which will perform a query/replace over the files in your TAGS file with fewer steps than using "find-dired". Tags have many other uses as well since they understand the definitions of the source format, e.g. "meta-." can be used to open a buffer on the definition of the name currently under the cursor ("point" in emacs).

1 comment:

Anonymous said...

Thanks for the response Patrick. I will look into the Tags approach you have suggested.


Blog Archive

About Me

Portland, Oregon, United States
I'm usually writing from my favorite location on the planet, the pacific northwest of the u.s. I write for myself only and unless otherwise specified my posts here should not be taken as representing an official position of my employer. Contact me at my gee mail account, username patrickdlogan.