From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eli Barzilay Newsgroups: gmane.emacs.bugs Subject: bug#20395: 24.3; Documentation for `replace-regexp-in-string' Date: Tue, 21 Apr 2015 05:59:01 -0400 Message-ID: <21814.8037.812473.636136@home.barzilay.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1429610450 23976 80.91.229.3 (21 Apr 2015 10:00:50 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 21 Apr 2015 10:00:50 +0000 (UTC) To: 20395@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Apr 21 12:00:36 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 1YkUyo-0003OW-Qd for geb-bug-gnu-emacs@m.gmane.org; Tue, 21 Apr 2015 12:00:35 +0200 Original-Received: from localhost ([::1]:57447 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YkUyn-00062Q-O2 for geb-bug-gnu-emacs@m.gmane.org; Tue, 21 Apr 2015 06:00:33 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57128) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YkUyP-0005Xe-5S for bug-gnu-emacs@gnu.org; Tue, 21 Apr 2015 06:00:10 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YkUyL-000743-Pf for bug-gnu-emacs@gnu.org; Tue, 21 Apr 2015 06:00:09 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:44624) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YkUyL-00073i-NO for bug-gnu-emacs@gnu.org; Tue, 21 Apr 2015 06:00:05 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1YkUyK-0007ww-MC for bug-gnu-emacs@gnu.org; Tue, 21 Apr 2015 06:00:04 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Barzilay Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 21 Apr 2015 10:00:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 20395 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.142961035930468 (code B ref -1); Tue, 21 Apr 2015 10:00:03 +0000 Original-Received: (at submit) by debbugs.gnu.org; 21 Apr 2015 09:59:19 +0000 Original-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 Original-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 Original-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 Original-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 Original-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 Original-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 Original-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 Original-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) Original-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) 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-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:101812 Archived-At: (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!