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

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

Re: Interative batch query-replace question


From: Ke Lu
Subject: Re: Interative batch query-replace question
Date: Sun, 02 Dec 2007 11:16:54 +0900
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1.50 (gnu/linux)

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?


reply via email to

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