From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Drew Adams Newsgroups: gmane.emacs.bugs Subject: bug#35354: 26.2; `dired-do-query-replace-regexp': How to replace only word-delimited matches? Date: Mon, 29 Apr 2019 19:29:00 -0700 (PDT) Message-ID: References: <08ee0770-3f50-433e-955e-f8e13547ec21@default> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="21825"; mail-complaints-to="usenet@blaine.gmane.org" Cc: 35354@debbugs.gnu.org, Dmitry Gutov To: npostavs@gmail.com Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Apr 30 04:30:13 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hLIX5-0005SD-S5 for geb-bug-gnu-emacs@m.gmane.org; Tue, 30 Apr 2019 04:30:12 +0200 Original-Received: from localhost ([127.0.0.1]:38003 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hLIX4-0002Rh-Js for geb-bug-gnu-emacs@m.gmane.org; Mon, 29 Apr 2019 22:30:10 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:44755) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hLIWy-0002Ra-Fm for bug-gnu-emacs@gnu.org; Mon, 29 Apr 2019 22:30:05 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hLIWx-00055d-8D for bug-gnu-emacs@gnu.org; Mon, 29 Apr 2019 22:30:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:54997) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hLIWx-00055T-4F for bug-gnu-emacs@gnu.org; Mon, 29 Apr 2019 22:30:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hLIWw-0003Hv-RX for bug-gnu-emacs@gnu.org; Mon, 29 Apr 2019 22:30:02 -0400 X-Loop: help-debbugs@gnu.org In-Reply-To: <08ee0770-3f50-433e-955e-f8e13547ec21@default> Resent-From: Drew Adams Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 30 Apr 2019 02:30:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 35354 X-GNU-PR-Package: emacs Original-Received: via spool by 35354-submit@debbugs.gnu.org id=B35354.155659135212550 (code B ref 35354); Tue, 30 Apr 2019 02:30:02 +0000 Original-Received: (at 35354) by debbugs.gnu.org; 30 Apr 2019 02:29:12 +0000 Original-Received: from localhost ([127.0.0.1]:40307 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hLIW8-0003GL-AS for submit@debbugs.gnu.org; Mon, 29 Apr 2019 22:29:12 -0400 Original-Received: from aserp2130.oracle.com ([141.146.126.79]:52766) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hLIW5-0003G1-Ow for 35354@debbugs.gnu.org; Mon, 29 Apr 2019 22:29:10 -0400 Original-Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x3U2Nt54088030; Tue, 30 Apr 2019 02:29:03 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=mime-version : message-id : date : from : sender : to : cc : subject : content-type : content-transfer-encoding; s=corp-2018-07-02; bh=+fnv8NK8RhXzqXj/eWmpj7lqTUUvmTigeSmZHrqHyfI=; b=PtE5ATMBknhaO/J4b4JiWm3L7QFdL6NPuy6e+1xjeTmdxL/RQXAZ1P2dLefHe8H5rSVY 9dPhzyvsNPKjw3chjAxXtKsJLdNdt03e09doQwtJiiTQDHGKVaBjMIUjFvxQOAo83qZb VuI4eaXs5kAeOZAlhJeRopUWKWG/P7uzJFQC46818CS4ZFxW8NbcESJsUamNQbJ/hzyX NHy2A0wUTwHJfxzgACl+IBlIN/gV+Ni5j5lPkfDYlujDmSY6tiy/JiqqmJWBYYZh+QWF 7dJcrZDTTjtAxGlg7bLnA3D4wbkLQHrci/lR2wGYxNjzzEGEvSrLTS4GFkO3aPlts8iN xg== Original-Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2130.oracle.com with ESMTP id 2s4ckd9yk2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 30 Apr 2019 02:29:03 +0000 Original-Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x3U2S6hC080595; Tue, 30 Apr 2019 02:29:03 GMT Original-Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3030.oracle.com with ESMTP id 2s4yy99max-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 30 Apr 2019 02:29:02 +0000 Original-Received: from abhmp0013.oracle.com (abhmp0013.oracle.com [141.146.116.19]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x3U2T1Gf028345; Tue, 30 Apr 2019 02:29:01 GMT X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.9.1 (1003210) [OL 16.0.4834.0 (x86)] X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9242 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=29 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1904300015 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9242 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=29 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1904300014 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.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" Xref: news.gmane.org gmane.emacs.bugs:158473 Archived-At: > >>>>> "Drew" =3D=3D Drew Adams writes: > >>>>> "Dmitry" =3D=3D Dmitry Gutov writes: >=20 > Drew> I was expecting that it would do all that the latter does plus > Drew> more. >=20 > Dmitry> I don't really understand how we can both expect FROM to be a > Dmitry> regexp and have a separate argument DELIMITED. >=20 > Drew> Why is that a problem? >=20 > It seems to give some possibly unexpected results. For example, with > this buffer contents: >=20 > word fooooo bar word > word foo bar word >=20 > C-u C-M-% foo.*bar RET replaces only the "foo bar" on the second line, > not the "fooooo bar" on the first line. That is to say, it's unclear > (to me at least) what DELIMITED means for regexps which can match both > word and non-word characters. The doc says that only the start and end of the match need be word boundaries. So I guess that Dmitry is right that in the case where the input is interpreted as a regexp non-nil DELIMITED can only be a convenience for not having to use \v. I was thinking that DELIMITED acted as a second filter, requiring not only word boundaries at beginning and end but also that all chars matched be word-constituent. That's clearly not the case though, and the doc doesn't suggest it should be. Your example points out a regression. It was introduced in Emacs 24.5. In Emacs 20-23 (and probably pre-20) it acts correctly (per the doc): both lines of your example are treated the same: fooooo bar is matched. Starting with Emacs 24.5 the doc is no longer respected. Was the change intentional, and someone forgot to update the doc? I doubt it. This change/regression coincides with the introduction of `replace-search' and `replace-highlight' and the use of `isearch-word', which later became ` isearch-regexp-function'. Before that, `perform-replace' just did this: (if delimited-flag =09(setq search-function 're-search-forward =09 search-string (concat "\\b" =09=09=09=09 (if regexp-flag from-string =09=09=09=09 (regexp-quote from-string)) =09=09=09=09 "\\b"))) > I understand how the match can be delimited, but I don't understand how > the replacement can be delimited. Right. I was wrongly thinking that non-nil DELIMITED meant that the otherwise-matches were in addition filtered by also requiring their chars to be word constituents. > Dmitry> Is there a practical difference between this and > Dmitry> using a regexp with word boundaries as FROM? >=20 > Drew> See `query-replace-regexp'. Why do you think it has argument > Drew> DELIMITED? >=20 > I think it might be just to save the user from typing `\<' and `\>'. > Did you have another reason in mind? If so, please say it plainly, > thanks. I think you must be right. Clearly for the `query-replace' case it is useful as such. For the `query-replace-regexp' case it is not as useful. But even in that case it can be useful in this sense: You can _reuse_ a regexp in a different search, and just use a prefix arg to temporarily restrict the matches to having word boundaries - no need to edit the regexp. Not a big win, granted, but if you need to go back and forth then it could be a convenience. The point of this bug report is that if we replace the command used by `Q' with another then we should maybe have it do at least as much. DELIMITED has been in Emacs for the functions that use it (in replace.el) for a very long time.