[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:26:08 +0900 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.1.50 (gnu/linux) |
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 <andreas.roehler@online.de> 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