From debbugs-submit-bounces@debbugs.gnu.org Tue Apr 21 05:59:19 2015 Received: (at submit) by debbugs.gnu.org; 21 Apr 2015 09:59:19 +0000 Received: from localhost ([127.0.0.1]:34400 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YkUxa-0007vL-SX for submit@debbugs.gnu.org; Tue, 21 Apr 2015 05:59:19 -0400 Received: from eggs.gnu.org ([208.118.235.92]:43420) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YkUxY-0007v7-Ho for submit@debbugs.gnu.org; Tue, 21 Apr 2015 05:59:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YkUxS-0006c0-Fe for submit@debbugs.gnu.org; Tue, 21 Apr 2015 05:59:11 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50 autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:40311) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YkUxS-0006bv-DV for submit@debbugs.gnu.org; Tue, 21 Apr 2015 05:59:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56921) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YkUxR-00051U-FW for bug-gnu-emacs@gnu.org; Tue, 21 Apr 2015 05:59:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YkUxO-0006aq-AH for bug-gnu-emacs@gnu.org; Tue, 21 Apr 2015 05:59:09 -0400 Received: from mail-qk0-f173.google.com ([209.85.220.173]:36675) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YkUxO-0006aZ-6d for bug-gnu-emacs@gnu.org; Tue, 21 Apr 2015 05:59:06 -0400 Received: by qku63 with SMTP id 63so207274703qku.3 for ; Tue, 21 Apr 2015 02:59:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:mime-version:content-type :content-transfer-encoding:message-id:date:to:subject; bh=v1qhJUG+zFUOIeV+e+PujgGs4snhm08sGi1AaOv/qJc=; b=NutWP2DmrXL8p8ZCkRT+kNyRcKkhFOQ8014nqSQLd3ZIvRKUF6NIE+GPpJXWRGSq7U E11dOwdj7g2Rn4zAwRuX4mp6YxnLZTiellOBhVG/B7Dgrr9/Kkzh1f1dL29I40OKQa4t bdBl2rNcm2P34ZQb8w580U6lFZBw8fObwMwPSPV973ujpQffibwvVx25mSMusmaKCdXF blU0r4u7A+XH/GTh+daMXC2xXylyaaMmy+f3Yg++zY+cDeKjvgB8Wo4OiWS0+9w+bVsc 7O6yMJ7A0OUui9RUWSKKJ/r0MhHV3PYR4UDq/xxvRzEZcDFskT9TG9udwX3tvmRk1424 m2KA== X-Gm-Message-State: ALoCoQmHLVwTBfLtKflL8OKrVdUIWtFjFPzNPRtV5IPiygJwWJw4jAeYqsRNJGeetEg21Z/JWisF X-Received: by 10.55.20.132 with SMTP id 4mr36849417qku.104.1429610344437; Tue, 21 Apr 2015 02:59:04 -0700 (PDT) Received: from home.barzilay.org (c-24-60-254-179.hsd1.ma.comcast.net. [24.60.254.179]) by mx.google.com with ESMTPSA id f35sm1032182qga.10.2015.04.21.02.59.02 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Apr 2015 02:59:03 -0700 (PDT) From: Eli Barzilay MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <21814.8037.812473.636136@home.barzilay.org> Date: Tue, 21 Apr 2015 05:59:01 -0400 To: bug-gnu-emacs@gnu.org Subject: 24.3; Documentation for `replace-regexp-in-string' X-Mailer: VM 8.2.0a under 24.3.1 (x86_64-redhat-linux-gnu) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -4.0 (----) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -4.0 (----) (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>". -- ((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay: http://barzilay.org/ Maze is Life! From debbugs-submit-bounces@debbugs.gnu.org Tue Apr 21 11:00:17 2015 Received: (at 20395) by debbugs.gnu.org; 21 Apr 2015 15:00:17 +0000 Received: from localhost ([127.0.0.1]:35410 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YkZeq-0008Km-21 for submit@debbugs.gnu.org; Tue, 21 Apr 2015 11:00:16 -0400 Received: from mtaout20.012.net.il ([80.179.55.166]:40287) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YkZem-0008KO-6n for 20395@debbugs.gnu.org; Tue, 21 Apr 2015 11:00:14 -0400 Received: from conversion-daemon.a-mtaout20.012.net.il by a-mtaout20.012.net.il (HyperSendmail v2007.08) id <0NN500M00W6D3K00@a-mtaout20.012.net.il> for 20395@debbugs.gnu.org; Tue, 21 Apr 2015 18:00:05 +0300 (IDT) Received: from HOME-C4E4A596F7 ([87.69.4.28]) by a-mtaout20.012.net.il (HyperSendmail v2007.08) with ESMTPA id <0NN500LQNWC5RSA0@a-mtaout20.012.net.il>; Tue, 21 Apr 2015 18:00:05 +0300 (IDT) Date: Tue, 21 Apr 2015 18:00:01 +0300 From: Eli Zaretskii Subject: Re: bug#20395: 24.3; Documentation for `replace-regexp-in-string' In-reply-to: <21814.8037.812473.636136@home.barzilay.org> X-012-Sender: halo1@inter.net.il To: Eli Barzilay Message-id: <83383t5xxq.fsf@gnu.org> References: <21814.8037.812473.636136@home.barzilay.org> X-Spam-Score: 1.0 (+) X-Debbugs-Envelope-To: 20395 Cc: 20395@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Eli Zaretskii List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 1.0 (+) > From: Eli Barzilay > Date: Tue, 21 Apr 2015 05:59:01 -0400 > > 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>". Thanks. However, I wonder whether your suggested change is really enough of an improvement. AFAIU, the main problem with the existing doc string is that it doesn't explain _which_ substring is being alluded to here, it only hints on the answer. And your suggested change also leaves that part unexplained, leaving it to the reader to glean that from the fact that 'concat' is being used. So I think it would be good to come up with text that actually makes that part clear. WDYT? From debbugs-submit-bounces@debbugs.gnu.org Sat Apr 25 05:40:31 2015 Received: (at 20395-done) by debbugs.gnu.org; 25 Apr 2015 09:40:31 +0000 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 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 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) 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) Date: Sat, 25 Apr 2015 12:40:06 +0300 From: Eli Zaretskii Subject: Re: bug#20395: 24.3; Documentation for `replace-regexp-in-string' In-reply-to: <21814.8037.812473.636136@home.barzilay.org> X-012-Sender: halo1@inter.net.il To: Eli Barzilay Message-id: <83r3r8y2a1.fsf@gnu.org> References: <21814.8037.812473.636136@home.barzilay.org> X-Spam-Score: 1.0 (+) X-Debbugs-Envelope-To: 20395-done Cc: 20395-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Eli Zaretskii List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 1.0 (+) > 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. From unknown Tue Jun 24 05:14:28 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Sat, 23 May 2015 11:24:06 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator