From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ke Lu Newsgroups: gmane.emacs.help Subject: Re: Interative batch query-replace question Date: Sun, 02 Dec 2007 11:26:08 +0900 Organization: Bentium Ltd. (CN99) Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1196563305 5039 80.91.229.12 (2 Dec 2007 02:41:45 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 2 Dec 2007 02:41:45 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Dec 02 03:41:54 2007 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1IyemH-00059p-UE for geh-help-gnu-emacs@m.gmane.org; Sun, 02 Dec 2007 03:41:54 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Iyem1-0003U6-VT for geh-help-gnu-emacs@m.gmane.org; Sat, 01 Dec 2007 21:41:38 -0500 Original-Path: shelby.stanford.edu!headwall.stanford.edu!newsfeed.news2me.com!news.glorb.com!news.neu.edu.cn!news.cn99.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 69 Original-NNTP-Posting-Host: softbank218118058050.bbtec.net Original-X-Trace: news.cn99.com 1196566734 5863 218.118.58.50 (2 Dec 2007 03:38:54 GMT) Original-X-Complaints-To: usenet@news.cn99.com Original-NNTP-Posting-Date: Sun, 2 Dec 2007 03:38:54 +0000 (UTC) User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1.50 (gnu/linux) Cancel-Lock: sha1:ejW/rIbDXuHxOR7n0wTBW9MvACA= Original-Xref: shelby.stanford.edu gnu.emacs.help:154338 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:49766 Archived-At: Thank you very much. It is true,we needs two task. > 1 - find the list of files I do it by find-dired and mark it because find-dired using os command "find" to find file and is powerful. > 2 - operate on them I do it by my-proc-one-query-replace-regexp. (defun my-proc-one-query-replace-regexp (files from to) (dolist (cur-file files) (find-file cur-file) (goto-char 0) (query-replace-regexp from to)) ) (defun my-batch-query-replace-regexp() "Muti-pattern query-replace-regrex on a dozen of files. It must be called in dired buffer. Mark some files then you can call this function." (interactive) (let ((files (dired-get-marked-files nil nil (lambda (file) (not (file-directory-p file))))) (patterns '(("ejb" . "ejb2") ("java" . "java2") ("sun2" . "sun3") ;; Add any other patterns ))) (when files (while patterns (let ((pattern (car patterns))) (my-proc-one-query-replace-regexp files (car pattern) (cdr pattern)) (setq patterns (cdr patterns)))) ))) Andreas Röhler writes: > Am Samstag, 1. Dezember 2007 10:11 schrieb Ke Lu: >> Perhaps my explain is not quite enough. >> >> I want to query-replace some files.(not filename) > ... > > > So we have basically two tasks > > 1 - find the list of files > 2 - operate on them > > Dired probably isn't TRT here, because it's for > manually operation. > > Maybe run this at your dir to have some impression how > it may start: > > (defun my-list-of-files () > " " > (interactive) > (let ((my-endings-list '(".co$" ".java$"))) > (dolist (el my-endings-list) > (let ((files (directory-files default-directory t el))) > (while files > (let ((file (car files))) > (when (file-exists-p file) > (when (y-or-n-p (concat "You agree to change \""file"\" later"))) > (message "Later we will change name and contents of %s " file)) > (setq files (cdr files)))))))) > > > Andreas Röhler