From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#67124: 26.3; query-replace Arg out of range with comma option (at end-buffer) Date: Mon, 13 Nov 2023 16:17:17 +0200 Message-ID: <83pm0du49e.fsf@gnu.org> References: <020a72b2-b896-4ecf-abab-111a6c1c9eac@medialab.sissa.it> <83cywfuwta.fsf@gnu.org> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="19053"; mail-complaints-to="usenet@ciao.gmane.io" Cc: gabriele@medialab.sissa.it, 67124@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Nov 13 15:18:51 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1r2Xm6-0004i6-IJ for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 13 Nov 2023 15:18:50 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r2Xli-0001EL-Ev; Mon, 13 Nov 2023 09:18:28 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r2Xle-0001ED-Lf for bug-gnu-emacs@gnu.org; Mon, 13 Nov 2023 09:18:22 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r2Xld-0005pR-Qg for bug-gnu-emacs@gnu.org; Mon, 13 Nov 2023 09:18:22 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1r2XmI-0000PR-3E for bug-gnu-emacs@gnu.org; Mon, 13 Nov 2023 09:19:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 13 Nov 2023 14:19:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 67124 X-GNU-PR-Package: emacs Original-Received: via spool by 67124-submit@debbugs.gnu.org id=B67124.16998851091524 (code B ref 67124); Mon, 13 Nov 2023 14:19:02 +0000 Original-Received: (at 67124) by debbugs.gnu.org; 13 Nov 2023 14:18:29 +0000 Original-Received: from localhost ([127.0.0.1]:57734 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r2Xlk-0000OW-Lh for submit@debbugs.gnu.org; Mon, 13 Nov 2023 09:18:29 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:52796) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r2Xle-0000O9-PM for 67124@debbugs.gnu.org; Mon, 13 Nov 2023 09:18:27 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r2Xkq-0005gL-S4; Mon, 13 Nov 2023 09:17:33 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=ch9G8iAtKkFh/ve0SxKPF8kNaaD4KVuQvptmQEMwKLQ=; b=PaecPEVcQhEY KAmExOmeyNuD98o24GIlC1XHDtsK997z3gpEHH2zCSrlTtklmaQzsjAH6QMZg8t8aObUp7lfFoVtR /7kq0f+B2sPBcSJZQgrwQZD7UPWh7hYuMCzcKitEY3mT3p2gm0Yowfntvq2uFzi2vzraI/0zm8oF4 SSQckqbruTZxAVDB2C/7IdwYsgDiEEuA1HHhTRUYtXVs52/ZKfTV5aiBkqN4CVzD3YKFBzP/rjcP0 jyxjxtScnNDTDp06aWVMEzXJhScyCGeO1IxNcnIv/VzEINRbx4A/6mqS2YKsi6rGkhpV25dXPYmsv 7Wg+NnHy6pF1xz0wswoQIw==; In-Reply-To: (message from Stefan Monnier on Sun, 12 Nov 2023 22:56:16 -0500) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:274261 Archived-At: > From: Stefan Monnier > Cc: Gabriele Nicolardi , 67124@debbugs.gnu.org > Date: Sun, 12 Nov 2023 22:56:16 -0500 > > (nth 1 (match-data)) == (match-end 0), no? No, because the former normally returns a marker, whereas the latter returns a number. And here the difference is crucial. > Hmm... so here we're throwing away all the subgroup info and keeping > only the start/end, right? Yes. > It's probably OK, indeed, but I think the comment should clarify > that (and should clarify that we (well, presumably the undo feature) > need the match end in addition to the match beginning). The comment before the patched part (you can see its end in the patch) says so, no? > Also here it's not obvious which match-data is returned by (match-data). > IIUC it's the match data as adjusted by `replace-match`. Yes, and that's the root cause here: replace-match updates match-data, but the original code then clobbered it by overwriting it with the match-data _before_ the replace-match call. > Which makes me wonder why we don't change `replace-match` so it's also > careful to preserve the match beginning just like it preserves the match > end. AFAIU, it's a general issue with markers: when you have both match-beginning and match-end at the same buffer position (because the matched text is an empty string, as when the search regexp is \b or similar, then replace-match moves them both to the end of the match, instead of leaving one of them at the beginning of the match. > > ;; `replace-match' leaves point at the end of the replacement text, > > ;; so move point to the beginning when replacing backward. > > (when backward (goto-char (nth 0 match-data))) > > and (nth 0 match-data) == (match-beginning 0), no? See above: not exactly. > So, I tried the patch below, which makes sense to my superficial > understanding of the problem, but it apparently doesn't fix the problem > in the OP's recipe, so I'm clearly missing something. I don't understand the fix, so cannot help you here ;-)