From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: David Kastrup Newsgroups: gmane.emacs.devel Subject: Re: query-replace-interactive not documented Date: 17 Jun 2004 19:03:36 +0200 Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: References: <20040528.181649.25475113.wl@gnu.org> <873c51w5rq.fsf@mail.jurta.org> <87659snbd8.fsf@mail.jurta.org> <87llin98sc.fsf@mail.jurta.org> <87n033y0yj.fsf@mail.jurta.org> <87fz8u19ou.fsf@mail.jurta.org> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: sea.gmane.org 1087491939 27773 80.91.224.253 (17 Jun 2004 17:05:39 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 17 Jun 2004 17:05:39 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Thu Jun 17 19:05:32 2004 Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1Bb0KS-0007GP-00 for ; Thu, 17 Jun 2004 19:05:32 +0200 Original-Received: from lists.gnu.org ([199.232.76.165]) by quimby.gnus.org with esmtp (Exim 3.35 #1 (Debian)) id 1Bb0KS-0007aC-00 for ; Thu, 17 Jun 2004 19:05:32 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1Bb0LV-0003rP-Jw for emacs-devel@quimby.gnus.org; Thu, 17 Jun 2004 13:06:37 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1Bb0LT-0003q7-At for emacs-devel@gnu.org; Thu, 17 Jun 2004 13:06:35 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1Bb0LS-0003pJ-5g for emacs-devel@gnu.org; Thu, 17 Jun 2004 13:06:34 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1Bb0LS-0003pF-2J for emacs-devel@gnu.org; Thu, 17 Jun 2004 13:06:34 -0400 Original-Received: from [199.232.76.164] (helo=fencepost.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.34) id 1Bb0Id-0004Cr-6f for emacs-devel@gnu.org; Thu, 17 Jun 2004 13:03:39 -0400 Original-Received: from localhost ([127.0.0.1] helo=lola.goethe.zz) by fencepost.gnu.org with esmtp (Exim 4.34) id 1Bb0Ib-0007yu-Lk; Thu, 17 Jun 2004 13:03:38 -0400 Original-To: Juri Linkov In-Reply-To: <87fz8u19ou.fsf@mail.jurta.org> Original-Lines: 25 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.4 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:25067 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:25067 --=-=-= Juri Linkov writes: > David Kastrup writes: > > > I have checked in that change now. While I have not given much of a > > time for protests, I want to have a starting point for thinking about > > \?. > > I think your idea about using the replacement string editor for \? > is very good. I hope you will not encounter any obstacles in > implementing it. Here is a sketch. I am calling it a sketch since the string-match for \? should not be done for every replacement again if the replacement string did not contain \? in the first place. This is a performance hog otherwise when doing lots of replacements automatically. If people like it, maybe somebody will volunteer to make it more efficient? --=-=-= Content-Type: text/x-patch Content-Disposition: attachment --- replace.el 17 Jun 2004 16:36:17 +0200 1.173 +++ replace.el 17 Jun 2004 18:55:27 +0200 @@ -1115,6 +1115,24 @@ (aset data 2 (if (consp next) next (aref data 3)))))) (car (aref data 2))) +(defun replace-match-maybe-edit (newtext fixedcase literal &optional match-data) + "Make a replacement with `replace-match', editing `\\?'. +NEXTEXT, FIXEDCASE, LITERAL are just passed on. If MATCH-DATA is handed +in, it is used for the replacement, otherwise the current MATCH-DATA is +used (and saved during editing)." + (unless literal + (unless match-data + (setq match-data (match-data))) + (while (string-match "\\(\\`\\|[^\\]\\)\\(\\\\\\\\\\)*\\(\\\\\\?\\)" + newtext) + (setq newtext + (read-input "Edit replacement string: " + (cons + (replace-match "" t t newtext 3) + (1+ (match-beginning 3))))))) + (if match-data (set-match-data match-data)) + (replace-match newtext fixedcase literal)) + (defun perform-replace (from-string replacements query-flag regexp-flag delimited-flag &optional repeat-count map start end) @@ -1252,8 +1270,8 @@ replace-count))) (if (not query-flag) (let ((inhibit-read-only query-replace-skip-read-only)) - (set-match-data real-match-data) - (replace-match next-replacement nocasify literal) + (replace-match-maybe-edit next-replacement nocasify literal + real-match-data) (setq replace-count (1+ replace-count))) (undo-boundary) (let (done replaced key def) @@ -1300,26 +1318,30 @@ ((eq def 'act) (or replaced (progn - (replace-match next-replacement nocasify literal) + (replace-match-maybe-edit + next-replacement nocasify literal) (setq replace-count (1+ replace-count)))) (setq done t replaced t)) ((eq def 'act-and-exit) (or replaced (progn - (replace-match next-replacement nocasify literal) + (replace-match-maybe-edit + next-replacement nocasify literal) (setq replace-count (1+ replace-count)))) (setq keep-going nil) (setq done t replaced t)) ((eq def 'act-and-show) (if (not replaced) (progn - (replace-match next-replacement nocasify literal) + (replace-match-maybe-edit + next-replacement nocasify literal) (setq replace-count (1+ replace-count)) (setq replaced t)))) ((eq def 'automatic) (or replaced (progn - (replace-match next-replacement nocasify literal) + (replace-match-maybe-edit + next-replacement nocasify literal) (setq replace-count (1+ replace-count)))) (setq done t query-flag nil replaced t)) ((eq def 'skip) @@ -1350,7 +1372,8 @@ (read-input "Edit replacement string: " next-replacement)) (or replaced - (replace-match next-replacement nocasify literal)) + (replace-match-maybe-edit + next-replacement nocasify literal)) (setq done t)) ((eq def 'delete-and-edit) --=-=-= -- David Kastrup, Kriemhildstr. 15, 44793 Bochum --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-devel mailing list Emacs-devel@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-devel --=-=-=--