From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Paul Pogonyshev Newsgroups: gmane.emacs.devel Subject: Re: regexp repacement, how to present replacement to user? Date: Mon, 15 Oct 2007 23:28:54 +0300 Message-ID: <200710152328.55144.pogonyshev@gmx.net> References: <200710131700.42100.pogonyshev@gmx.net> <85y7e4j4xg.fsf@lola.goethe.zz> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1192482027 10772 80.91.229.12 (15 Oct 2007 21:00:27 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 15 Oct 2007 21:00:27 +0000 (UTC) Cc: Juri Linkov , Stefan Monnier To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Oct 15 23:00:18 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 1IhWG3-0005N6-Eb for ged-emacs-devel@m.gmane.org; Mon, 15 Oct 2007 22:09:47 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IhWFw-00005a-BR for ged-emacs-devel@m.gmane.org; Mon, 15 Oct 2007 16:09:40 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1IhWFt-0008VL-In for emacs-devel@gnu.org; Mon, 15 Oct 2007 16:09:37 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1IhWFr-0008Ry-48 for emacs-devel@gnu.org; Mon, 15 Oct 2007 16:09:37 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IhWFq-0008Rm-UU for emacs-devel@gnu.org; Mon, 15 Oct 2007 16:09:35 -0400 Original-Received: from mail.gmx.net ([213.165.64.20]) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1IhWFq-0003vH-B1 for emacs-devel@gnu.org; Mon, 15 Oct 2007 16:09:34 -0400 Original-Received: (qmail invoked by alias); 15 Oct 2007 20:09:32 -0000 Original-Received: from unknown (EHLO [80.94.234.96]) [80.94.234.96] by mail.gmx.net (mp058) with SMTP; 15 Oct 2007 22:09:32 +0200 X-Authenticated: #16844820 X-Provags-ID: V01U2FsdGVkX1+mZhUZC1KmkopfV42FtvUt0UuLG13sdI3N3coVo6 GyJb/a/ZYys2hv User-Agent: KMail/1.7.2 In-Reply-To: <85y7e4j4xg.fsf@lola.goethe.zz> Content-Disposition: inline X-Y-GMX-Trusted: 0 X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 1) 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:80960 Archived-At: David Kastrup wrote: > 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))) Thanks, but shouldn't this be a function somewhere? I mean, it's not like random peope are going to easily write such code. Besides, what if Emacs regexps are slightly improved with more features, like named groups or whatnot? Paul