From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: David Kastrup Newsgroups: gmane.emacs.devel Subject: Re: regexp repacement, how to present replacement to user? Date: Mon, 15 Oct 2007 07:57:31 +0200 Message-ID: <85y7e4j4xg.fsf@lola.goethe.zz> References: <200710131700.42100.pogonyshev@gmx.net> <87y7e51fc6.fsf@jurta.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1192427912 23075 80.91.229.12 (15 Oct 2007 05:58:32 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 15 Oct 2007 05:58:32 +0000 (UTC) Cc: Juri Linkov , Paul Pogonyshev , emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Oct 15 07:58:23 2007 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1IhIwr-0004AR-43 for ged-emacs-devel@m.gmane.org; Mon, 15 Oct 2007 07:57:05 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IhIwk-0007vq-I6 for ged-emacs-devel@m.gmane.org; Mon, 15 Oct 2007 01:56:58 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1IhIwg-0007vg-Q0 for emacs-devel@gnu.org; Mon, 15 Oct 2007 01:56:54 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1IhIwf-0007vU-MJ for emacs-devel@gnu.org; Mon, 15 Oct 2007 01:56:54 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IhIwf-0007vR-JA for emacs-devel@gnu.org; Mon, 15 Oct 2007 01:56:53 -0400 Original-Received: from fencepost.gnu.org ([140.186.70.10]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1IhIwf-0000sb-8w for emacs-devel@gnu.org; Mon, 15 Oct 2007 01:56:53 -0400 Original-Received: from localhost ([127.0.0.1] helo=lola.goethe.zz) by fencepost.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1IhIwe-0006cB-F4; Mon, 15 Oct 2007 01:56:52 -0400 Original-Received: by lola.goethe.zz (Postfix, from userid 1002) id 33D851C4D4B3; Mon, 15 Oct 2007 07:57:31 +0200 (CEST) In-Reply-To: (Stefan Monnier's message of "Sun\, 14 Oct 2007 23\:20\:15 -0400") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1.50 (gnu/linux) X-detected-kernel: by monty-python.gnu.org: Linux 2.6, seldom 2.4 (older, 4) 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:80896 Archived-At: Stefan Monnier writes: >> (let ((from "\\([[:alpha:]]+\\)-\\([[:alpha:]]+\\)") >> (to "\\1 \\2")) >> (while (re-search-forward from nil t) >> (if (y-or-n-p (format "Replace %s with %s " >> (match-string 0) >> (replace-regexp-in-string from to (match-string 0)))) >> (replace-match to nil nil)))) > > This work 99% with the last 1% being due to failure in boundary conditions > (e.g. if the pattern starts with "\\>"). (while (re-search-forward from nil t) (if y-or-n-p (format "Replace %s with %s " (match-string 0) (save-match-data (replace-match to nil nil (match-string 0) (prog1 nil (set-match-data (mapcar (lambda(x)(if (numberp x) (- x (match-beginning 0)) x))) (match-data t))) [...] -- David Kastrup, Kriemhildstr. 15, 44793 Bochum