From: Ke Lu <lu@luxdo.jp>
To: help-gnu-emacs@gnu.org
Subject: Re: Interative batch query-replace question
Date: Sun, 02 Dec 2007 11:16:54 +0900 [thread overview]
Message-ID: <m3bq997sdl.fsf@www.luxdo.jp> (raw)
In-Reply-To: 65e12572-4a77-4f05-ac7a-3e0135279cd2@e25g2000prg.googlegroups.com
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 <xah@xahlee.org> 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
> \xAD\xF4 http://xahlee.org/
>
> On Dec 1, 1:11 am, Ke Lu <l...@luxdo.jp> 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月 21 2003 ejbdemo/DemoEntity.java
> -rw-r--r-- 1 lu lu 178 1月 21 2003 ejbdemo/DemoSession.java
> -rw-r--r-- 1 lu lu 146 1月 21 2003 ejbdemo/DemoSessionLocal.java
> -rw-r--r-- 1 lu lu 573 1月 21 2003 ejbdemo/DemoSessionEJB.java
> -rw-r--r-- 1 lu lu 194 1月 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月 21 2003 ejbdemo/DemoEntity.java
> * -rw-r--r-- 1 lu lu 178 1月 21 2003 ejbdemo/DemoSession.java
> * -rw-r--r-- 1 lu lu 146 1月 21 2003 ejbdemo/DemoSessionLocal.java
> * -rw-r--r-- 1 lu lu 573 1月 21 2003 ejbdemo/DemoSessionEJB.java
> -rw-r--r-- 1 lu lu 194 1月 21 2003 ejbdemo/DemoSessionHome.java
> * -rw-r--r-- 1 lu lu 159 1月 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?
next prev parent reply other threads:[~2007-12-02 2:16 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-29 3:08 Interative batch query-replace question Ke Lu
2007-11-29 5:56 ` Ke Lu
2007-11-29 7:37 ` Andreas Röhler
[not found] ` <mailman.4291.1196321879.18990.help-gnu-emacs@gnu.org>
2007-11-29 9:15 ` Ke Lu
2007-11-29 10:18 ` Ke Lu
2007-11-29 20:55 ` Andreas Röhler
[not found] ` <mailman.4324.1196369791.18990.help-gnu-emacs@gnu.org>
2007-11-29 21:16 ` Joel J. Adamson
2007-11-30 1:58 ` Ke Lu
2007-11-30 8:08 ` Andreas Röhler
[not found] ` <mailman.4336.1196410171.18990.help-gnu-emacs@gnu.org>
2007-11-30 9:25 ` Ke Lu
2007-11-30 14:25 ` Joel J. Adamson
2007-11-30 19:33 ` Andreas Röhler
[not found] ` <mailman.4365.1196451256.18990.help-gnu-emacs@gnu.org>
2007-12-01 1:00 ` Ke Lu
2007-12-01 8:19 ` Andreas Röhler
[not found] ` <mailman.4382.1196497198.18990.help-gnu-emacs@gnu.org>
2007-12-01 9:11 ` Ke Lu
2007-12-01 15:19 ` Xah Lee
2007-12-02 2:16 ` Ke Lu [this message]
2007-12-03 15:27 ` Joel J. Adamson
2007-12-01 17:39 ` Andreas Röhler
[not found] ` <mailman.4401.1196530793.18990.help-gnu-emacs@gnu.org>
2007-12-02 2:26 ` Ke Lu
2007-12-03 15:32 ` jedit.el (was: Interative batch query-replace question) Joel J. Adamson
2007-11-29 6:54 ` Interative batch query-replace question Andreas Röhler
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m3bq997sdl.fsf@www.luxdo.jp \
--to=lu@luxdo.jp \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.