From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: zhanghj Newsgroups: gmane.emacs.devel Subject: Re: query-replace-regexp: Can't use \0 in TO-STRING Date: Sun, 07 May 2017 11:55:15 +0800 Message-ID: <87bmr5micc.fsf@gmail.com> References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1494129359 3680 195.159.176.226 (7 May 2017 03:55:59 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 7 May 2017 03:55:59 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) Cc: netjune@qq.com, Emacs developers To: Tino Calancha Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun May 07 05:55:56 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d7DIa-0000u3-2e for ged-emacs-devel@m.gmane.org; Sun, 07 May 2017 05:55:56 +0200 Original-Received: from localhost ([::1]:53556 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d7DIf-0001pJ-Of for ged-emacs-devel@m.gmane.org; Sat, 06 May 2017 23:56:01 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:38374) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d7DI4-0001nv-AA for emacs-devel@gnu.org; Sat, 06 May 2017 23:55:25 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d7DI1-0007T2-3W for emacs-devel@gnu.org; Sat, 06 May 2017 23:55:24 -0400 Original-Received: from mail-pg0-x242.google.com ([2607:f8b0:400e:c05::242]:36050) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d7DI0-0007Sa-Sx for emacs-devel@gnu.org; Sat, 06 May 2017 23:55:21 -0400 Original-Received: by mail-pg0-x242.google.com with SMTP id q4so2514424pga.3 for ; Sat, 06 May 2017 20:55:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:cc:date:in-reply-to:message-id :user-agent:mime-version; bh=XuEMt7GIKX79q1RCi9/ZXVz53V0JohD/VQWdf0ThgSY=; b=W8B4NFbQu0YYFwqZkOpq6CNCESag8sFivcN3KNZbjHdK9TLHsL/Y+EIULvInZbxJdM pNgmkrjh7TAHI/8SyjpQTvPhYSgcDKQAx93lfeuH1fZyBCLdFe9AORoMtA4hy4uJdDRZ wqyA3/qNX+FjNNCXdiwEj6iR+6lNP1rjGALgfZUQiO620Dzj2ExTJjQ4XW0a1CSzRSte /hkm9qPV/R3kgVKHY9Q2lschvwpjYS7G1sgBEKTp0+AlR3mW+ZHehiJVJbJdHaQVfQq0 jKKZA5bW+bWT+wYdVffcPngo8jmXKwNdmDvo1wIrRbZ4Klth8i3hjT8q3bsLj/VTHQH/ hcsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:cc:date :in-reply-to:message-id:user-agent:mime-version; bh=XuEMt7GIKX79q1RCi9/ZXVz53V0JohD/VQWdf0ThgSY=; b=bV6BOXgTE0rqcxh45IHwZjZwmtSA7HMnRUIV+2QRX/Zgi8mb+9hwisVrkpqWexSb8K qeDvNs2nLTq8cimy4s/ivf/siYTDo9EtCP1GjJr8sQDXoEmOGfy0Bba7XLR5YiWHhNkn z9vpEvKL9uDwyKPLf+YviBI9LM+FNmZqhQ3xoqU3CKD1PdliZGlPJxaZxKeLJEB7UaN4 k0O9zP5yV+tsWD48DU68F2+nWie4Droy0gPY5KUUn0zpmHImHp3cgLjreo6c/SKcxQQv 08AbzkuypNa1mVjYXHbbMGwEifw0WPrSncf3Cdxsfpq5IID1nNuOjNJEmIkLo6sn5Hgq N0tg== X-Gm-Message-State: AN3rC/6u3NrnWkn9yBOFTf0U9zmex6h+ycxwmh1P4MXVUVXimTXmDbpA UDCvD1hbWzAn+g== X-Received: by 10.84.233.131 with SMTP id l3mr38652877plk.18.1494129319916; Sat, 06 May 2017 20:55:19 -0700 (PDT) Original-Received: from junlinux ([122.225.224.236]) by smtp.gmail.com with ESMTPSA id r131sm13198037pgr.67.2017.05.06.20.55.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 06 May 2017 20:55:19 -0700 (PDT) In-Reply-To: (Tino Calancha's message of "Sat, 6 May 2017 21:39:25 +0900 (JST)") X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::242 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:214649 Archived-At: Tino Calancha writes: >> Why not \0? I think \0 is more intuitive and also used in vim. > I agree is more intuitive, and it works in `replace-match', or instance: > (mapcar > (lambda (group) > (let ((str "foo123")) > (when (string-match "[a-z]+\\([1-9]+\\)" str) > (replace-match "bar" nil nil str group)))) > (list 0 1)) > => ("bar" "foobar") > > Are you willing to write a patch to implement it? The following patch works on my machine for regexp replacing. But I don't known if \0 should be supported in other places such as sort-regexp-fields, occur. diff --git a/lisp/subr.el b/lisp/subr.el index 02e7993..c182128 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -3634,7 +3634,7 @@ match-string-no-properties (defun match-substitute-replacement (replacement &optional fixedcase literal string subexp) "Return REPLACEMENT as it will be inserted by `replace-match'. -In other words, all back-references in the form `\\&' and `\\N' +In other words, all back-references in the form `\\&', `\\0' and `\\N' are substituted with actual strings matched by the last search. Optional FIXEDCASE, LITERAL, STRING and SUBEXP have the same meaning as for `replace-match'." diff --git a/src/search.c b/src/search.c index 1223cbf..86255f0 100644 --- a/src/search.c +++ b/src/search.c @@ -2339,7 +2339,7 @@ in the replaced text, capitalize each word in NEWTEXT. If optional third arg LITERAL is non-nil, insert NEWTEXT literally. Otherwise treat `\\' as special: - `\\&' in NEWTEXT means substitute original matched text. + `\\&' or `\\0' in NEWTEXT means substitute original matched text. `\\N' means substitute what matched the Nth `\\(...\\)'. If Nth parens didn't match, substitute nothing. `\\\\' means insert one `\\'. @@ -2523,7 +2523,7 @@ since only regular expressions have distinguished subexpressions. */) { FETCH_STRING_CHAR_ADVANCE (c, newtext, pos, pos_byte); - if (c == '&') + if (c == '&' || c == '0') { substart = search_regs.start[sub]; subend = search_regs.end[sub]; @@ -2668,7 +2668,7 @@ since only regular expressions have distinguished subexpressions. */) MAKE_CHAR_MULTIBYTE (c); } - if (c == '&') + if (c == '&' || c == '0') idx = sub; else if (c >= '1' && c <= '9' && c - '0' < search_regs.num_regs) {