From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.devel Subject: dired-do-query-replace-regexp (was: Copyright notices) Date: Thu, 04 Aug 2005 22:59:33 +0300 Organization: JURTA Message-ID: <874qa5h3wu.fsf_-_@jurta.org> References: <17130.41727.178496.468583@farnswood.snap.net.nz> <17132.7450.945474.746680@farnswood.snap.net.nz> <17134.56687.951950.51407@farnswood.snap.net.nz> <87irylk2gh.fsf@jurta.org> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1123186164 26428 80.91.229.2 (4 Aug 2005 20:09:24 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 4 Aug 2005 20:09:24 +0000 (UTC) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Aug 04 22:09:22 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1E0m0d-0006Z7-GX for ged-emacs-devel@m.gmane.org; Thu, 04 Aug 2005 22:08:07 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1E0m3S-0002FS-6r for ged-emacs-devel@m.gmane.org; Thu, 04 Aug 2005 16:11:02 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1E0m2s-00025X-Ld for emacs-devel@gnu.org; Thu, 04 Aug 2005 16:10:27 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1E0m2m-00022P-TV for emacs-devel@gnu.org; Thu, 04 Aug 2005 16:10:21 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1E0m2m-000227-Or for emacs-devel@gnu.org; Thu, 04 Aug 2005 16:10:20 -0400 Original-Received: from [194.126.101.111] (helo=mail.neti.ee) by monty-python.gnu.org with esmtp (Exim 4.34) id 1E0mCQ-0006qp-H2 for emacs-devel@gnu.org; Thu, 04 Aug 2005 16:20:18 -0400 Original-Received: from mail.neti.ee (80-235-42-219-dsl.mus.estpak.ee [80.235.42.219]) by Relayhost2.neti.ee (Postfix) with ESMTP id 393B81F7B for ; Thu, 4 Aug 2005 23:06:55 +0300 (EEST) Original-To: emacs-devel@gnu.org In-Reply-To: <87irylk2gh.fsf@jurta.org> (Juri Linkov's message of "Thu, 04 Aug 2005 20:06:15 +0300") User-Agent: Gnus/5.110004 (No Gnus v0.4) Emacs/22.0.50 (gnu/linux) X-Virus-Scanned: by amavisd-new-2.2.1 (20041222) (Debian) at neti.ee X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:41504 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:41504 > A good interface for mass-replacing is query-replace. You can just do > > M-x find-dired RET -name '*.el' RET t Q > > and use a function call like \,(copyright-fix-years \0) > in the replacement part. BTW, currently `dired-do-query-replace-regexp' doesn't use query-replace history variables. It adds both from-string and to-string to the default history. The following patch allows it to use `query-replace-read-args' to read query-replace arguments. It also replaces too generic argument name `string' with `prompt'. Index: lisp/dired-aux.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/dired-aux.el,v retrieving revision 1.135 diff -c -r1.135 dired-aux.el *** lisp/dired-aux.el 11 Jul 2005 04:24:46 -0000 1.135 --- lisp/dired-aux.el 4 Aug 2005 19:55:22 -0000 *************** *** 2208,2214 **** If you exit (\\[keyboard-quit], RET or q), you can resume the query replace with the command \\[tags-loop-continue]." (interactive ! "sQuery replace in marked files (regexp): \nsQuery replace %s by: \nP") (dolist (file (dired-get-marked-files nil nil 'dired-nondirectory-p)) (let ((buffer (get-file-buffer file))) (if (and buffer (with-current-buffer buffer --- 2210,2219 ---- If you exit (\\[keyboard-quit], RET or q), you can resume the query replace with the command \\[tags-loop-continue]." (interactive ! (let ((common ! (query-replace-read-args ! "Query replace regexp in marked files" t t))) ! (list (nth 0 common) (nth 1 common) (nth 2 common)))) (dolist (file (dired-get-marked-files nil nil 'dired-nondirectory-p)) (let ((buffer (get-file-buffer file))) (if (and buffer (with-current-buffer buffer Index: lisp/replace.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/replace.el,v retrieving revision 1.220 diff -u -r1.220 replace.el --- lisp/replace.el 19 Jul 2005 11:41:20 -0000 1.220 +++ lisp/replace.el 4 Aug 2005 19:55:55 -0000 @@ -88,7 +88,7 @@ (defun query-replace-descr (string) (mapconcat 'isearch-text-char-description string "")) -(defun query-replace-read-from (string regexp-flag) +(defun query-replace-read-from (prompt regexp-flag) "Query and return the `from' argument of a query-replace operation. The return value can also be a pair (FROM . TO) indicating that the user wants to replace FROM with TO." @@ -107,10 +107,10 @@ query-replace-from-history-variable)))) (read-from-minibuffer (if (and lastto lastfrom) - (format "%s (default %s -> %s): " string + (format "%s (default %s -> %s): " prompt (query-replace-descr lastfrom) (query-replace-descr lastto)) - (format "%s: " string)) + (format "%s: " prompt)) nil nil nil query-replace-from-history-variable nil t t)))) @@ -173,22 +173,22 @@ to)) -(defun query-replace-read-to (from string regexp-flag) +(defun query-replace-read-to (from prompt regexp-flag) "Query and return the `to' argument of a query-replace operation." (query-replace-compile-replacement (save-excursion (read-from-minibuffer - (format "%s %s with: " string (query-replace-descr from)) + (format "%s %s with: " prompt (query-replace-descr from)) nil nil nil query-replace-to-history-variable from t t)) regexp-flag)) -(defun query-replace-read-args (string regexp-flag &optional noerror) +(defun query-replace-read-args (prompt regexp-flag &optional noerror) (unless noerror (barf-if-buffer-read-only)) - (let* ((from (query-replace-read-from string regexp-flag)) + (let* ((from (query-replace-read-from prompt regexp-flag)) (to (if (consp from) (prog1 (cdr from) (setq from (car from))) - (query-replace-read-to from string regexp-flag)))) + (query-replace-read-to from prompt regexp-flag)))) (list from to current-prefix-arg))) (defun query-replace (from-string to-string &optional delimited start end) -- Juri Linkov http://www.jurta.org/emacs/