From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#20395: 24.3; Documentation for `replace-regexp-in-string' Date: Sat, 25 Apr 2015 12:40:06 +0300 Message-ID: <83r3r8y2a1.fsf@gnu.org> References: <21814.8037.812473.636136@home.barzilay.org> Reply-To: Eli Zaretskii NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1429954884 18040 80.91.229.3 (25 Apr 2015 09:41:24 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 25 Apr 2015 09:41:24 +0000 (UTC) Cc: 20395-done@debbugs.gnu.org To: Eli Barzilay Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Apr 25 11:41:13 2015 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1YlwaF-0004IX-II for geb-bug-gnu-emacs@m.gmane.org; Sat, 25 Apr 2015 11:41:11 +0200 Original-Received: from localhost ([::1]:47781 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YlwaE-0004SU-F3 for geb-bug-gnu-emacs@m.gmane.org; Sat, 25 Apr 2015 05:41:10 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40736) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YlwaB-0004RG-8a for bug-gnu-emacs@gnu.org; Sat, 25 Apr 2015 05:41:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ylwa8-0005rf-2W for bug-gnu-emacs@gnu.org; Sat, 25 Apr 2015 05:41:07 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:49473) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ylwa7-0005rY-Vk for bug-gnu-emacs@gnu.org; Sat, 25 Apr 2015 05:41:04 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1Ylwa7-0002p8-Mc for bug-gnu-emacs@gnu.org; Sat, 25 Apr 2015 05:41:03 -0400 Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-To: bug-gnu-emacs@gnu.org Resent-Date: Sat, 25 Apr 2015 09:41:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: cc-closed 20395 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Mail-Followup-To: 20395@debbugs.gnu.org, eliz@gnu.org, eli@barzilay.org Original-Received: via spool by 20395-done@debbugs.gnu.org id=D20395.142995483110803 (code D ref 20395); Sat, 25 Apr 2015 09:41:02 +0000 Original-Received: (at 20395-done) by debbugs.gnu.org; 25 Apr 2015 09:40:31 +0000 Original-Received: from localhost ([127.0.0.1]:39248 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YlwZb-0002oA-9g for submit@debbugs.gnu.org; Sat, 25 Apr 2015 05:40:31 -0400 Original-Received: from mtaout29.012.net.il ([80.179.55.185]:35616) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YlwZX-0002nt-PH for 20395-done@debbugs.gnu.org; Sat, 25 Apr 2015 05:40:29 -0400 Original-Received: from conversion-daemon.mtaout29.012.net.il by mtaout29.012.net.il (HyperSendmail v2007.08) id <0NNC00300VQDJM00@mtaout29.012.net.il> for 20395-done@debbugs.gnu.org; Sat, 25 Apr 2015 12:38:55 +0300 (IDT) Original-Received: from HOME-C4E4A596F7 ([87.69.4.28]) by mtaout29.012.net.il (HyperSendmail v2007.08) with ESMTPA id <0NNC00J4ZW4UN380@mtaout29.012.net.il>; Sat, 25 Apr 2015 12:38:55 +0300 (IDT) In-reply-to: <21814.8037.812473.636136@home.barzilay.org> X-012-Sender: halo1@inter.net.il X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:102015 Archived-At: > From: Eli Barzilay > Date: Tue, 21 Apr 2015 05:59:01 -0400 > > (In GNU Emacs 24.3.1, but same in git) > > I tried to use `replace-regexp-in-string' like this: > > (let ((text "foo\nbar\nbaz\n") (r "*")) > (replace-regexp-in-string > "\n\\(.\\)" > (lambda (_) (concat "\n" r (match-string 1 text))) > text)) > > and it surprised me that this didn't work. Looking at the docstring, > I found this > > When REP is called, the match data are the result of matching > REGEXP against a substring of STRING. > > and IMO that "a substring" is very subtle and easy to miss. I then > looked at the code, and at least in its current form, I saw that I > could do this instead: > > (let ((text "foo\nbar\nbaz\n") (r "*")) > (replace-regexp-in-string > "\n\\(.\\)" > (lambda (s) (concat "\n" r (match-string 1 s))) > text)) > > So I think that it would be really good if this was made explicit in > the documentation, better with an example. Something like > > When REP is called, the match data are the result of matching > REGEXP against only the currently matched substring of STRING. > For example, (lambda (s) (concat "<" (match-string 1 s) ">")) as > REP is equivalent to "<\\1>". I tried to clarify this issue in a slightly different way.