help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: creating a tags file for interactive search and replace regexp


From: Mathias Dahl
Subject: Re: creating a tags file for interactive search and replace regexp
Date: Tue, 20 Jun 2006 11:55:44 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (windows-nt)

"Ryan Krauss" <ryanlists@gmail.com> writes:

> Is there a way to do the dired-do-query-replace-regexp based on marked
> files in the standard buffer list?  The reason I ask is that it is
> very easy for me to use python to open emacs with only the files I
> want (basically doing emacs file1.tex file2.tex ...).  The buffer list
> will already have all the files I want and only the files I want.

I ripped apart dired-do-query-replace-regexp and came up with this:

(defun query-replace-regexp-in-files (from to files &optional delimited)
  "Do `query-replace-regexp' of FROM with TO, on all FILES.
Third arg DELIMITED (prefix arg) means replace only word-delimited matches.
If you exit (\\[keyboard-quit], RET or q), you can resume the query replace
with the command \\[tags-loop-continue]."
  (dolist (file files)
    (let ((buffer (get-file-buffer file)))
      (if (and buffer (with-current-buffer buffer
                        buffer-read-only))
          (error "File `%s' is visited read-only" file))))
  (tags-query-replace from to delimited
                      'files))

Example of usage:

(query-replace-regexp-in-files 
 "from" "to"
 '("c:/tmp/test1.txt"
   "c:/tmp/test2.txt"))

/Mathias


reply via email to

[Prev in Thread] Current Thread [Next in Thread]