From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: jadamson@partners.org (Joel J. Adamson) Newsgroups: gmane.emacs.help Subject: Re: Interative batch query-replace question Date: Mon, 03 Dec 2007 10:27:23 -0500 Organization: I need to put my ORGANIZATION here. Message-ID: <87y7cbg5no.fsf@W0053328.mgh.harvard.edu> References: <65e12572-4a77-4f05-ac7a-3e0135279cd2@e25g2000prg.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1196696532 32650 80.91.229.12 (3 Dec 2007 15:42:12 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 3 Dec 2007 15:42:12 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Dec 03 16:42:20 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 1IzDQx-0001An-Pv for geh-help-gnu-emacs@m.gmane.org; Mon, 03 Dec 2007 16:42:12 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IzDQh-00053C-5o for geh-help-gnu-emacs@m.gmane.org; Mon, 03 Dec 2007 10:41:55 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!goblin1!goblin.stu.neva.ru!feed.xsnews.nl!border-2.ams.xsnews.nl!216.196.110.149.MISMATCH!border2.nntp.ams.giganews.com!nntp.giganews.com!uio.no!quimby.gnus.org!news.ccs.neu.edu!news.dfci.harvard.edu!news.harvard.edu!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 55 Original-NNTP-Posting-Host: w0053328.mgh.harvard.edu Original-X-Trace: plato.harvard.edu 1196695643 13527 132.183.29.121 (3 Dec 2007 15:27:23 GMT) Original-X-Complaints-To: news@plato.harvard.edu Original-NNTP-Posting-Date: Mon, 3 Dec 2007 15:27:23 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) Cancel-Lock: sha1:qfa43qiEmN6VKKr9iEg9B+rjQe8= Original-Xref: shelby.stanford.edu gnu.emacs.help:154364 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:49791 Archived-At: Ke Lu writes: > (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)) > ) FYI, you can do this from a shell-script using #!/usr/bin/emacs --script. You can also have interactive and non-interactive versions of the same function. > (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)))) > ))) One suggestion (and I'd be happy to show you my version of the same function): make this a function that processes the alist, instead of directly including the alist, then you can re-use it. For example: (setq replace-list '(("\\$\\(.*?\n*.*?\\)\\$" "\\1") ("sidewaystable" "table") ("\\(\\(\\^\\|_\\){?\\([a-z0-9*.,]+ *\\)\\)}?" "\\3") ("^.*listof.*$" "") ("^.*bibliography.*$" ""))) (jedit-strip-regex replace-list) "jedit-strip-regex" is my function that does the same thing as yours. Joel -- Joel J. Adamson Biostatistician Pediatric Psychopharmacology Research Unit Massachusetts General Hospital Boston, MA 02114 (617) 643-1432 (303) 880-3109