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:16:54 +0900 Organization: Bentium Ltd. (CN99) Message-ID: References: <65e12572-4a77-4f05-ac7a-3e0135279cd2@e25g2000prg.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-2022-jp X-Trace: ger.gmane.org 1196563273 5000 80.91.229.12 (2 Dec 2007 02:41:13 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 2 Dec 2007 02:41:13 +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:22 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 1Iyell-000538-9f for geh-help-gnu-emacs@m.gmane.org; Sun, 02 Dec 2007 03:41:21 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IyelV-0002zx-95 for geh-help-gnu-emacs@m.gmane.org; Sat, 01 Dec 2007 21:41:05 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!newsfeed.berkeley.edu!ucberkeley!newsgate.cuhk.edu.hk!news.neu.edu.cn!news.cn99.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 98 Original-NNTP-Posting-Host: softbank218118058050.bbtec.net Original-X-Trace: news.cn99.com 1196566180 5863 218.118.58.50 (2 Dec 2007 03:29:40 GMT) Original-X-Complaints-To: usenet@news.cn99.com Original-NNTP-Posting-Date: Sun, 2 Dec 2007 03:29:40 +0000 (UTC) User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1.50 (gnu/linux) Cancel-Lock: sha1:yu8+7K+OZItsoHURkcNacN0C6wU= Original-Xref: shelby.stanford.edu gnu.emacs.help:154337 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:49765 Archived-At: Hi Xah Lee, Finally I give up call dired-do-query-replace-regexp directly. I did it by the following: (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)))) ))) Thanks all. Xah Lee writes: > Hi Ke Lu, > > what you want to do is exactly what i wanted to do ever since i knew > about dired-do-query-replace-regexp. In summary, you want to use it to > do multiple find-replace pairs. > > (Note: i have (defalias 'ddqrr 'dired-do-query-replace-regexp) > ) > > I don't think you can just slap in several ddqrr in your own function > to achieve multiple find-replace pairs one-shot. Rather, i think you > need to find the function that's behind the interface used by ddqrr. > > Xah > xah@xahlee.org > $B-t(B http://xahlee.org/ > > On Dec 1, 1:11 am, Ke Lu wrote: > Perhaps my explain is not quite enough. > > I want to query-replace some files.(not filename) > > 1. Use find-dired to Find some files.(M-x find-dired) > In "*File" buffer,it looks like: > /home/lu/workspace/: > find . \( -name "*.java" \) -exec ls -ld \{\} \; > -rw-r--r-- 1 lu lu 215 1$B7n(B 21 2003 ejbdemo/DemoEntity.java > -rw-r--r-- 1 lu lu 178 1$B7n(B 21 2003 ejbdemo/DemoSession.java > -rw-r--r-- 1 lu lu 146 1$B7n(B 21 2003 ejbdemo/DemoSessionLocal.java > -rw-r--r-- 1 lu lu 573 1$B7n(B 21 2003 ejbdemo/DemoSessionEJB.java > -rw-r--r-- 1 lu lu 194 1$B7n(B 21 2003 ejbdemo/DemoSessionHome.java > > 2. Mark some file in "*Find*" buffer > In "*File" buffer,it looks like: > /home/lu/workspace/: > find . \( -name "*.java" \) -exec ls -ld \{\} \; > -rw-r--r-- 1 lu lu 215 1$B7n(B 21 2003 ejbdemo/DemoEntity.java > * -rw-r--r-- 1 lu lu 178 1$B7n(B 21 2003 ejbdemo/DemoSession.java > * -rw-r--r-- 1 lu lu 146 1$B7n(B 21 2003 ejbdemo/DemoSessionLocal.java > * -rw-r--r-- 1 lu lu 573 1$B7n(B 21 2003 ejbdemo/DemoSessionEJB.java > -rw-r--r-- 1 lu lu 194 1$B7n(B 21 2003 ejbdemo/DemoSessionHome.java > * -rw-r--r-- 1 lu lu 159 1$B7n(B 21 2003 ejbdemo/ > DemoSessionLocalHome.java > > 3. call batch-query-replace-regexp. > >>> (defun batch-query-replace-regexp() >>> (interactive) >>> (switch-to-buffer "*Find*") >>> (dired-do-query-replace-regexp "jp\\.co" "jp.co2") >>> ->can't reach here (switch-to-buffer "*Find*") >>> (dired-do-query-replace-regexp "java" "java2") > > ...a lot of pattern to query-replace-regexp>> ) > > You can press "Q" key to dired-do-query-replace-regexp once. > But I have about 50 patterns to replace, do it one by one is > quite troublesome. so I copy patterns from excel file > and write them to a function > (which named batch-query-replace-regexp above). > The problem is the function finished when first call > of dired-do-query-replace-regexp finish. > > Doesn't you feel it is strange?