From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#67124: 26.3; query-replace Arg out of range with comma option (at end-buffer) Date: Thu, 16 Nov 2023 11:15:56 -0500 Message-ID: References: <020a72b2-b896-4ecf-abab-111a6c1c9eac@medialab.sissa.it> <83cywfuwta.fsf@gnu.org> <83pm0du49e.fsf@gnu.org> <83o7ftpx1w.fsf@gnu.org> Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="19538"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: gabriele@medialab.sissa.it, 67124@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Nov 16 17:17:24 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 1r3f3T-0004uC-AH for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 16 Nov 2023 17:17:23 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r3f3A-0005sy-E6; Thu, 16 Nov 2023 11:17:04 -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 1r3f39-0005sc-63 for bug-gnu-emacs@gnu.org; Thu, 16 Nov 2023 11:17:03 -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 1r3f38-00089i-Tg for bug-gnu-emacs@gnu.org; Thu, 16 Nov 2023 11:17:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1r3f38-0000aV-J0 for bug-gnu-emacs@gnu.org; Thu, 16 Nov 2023 11:17:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 16 Nov 2023 16:17: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.17001513722186 (code B ref 67124); Thu, 16 Nov 2023 16:17:02 +0000 Original-Received: (at 67124) by debbugs.gnu.org; 16 Nov 2023 16:16:12 +0000 Original-Received: from localhost ([127.0.0.1]:57471 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r3f2J-0000ZC-U5 for submit@debbugs.gnu.org; Thu, 16 Nov 2023 11:16:12 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:7219) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r3f2F-0000Yn-Ef for 67124@debbugs.gnu.org; Thu, 16 Nov 2023 11:16:09 -0500 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 590421000BC; Thu, 16 Nov 2023 11:16:02 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1700151357; bh=0xBEW8VIfDcd75QrHQKDdVA6Ix8/5OsjfVD8FigaB8k=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=jTEarxiy5OI7JapUrd90DEjcZmp8GqX+SiooIZZR3ld0x7EhyR9T5VgwCX/5OdXhX rsaZGGZVem3D/itLM8qvbEZT3ovxizWjOJhbVod3cLlaLIZ1cwR6/CGMrS+oHwJOkK 67qo/EiH2b1DUYsWk8EPnBUgJnaN05AQbyJm1gyD+d/OuOdU4CO9Z2eMaZDHsIww4N mEMSUcd2cYJGLFxBu2+Dox548gfvLeNMdXZtJtLdssZwFj9rgoXjpEyXcQcMp2SVo+ GxSBWZpDCrfxvuA77E22yxw9dRZXEqRzOEIQUxDAzh3oRBquXYd3N8S9u8+JgMifoR LGJC6367owrpA== Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 740A1100068; Thu, 16 Nov 2023 11:15:57 -0500 (EST) Original-Received: from pastel (unknown [45.72.227.120]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 4DB2812004E; Thu, 16 Nov 2023 11:15:57 -0500 (EST) In-Reply-To: <83o7ftpx1w.fsf@gnu.org> (Eli Zaretskii's message of "Thu, 16 Nov 2023 16:55:39 +0200") 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:274467 Archived-At: >> >> > ;; `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. >> >> I believe the numerical value of (nth 0 match-data) will be the same at >> this point as that of (nth 0 (match-data)) because we just passed that >> very value to `set-match-data`, and that is always equal >> (numerically) to (match-beginning 0). >> Since the only thing we do with that value is pass it immediately to >> `goto-char`, it makes no difference if it's a marker or an integer, no? >> >> What am I missing? > > What are you trying to understand? Why you're saying that in ;; `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))) it is not true that and (nth 0 match-data) == (match-beginning 0), no? Note: this is not directly related to your patch, since your patch did not touch that line, AFAICT. > What my kludge did is simply use a marker, so the adjusted position is > not clobbered. I don't see that. E.g. if you change your code from (set-match-data (list (car match-data) (nth 1 (match-data)))) to (set-match-data (list (car match-data) (nth 1 (match-data t)))) it fixes the problem just as well, AFAICT. And it could even be replaced with: (set-match-data (cons (car match-data) (cdr (match-data t)))) My understand is that what you patch does is use the match end as adjusted by `replace-match` rather than the match end as provided by the `match-end` argument (because that argument contains integers and hence ends up pointing to the wrong place after the buffer was modified by `replace-match`). Basically, the purpose of the above `set-match-data` originally was to correct the (match-beginning 0) info because `replace-match` adjusted it incorrectly (i.e. it works around a bug in `update_search_regs`), but while doing that it ended up messing up the (match-end 0), so your patch refines that code so as to leave (match-end 0) unchanged while correcting (match-beginning 0). "use a marker kludge" would sound like an appropriate description of the `advice-add` I sent to Grabriel, on the other hand. Stefan