From unknown Sun Jun 22 04:27:25 2025 X-Loop: help-debbugs@gnu.org Subject: bug#67124: 26.3; query-replace Arg out of range with comma option (at end-buffer) Resent-From: Gabriele Nicolardi Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 12 Nov 2023 07:52:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 67124 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: 67124@debbugs.gnu.org X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.169977547131290 (code B ref -1); Sun, 12 Nov 2023 07:52:03 +0000 Received: (at submit) by debbugs.gnu.org; 12 Nov 2023 07:51:11 +0000 Received: from localhost ([127.0.0.1]:55030 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r25FN-00088V-Os for submit@debbugs.gnu.org; Sun, 12 Nov 2023 02:51:10 -0500 Received: from lists.gnu.org ([2001:470:142::17]:50924) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r1trD-0005Hl-O1 for submit@debbugs.gnu.org; Sat, 11 Nov 2023 14:41:28 -0500 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 1r1tqR-0006wC-88 for bug-gnu-emacs@gnu.org; Sat, 11 Nov 2023 14:40:39 -0500 Received: from smtp04.cbsolt.net ([185.97.217.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r1tqO-0002eQ-WD for bug-gnu-emacs@gnu.org; Sat, 11 Nov 2023 14:40:38 -0500 Received: from [10.0.2.15] (host-82-60-177-34.retail.telecomitalia.it [82.60.177.34]) by smtp04.cbsolt.net (Postfix) with ESMTPSA id 4SSQyh5yM9z3wbv for ; Sat, 11 Nov 2023 20:40:28 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cbsolt.net; s=201504-di4k2w; t=1699731629; bh=lsZA45SwU4ePu39xBinRdLfQ4w7A6UPFPIxwz+YMK1g=; h=Date:To:Subject:From:From; b=QZjOXsRdFZ9xkTztvWFUHP7TE3knd2kFFWqtvCMzAarP9T+Tmqmk8pdPfCQq8blsL aqEKsTf0asN66NIFZb5QtN73SfJeE2E8f+728Cfh3XgAbkcz0mLXmBON0NJu5tI+ZW XI7CGGpJlDP4CXhzveolK93JrZYqXNxXaZRmEM68= Message-ID: <020a72b2-b896-4ecf-abab-111a6c1c9eac@medialab.sissa.it> Date: Sat, 11 Nov 2023 20:40:27 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US From: Gabriele Nicolardi Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=185.97.217.43; envelope-from=gabriele@medialab.sissa.it; helo=smtp04.cbsolt.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: 1.0 (+) X-Mailman-Approved-At: Sun, 12 Nov 2023 02:51:04 -0500 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) Hi, I'm resending the bug report trying to do better than the previous one. When I run `query-replace-regexp` command if I type `?` I get this explanation of the function's options: Type Space or ‘y’ to replace one match, Delete or ‘n’ to skip to next, RET or ‘q’ to exit, Period to replace one match and exit, Comma to replace but not move point immediately, C-r to enter recursive edit (C-M-c to get out again), C-w to delete match and recursive edit, C-l to clear the screen, redisplay, and offer same replacement again, ! to replace all remaining matches in this buffer with no more questions, ^ to move point back to previous match, u to undo previous replacement, U to undo all replacements, E to edit the replacement string. In multi-buffer replacements type ‘Y’ to replace all remaining matches in all remaining buffers with no more questions, ‘N’ to skip to the next buffer without replacing remaining matches in the current buffer. I often type `,` (`comma`) to check the replacement. It happens that, some times, I get the error (e.g.): match-substitute-replacement: Args out of range: #, 1667, 1679 The error doesn't happen if I type `y` (or `n`) Try this: (query-replace ",.\\footnote{" ".\\footnote{" nil) With the string ",.\footnote{" at the end of the buffer. To see the error "{" must be the last char in the buffer. (I see often this bug because I use "narrowing" a lot) Is it a known bug? My emacs version is GNU Emacs 26.3. In GNU Emacs 26.3 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.24.14) of 2020-03-26, modified by Debian built on lcy01-amd64-020 Windowing system distributor 'The X.Org Foundation', version 11.0.12013000 System Description: Ubuntu 20.04.6 LTS Recent messages: Mark set next-line: End of buffer Mark set funcall-interactively: End of buffer Quit Mark set Entering debugger... Mark set previous-line: Beginning of buffer Mark set previous-line: Beginning of buffer Configured using: 'configure --build x86_64-linux-gnu --prefix=/usr --sharedstatedir=/var/lib --libexecdir=/usr/lib --localstatedir=/var/lib --infodir=/usr/share/info --mandir=/usr/share/man --enable-libsystemd --with-pop=yes --enable-locallisppath=/etc/emacs:/usr/local/share/emacs/26.3/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/26.3/site-lisp:/usr/share/emacs/site-lisp --with-sound=alsa --without-gconf --with-mailutils --build x86_64-linux-gnu --prefix=/usr --sharedstatedir=/var/lib --libexecdir=/usr/lib --localstatedir=/var/lib --infodir=/usr/share/info --mandir=/usr/share/man --enable-libsystemd --with-pop=yes --enable-locallisppath=/etc/emacs:/usr/local/share/emacs/26.3/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/26.3/site-lisp:/usr/share/emacs/site-lisp --with-sound=alsa --without-gconf --with-mailutils --with-x=yes --with-x-toolkit=gtk3 --with-toolkit-scroll-bars 'CFLAGS=-g -O2 -fdebug-prefix-map=/build/emacs-mEZBk7/emacs-26.3+1=. -fstack-protector-strong -Wformat -Werror=format-security -Wall' 'CPPFLAGS=-Wdate-time -D_FORTIFY_SOURCE=2' 'LDFLAGS=-Wl,-Bsymbolic-functions -Wl,-z,relro'' Configured features: XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK SOUND GPM DBUS GSETTINGS GLIB NOTIFY ACL LIBSELINUX GNUTLS LIBXML2 FREETYPE M17N_FLT LIBOTF XFT ZLIB TOOLKIT_SCROLL_BARS GTK3 X11 XDBE XIM THREADS LIBSYSTEMD LCMS2 Important settings: value of $LANG: it_IT.UTF-8 locale-coding-system: utf-8-unix Major mode: Lisp Interaction Minor modes in effect: tooltip-mode: t global-eldoc-mode: t eldoc-mode: t electric-indent-mode: t mouse-wheel-mode: t tool-bar-mode: t menu-bar-mode: t file-name-shadow-mode: t global-font-lock-mode: t font-lock-mode: t blink-cursor-mode: t auto-composition-mode: t auto-encryption-mode: t auto-compression-mode: t line-number-mode: t transient-mark-mode: t Load-path shadows: None found. Features: (shadow sort mail-extr emacsbug message rmc puny seq dired dired-loaddefs format-spec rfc822 ...) Memory information: ((conses 16 97042 8905) (symbols 48 20561 1) (miscs 40 86 120) (strings 32 28945 1187) (string-bytes 1 762727) (vectors 16 14159) (vector-slots 8 504582 10748) (floats 8 56 120) (intervals 56 316 55) (buffers 992 12)) From debbugs-submit-bounces@debbugs.gnu.org Sun Nov 12 03:50:24 2023 Received: (at control) by debbugs.gnu.org; 12 Nov 2023 08:50:24 +0000 Received: from localhost ([127.0.0.1]:55100 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r26Ah-0001FT-Tb for submit@debbugs.gnu.org; Sun, 12 Nov 2023 03:50:24 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:38578) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r26Ag-0001FD-Au for control@debbugs.gnu.org; Sun, 12 Nov 2023 03:50:22 -0500 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 1r269w-0000TT-3i for control@debbugs.gnu.org; Sun, 12 Nov 2023 03:49:36 -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=Iih13Aj8oJQVQeGqaR5aWGODkS+Ru50Z9maVhwRPtX0=; b=PfyM7zg64z6T u5jqk1EWXxw4T22Tv3o3h4BRDZqaPVn0VZe4UkXgf2GbhWWixOyznL+6cybVufXmN92o0fiB+AV7d cc2tYzK65hYqfcjiBfmCbn57Hf68GFNdEKvvVWO+6aClq0jH0dnLBmiUzGbO0sG3lsamkxwiNkPgo +aVlfP1G+FLf5PMdNnMztfZGmJyNc+PkmfjHfQtMeCb8YAXSLWZNW2g8D6UwmloVj97EYHKr2fD4z 8TT0UNJcYZavRrCimZ3ltk6Bp1e0ZRUoDTGRofSvHU73ZjB7R7tz++duYzCwytpcwuJQ3lk6cLojc +vLAB1ZC5n+cBVecfpnE8g==; Date: Sun, 12 Nov 2023 10:49:19 +0200 Message-Id: <83edgvuzjk.fsf@gnu.org> From: Eli Zaretskii To: control@debbugs.gnu.org In-Reply-To: <020a72b2-b896-4ecf-abab-111a6c1c9eac@medialab.sissa.it> (message from Gabriele Nicolardi on Sat, 11 Nov 2023 20:40:27 +0100) Subject: Re: bug#67124: 26.3; query-replace Arg out of range with comma option (at end-buffer) References: <020a72b2-b896-4ecf-abab-111a6c1c9eac@medialab.sissa.it> X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) merge 67050 67124 thanks From unknown Sun Jun 22 04:27:25 2025 X-Loop: help-debbugs@gnu.org Subject: bug#67124: 26.3; query-replace Arg out of range with comma option (at end-buffer) Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 12 Nov 2023 09:50:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 67124 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Gabriele Nicolardi , Stefan Monnier Cc: 67124@debbugs.gnu.org Received: via spool by 67124-submit@debbugs.gnu.org id=B67124.169978256720663 (code B ref 67124); Sun, 12 Nov 2023 09:50:02 +0000 Received: (at 67124) by debbugs.gnu.org; 12 Nov 2023 09:49:27 +0000 Received: from localhost ([127.0.0.1]:55124 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r275q-0005NB-TX for submit@debbugs.gnu.org; Sun, 12 Nov 2023 04:49:27 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:56518) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r275n-0005MQ-Hz for 67124@debbugs.gnu.org; Sun, 12 Nov 2023 04:49:24 -0500 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 1r2751-0007ZU-LA; Sun, 12 Nov 2023 04:48:35 -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=PPsNWj3mQsUsdWugY8prIuZTH0GxLcA/30nTQmdOCxM=; b=TO+w/sgCr16v mlu2mo4tv8hTb3I5GsGELvaApDt3NdS/VhqRKcr5GH5T0vIsC66rwtAxvuuXsYNBb+0DMUEk2kdRy p5U1L+0T9ACSbNDstbqEoc0zKhf16QYU+iUp5vlNdXNVFOVoJJmoZITS4agMKBS/KsK+aQmhOApsE Z6XqAtfGx+0zKkgNkQPyHHU5GrfudE0FlBSR+k36Ffgo5OzJCKn19AJ0CHAh3FdnoWV0pbL2vaPjg t+6A+CeuIfR96dWXLO7JD8sTfXahX0rg+73m52sPG8ieEQOi0a/EO/cnSJPjpDjPxbCyzSt64gTbw 0fwVIoFaJLkkS0FZVqEvpw==; Date: Sun, 12 Nov 2023 11:48:17 +0200 Message-Id: <83cywfuwta.fsf@gnu.org> From: Eli Zaretskii In-Reply-To: <020a72b2-b896-4ecf-abab-111a6c1c9eac@medialab.sissa.it> (message from Gabriele Nicolardi on Sat, 11 Nov 2023 20:40:27 +0100) References: <020a72b2-b896-4ecf-abab-111a6c1c9eac@medialab.sissa.it> X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > Date: Sat, 11 Nov 2023 20:40:27 +0100 > From: Gabriele Nicolardi > > Hi, I'm resending the bug report trying to do better than the previous one. Thanks. (In the future, please respond to the original bug number, instead of creating a new bug report; I've merged them now.) > I often type `,` (`comma`) to check the replacement. It happens that, > some times, I get the error (e.g.): > > match-substitute-replacement: Args out of range: #, > 1667, 1679 > > The error doesn't happen if I type `y` (or `n`) > > Try this: > > (query-replace ",.\\footnote{" ".\\footnote{" nil) > > With the string ",.\footnote{" at the end of the buffer. To see the > error "{" must be the last char in the buffer. > > (I see often this bug because I use "narrowing" a lot) > > Is it a known bug? The kludgey solution in the patch below should fix this. Please see if it indeed fixes your real-life use cases. Stefan, any ideas for a better fix, or other comments? AFAIU, the root cause of the bug was that we are using integers instead of markers there, and that is because bug#31492 needs to preserve the original match-start position when the search string is a regexp that matches an empty string (in which case the match-start marker moves together with the match-end marker instead of staying put). diff --git a/lisp/replace.el b/lisp/replace.el index eeac734..6a3f223 100644 --- a/lisp/replace.el +++ b/lisp/replace.el @@ -2642,8 +2642,11 @@ replace-match-maybe-edit (replace-match newtext fixedcase literal) ;; `query-replace' undo feature needs the beginning of the match position, ;; but `replace-match' may change it, for instance, with a regexp like "^". - ;; Ensure that this function preserves the match data (Bug#31492). - (set-match-data match-data) + ;; Ensure that this function preserves the beginning of the match position + ;; (bug#31492). But we need to avoid clobbering the end of the match with + ;; the original match-end position, since `replace-match' could have made + ;; that incorrect or even invalid (bug#67124). + (set-match-data (list (car match-data) (nth 1 (match-data)))) ;; `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))) From unknown Sun Jun 22 04:27:25 2025 X-Loop: help-debbugs@gnu.org Subject: bug#67124: 26.3; query-replace Arg out of range with comma option (at end-buffer) Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 13 Nov 2023 03:58:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 67124 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Eli Zaretskii Cc: Gabriele Nicolardi , 67124@debbugs.gnu.org Received: via spool by 67124-submit@debbugs.gnu.org id=B67124.16998478323847 (code B ref 67124); Mon, 13 Nov 2023 03:58:02 +0000 Received: (at 67124) by debbugs.gnu.org; 13 Nov 2023 03:57:12 +0000 Received: from localhost ([127.0.0.1]:57293 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r2O4W-0000zz-DZ for submit@debbugs.gnu.org; Sun, 12 Nov 2023 22:57:12 -0500 Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:25454) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r2O4T-0000zj-90 for 67124@debbugs.gnu.org; Sun, 12 Nov 2023 22:57:10 -0500 Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 863F8801D4; Sun, 12 Nov 2023 22:56:22 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1699847777; bh=dxsi5WiBqg6Cdk0IQJPqfasHwepS2ADeL73/XfFXYds=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=RFzQnDqA7WSqswsETV6rHoHUm+ohiYSGu1bMDgGTwi1ln4nAUGQKxG+AqHdHVs9KU 80l6fC1lrkdoznZlgEKnuVv7kamxfSdvs4J4r4Nlbg2w/02cByAY1VePGkQWL2DDeT FXNuM1vMlHkVbqBm/0GR7FCDEMv6fW1C6JG+JP/J5xp2I4yv3oD6bOdCTL2UeXCCFG eHbxMnikkMmk1cDkDiE6WpvBza+1nj54Qc1i90oPyaoJs68eA+yaBNwHxbxbM5nNMO eC0xCgd3pi4iCq3M8aKOef4MBNy1dwvPmyXg8AqLZnOcvpRpdfi2rayIB/s9CHhxW2 ARqqMnx7jJrKA== Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 44CDB8001F; Sun, 12 Nov 2023 22:56:17 -0500 (EST) Received: from pastel (unknown [45.72.227.120]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 17452120250; Sun, 12 Nov 2023 22:56:17 -0500 (EST) From: Stefan Monnier In-Reply-To: <83cywfuwta.fsf@gnu.org> (Eli Zaretskii's message of "Sun, 12 Nov 2023 11:48:17 +0200") Message-ID: References: <020a72b2-b896-4ecf-abab-111a6c1c9eac@medialab.sissa.it> <83cywfuwta.fsf@gnu.org> Date: Sun, 12 Nov 2023 22:56:16 -0500 User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-SPAM-INFO: Spam detection results: 0 ALL_TRUSTED -1 Passed through trusted hosts only via SMTP AWL 0.016 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's domain DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from domain T_SCC_BODY_TEXT_LINE -0.01 - X-SPAM-LEVEL: X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > Stefan, any ideas for a better fix, or other comments? AFAIU, the > root cause of the bug was that we are using integers instead of > markers there, and that is because bug#31492 needs to preserve the > original match-start position when the search string is a regexp that > matches an empty string (in which case the match-start marker moves > together with the match-end marker instead of staying put). > diff --git a/lisp/replace.el b/lisp/replace.el > index eeac734..6a3f223 100644 > --- a/lisp/replace.el > +++ b/lisp/replace.el > @@ -2642,8 +2642,11 @@ replace-match-maybe-edit > (replace-match newtext fixedcase literal) > ;; `query-replace' undo feature needs the beginning of the match position, > ;; but `replace-match' may change it, for instance, with a regexp like "^". > - ;; Ensure that this function preserves the match data (Bug#31492). > - (set-match-data match-data) > + ;; Ensure that this function preserves the beginning of the match position > + ;; (bug#31492). But we need to avoid clobbering the end of the match with > + ;; the original match-end position, since `replace-match' could have made > + ;; that incorrect or even invalid (bug#67124). > + (set-match-data (list (car match-data) (nth 1 (match-data)))) (nth 1 (match-data)) == (match-end 0), no? Hmm... so here we're throwing away all the subgroup info and keeping only the start/end, right? 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). 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`. 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. > ;; `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? 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. In any case the C part of the change seems right (if I may say so myself :-), at least when `i==0` and more generally when `i` denotes a subgroup which contains the subgroup that `replace-match` has replaced. Stefan diff --git a/lisp/replace.el b/lisp/replace.el index 6b06e48c384..acf6b8a4652 100644 --- a/lisp/replace.el +++ b/lisp/replace.el @@ -2642,13 +2642,9 @@ replace-match-maybe-edit noedit nil))) (set-match-data match-data) (replace-match newtext fixedcase literal) - ;; `query-replace' undo feature needs the beginning of the match position, - ;; but `replace-match' may change it, for instance, with a regexp like "^". - ;; Ensure that this function preserves the match data (Bug#31492). - (set-match-data match-data) ;; `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))) + (when backward (goto-char (match-beginning 0))) noedit) (defvar replace-update-post-hook nil diff --git a/src/search.c b/src/search.c index 692d8488049..0c5e81a245d 100644 --- a/src/search.c +++ b/src/search.c @@ -3142,9 +3142,11 @@ update_search_regs (ptrdiff_t oldstart, ptrdiff_t oldend, ptrdiff_t newend) for (i = 0; i < search_regs.num_regs; i++) { - if (search_regs.start[i] >= oldend) + if (search_regs.start[i] <= oldstart) + ; + else if (search_regs.start[i] >= oldend) search_regs.start[i] += change; - else if (search_regs.start[i] > oldstart) + else search_regs.start[i] = oldstart; if (search_regs.end[i] >= oldend) search_regs.end[i] += change; From unknown Sun Jun 22 04:27:25 2025 X-Loop: help-debbugs@gnu.org Subject: bug#67124: 26.3; query-replace Arg out of range with comma option (at end-buffer) Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 13 Nov 2023 14:08:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 67124 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Gabriele Nicolardi Cc: 67124@debbugs.gnu.org Received: via spool by 67124-submit@debbugs.gnu.org id=B67124.169988443132741 (code B ref 67124); Mon, 13 Nov 2023 14:08:01 +0000 Received: (at 67124) by debbugs.gnu.org; 13 Nov 2023 14:07:11 +0000 Received: from localhost ([127.0.0.1]:57717 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r2Xao-0008W1-Pe for submit@debbugs.gnu.org; Mon, 13 Nov 2023 09:07:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50624) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r2Xan-0008Vm-CO for 67124@debbugs.gnu.org; Mon, 13 Nov 2023 09:07:09 -0500 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 1r2XZz-0003Oz-ED; Mon, 13 Nov 2023 09:06:20 -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=8SHt7DW++NmQmZZYwBwJngpOyI9jRu2h11WcuGs0u+4=; b=Gs0h95Vf97GD QU5N04lSxYL8yN/haDEoWdKCwnOCbOmdEhLEkVk6YIkJuJOxAtkuScFOgAKY6WkjWbwDV7cOuJIId iK75CkoOcwK8zqmPJ4rqqSD6OtP02wHtXKq+v0qnS9AJCqu9rC6FuPzYKHv/MrwSL7EFuzsp4extU qoTPe5/cHFhrXI0HkLRIAeaRO0NdpzhMVihN5lQg4wP8EmXlJSwJ7SvzfMYuCKuk5BdWNZyOprczR OxIUhd1LS+Zf3lxqnZT0Uljd9pKKfv5u6b/kWrqzv7HKuBj44+frHL6X2xX3+SrXo4eKKvn6uDI+9 TNrbfYiuLv3xxy8Jk9t1FA==; Date: Mon, 13 Nov 2023 16:06:00 +0200 Message-Id: <83r0ktu4s7.fsf@gnu.org> From: Eli Zaretskii In-Reply-To: (message from Gabriele Nicolardi on Sun, 12 Nov 2023 23:44:43 +0100) References: <020a72b2-b896-4ecf-abab-111a6c1c9eac@medialab.sissa.it> <83cywfuwta.fsf@gnu.org> X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) [Please use Reply All to reply, so that the bug tracker is CC'ed.] > Date: Sun, 12 Nov 2023 23:44:43 +0100 > From: Gabriele Nicolardi > > I tested the patch on the MWE I sent to you. Thanks! > > Now I'm not sure what I should do. I write elisp code used by a production team. We use Emacs to > format LaTeX documents of scientific papers. I don't control which version of Emacs my > collaborators use. Do you have any suggestions? I guess either wait for the next Emacs release or build your own Emacs? From unknown Sun Jun 22 04:27:25 2025 X-Loop: help-debbugs@gnu.org Subject: bug#67124: 26.3; query-replace Arg out of range with comma option (at end-buffer) 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 X-GNU-PR-Keywords: To: Stefan Monnier Cc: gabriele@medialab.sissa.it, 67124@debbugs.gnu.org Received: via spool by 67124-submit@debbugs.gnu.org id=B67124.16998851091524 (code B ref 67124); Mon, 13 Nov 2023 14:19:02 +0000 Received: (at 67124) by debbugs.gnu.org; 13 Nov 2023 14:18:29 +0000 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 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 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==; Date: Mon, 13 Nov 2023 16:17:17 +0200 Message-Id: <83pm0du49e.fsf@gnu.org> From: Eli Zaretskii In-Reply-To: (message from Stefan Monnier on Sun, 12 Nov 2023 22:56:16 -0500) References: <020a72b2-b896-4ecf-abab-111a6c1c9eac@medialab.sissa.it> <83cywfuwta.fsf@gnu.org> X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > 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 ;-) From unknown Sun Jun 22 04:27:25 2025 X-Loop: help-debbugs@gnu.org Subject: bug#67124: 26.3; query-replace Arg out of range with comma option (at end-buffer) Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 13 Nov 2023 14:23:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 67124 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Eli Zaretskii , Gabriele Nicolardi Cc: 67124@debbugs.gnu.org Received: via spool by 67124-submit@debbugs.gnu.org id=B67124.16998853561992 (code B ref 67124); Mon, 13 Nov 2023 14:23:01 +0000 Received: (at 67124) by debbugs.gnu.org; 13 Nov 2023 14:22:36 +0000 Received: from localhost ([127.0.0.1]:57744 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r2Xpk-0000W4-51 for submit@debbugs.gnu.org; Mon, 13 Nov 2023 09:22:36 -0500 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]:33545) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r2Xpi-0000Vr-P3 for 67124@debbugs.gnu.org; Mon, 13 Nov 2023 09:22:35 -0500 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 63329320051E; Mon, 13 Nov 2023 09:21:47 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Mon, 13 Nov 2023 09:21:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gutov.dev; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to; s=fm2; t= 1699885306; x=1699971706; bh=o+VdtPh0YEZuiz/kRzGBhjPQOvNEfIh2nau kpBMt2QQ=; b=ko6mwzzEhUH2RdMTCqlhMkEFHYbNnf/ViEqUcjMSje1o7CPv9pN 1zD4R+a6JvuC2IKoXl9rqKqZFfu9v3NmWtz8RNzWTSloJKoCfod+2eeww43vihrK IBvuuysDj4WHjLaDxUU/dk/nXb5JQtd98mbjPaoAwosPicI+u+z45VMAzPpZyzZ6 xblf5GmRw1xR/Jma8YD+va4Ti9HgnHaKcxirRZPgc635N/h67bYxB6vUGx7h2zHU h0yWXTPn+NsbwkPFnwogHU922msgHg9JHyHb4qE07QGfP/04wi7sQZwFd6X9EvoK nHNSybJp2+HHeaw0KCxRm6mxpsR5WPanKZg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1699885306; x=1699971706; bh=o+VdtPh0YEZuiz/kRzGBhjPQOvNEfIh2nau kpBMt2QQ=; b=dkK6o5oIerUrZpYRSXLknRq2ZknEkG9f8UakSCi21RmZPEpHd8h lqM+Da/2myf48o/L1WQDeEs8p+FvPxK62b0oCmcc9bnOHGA5/r18CiOZtVdhRCjn XwiE/IWgV/UyB+rAsiQ3ubZDwfE/NephjXgXxGVTGWi75UgoPibNDPRMZj1QJoVd HEBnf4Vf5c5BmR4CwafgPS9kbL2deSRBCG7LuJkr/Ap1e7zSXAtGo/cxcpaggytc XXGiF2rJl+ZShc7bkUOBBRl6PrE4T4DDPnvT685XszWrQHc6mVO1mnvW3j9nH8rw ySUPy6g3QwC8bf3gfBxs+lwRFxd6YcnUwzw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrudeftddgieduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepkfffgggfuffvvehfhfgjtgfgsehtjeertddtfeejnecuhfhrohhmpeffmhhi thhrhicuifhuthhovhcuoegumhhithhrhiesghhuthhovhdruggvvheqnecuggftrfgrth htvghrnhepiefgteevheevveffheeltdeukeeiieekueefgedugfefgefhudelgfefveel vdevnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepug hmihhtrhihsehguhhtohhvrdguvghv X-ME-Proxy: Feedback-ID: i0e71465a:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 13 Nov 2023 09:21:45 -0500 (EST) Message-ID: <03fc7766-3d3a-394b-e08c-53eb136d40a6@gutov.dev> Date: Mon, 13 Nov 2023 16:21:43 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Content-Language: en-US References: <020a72b2-b896-4ecf-abab-111a6c1c9eac@medialab.sissa.it> <83cywfuwta.fsf@gnu.org> <83r0ktu4s7.fsf@gnu.org> From: Dmitry Gutov In-Reply-To: <83r0ktu4s7.fsf@gnu.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -2.2 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.2 (---) On 13/11/2023 16:06, Eli Zaretskii wrote: > [Please use Reply All to reply, so that the bug tracker is CC'ed.] >> Date: Sun, 12 Nov 2023 23:44:43 +0100 >> From: Gabriele Nicolardi >> >> I tested the patch on the MWE I sent to you. Thanks! >> >> Now I'm not sure what I should do. I write elisp code used by a production team. We use Emacs to >> format LaTeX documents of scientific papers. I don't control which version of Emacs my >> collaborators use. Do you have any suggestions? > I guess either wait for the next Emacs release or build your own > Emacs? I haven't examined the exact problem, but in such cases some people also either have workarounds in their own code, or supply "advices" for the core functions that work around the problem there. This kind of solution requires a certain level of understanding of the code in question, and might be quite brittle otherwise (breaking other features for the same users). Not for the faint of heart, I'd say. From unknown Sun Jun 22 04:27:25 2025 X-Loop: help-debbugs@gnu.org Subject: bug#67124: 26.3; query-replace Arg out of range with comma option (at end-buffer) Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 13 Nov 2023 14:40:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 67124 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Dmitry Gutov Cc: gabriele@medialab.sissa.it, 67124@debbugs.gnu.org Received: via spool by 67124-submit@debbugs.gnu.org id=B67124.16998863763651 (code B ref 67124); Mon, 13 Nov 2023 14:40:01 +0000 Received: (at 67124) by debbugs.gnu.org; 13 Nov 2023 14:39:36 +0000 Received: from localhost ([127.0.0.1]:57763 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r2Y6C-0000wp-2Z for submit@debbugs.gnu.org; Mon, 13 Nov 2023 09:39:36 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36864) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r2Y69-0000wb-JX for 67124@debbugs.gnu.org; Mon, 13 Nov 2023 09:39:34 -0500 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 1r2Y5L-0001ec-RN; Mon, 13 Nov 2023 09:38:44 -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=9geWroEwC+PuWazJ7npv41rS5LGRvR/KnogLdZIjuh4=; b=KgakBX/SjeCa wNIDpwrAawKlusJUKltGJwcPJEMQTFA7jYUxVcGQfCOEoHD/2tI9rQe9PXBlwyjMhfSzMP3wuDnJf 5FeaIX+GWDZViMW3elP4HeA2zWq8KXprOOMkbWz0qLd3ZQqSSDOnROPf9DUwP5idD2Czw/zybCg4T 0FJCWlqqLVd966vPrTVPmKAJ82CxTdgI4NJ/m7xyhwDpnvSc3MZJgHx3WylhvDv04wy4u48jQ9ZUi 5YaHQJa8FaC2Cgqj1sShHOYwJ0acjFMl0+dQMKDF/r7kfiPaIq6scabEDOLailk5t5jcBMegLFJWx wGGNyeAzn4rsNBh6ZUtE+A==; Date: Mon, 13 Nov 2023 16:38:25 +0200 Message-Id: <83jzqlu3a6.fsf@gnu.org> From: Eli Zaretskii In-Reply-To: <03fc7766-3d3a-394b-e08c-53eb136d40a6@gutov.dev> (message from Dmitry Gutov on Mon, 13 Nov 2023 16:21:43 +0200) References: <020a72b2-b896-4ecf-abab-111a6c1c9eac@medialab.sissa.it> <83cywfuwta.fsf@gnu.org> <83r0ktu4s7.fsf@gnu.org> <03fc7766-3d3a-394b-e08c-53eb136d40a6@gutov.dev> X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > Date: Mon, 13 Nov 2023 16:21:43 +0200 > Cc: 67124@debbugs.gnu.org > From: Dmitry Gutov > > On 13/11/2023 16:06, Eli Zaretskii wrote: > > [Please use Reply All to reply, so that the bug tracker is CC'ed.] > >> Date: Sun, 12 Nov 2023 23:44:43 +0100 > >> From: Gabriele Nicolardi > >> > >> I tested the patch on the MWE I sent to you. Thanks! > >> > >> Now I'm not sure what I should do. I write elisp code used by a production team. We use Emacs to > >> format LaTeX documents of scientific papers. I don't control which version of Emacs my > >> collaborators use. Do you have any suggestions? > > I guess either wait for the next Emacs release or build your own > > Emacs? > > I haven't examined the exact problem, but in such cases some people also > either have workarounds in their own code, or supply "advices" for the > core functions that work around the problem there. Then maybe a simple replacement for the offending function, defined in an init file, would also be a possible solution? From unknown Sun Jun 22 04:27:25 2025 X-Loop: help-debbugs@gnu.org Subject: bug#67124: 26.3; query-replace Arg out of range with comma option (at end-buffer) Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 13 Nov 2023 14:47:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 67124 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Eli Zaretskii Cc: gabriele@medialab.sissa.it, 67124@debbugs.gnu.org Received: via spool by 67124-submit@debbugs.gnu.org id=B67124.16998867904352 (code B ref 67124); Mon, 13 Nov 2023 14:47:01 +0000 Received: (at 67124) by debbugs.gnu.org; 13 Nov 2023 14:46:30 +0000 Received: from localhost ([127.0.0.1]:57778 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r2YCs-000183-2v for submit@debbugs.gnu.org; Mon, 13 Nov 2023 09:46:30 -0500 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]:43515) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r2YCp-00017N-NO for 67124@debbugs.gnu.org; Mon, 13 Nov 2023 09:46:28 -0500 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id E8C073200908; Mon, 13 Nov 2023 09:45:39 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Mon, 13 Nov 2023 09:45:40 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gutov.dev; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to; s=fm2; t= 1699886739; x=1699973139; bh=7vKUWH3Xaw6upcFaUmhXHMWm8CqEG20kkS2 VMhOopbo=; b=e5FcNPQB7JxTev4mBaQJhL9hgRJyS/N+DECxDQ5RewCKS6LNSdz +ULDSMYkcclCP0/LvP/1zIl4kLmhcIRVbVFLGCwXJS/+DvpmNog9gPfKefYzFecr BBI3VFyAkcfYWueGNQcv0vOJilSILL2InKVUsPxxSvNERVD7seMN+LbIuO6rcL3B P1inP3hu1eibk2iVJ06c7Vmqh+xf5MA89QDNJahYWMjxA5heQO3z+vdtD0ALPD4w P+G4rvBgzoJi0tcLndL5Oz4HCbDa4h64hClnh6iUC+04JPwPsJ9uZFjF/XaHnuvz Rk8cC2CYN82wPAs8A0W76l37ubLTg8jr/nA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1699886739; x=1699973139; bh=7vKUWH3Xaw6upcFaUmhXHMWm8CqEG20kkS2 VMhOopbo=; b=dJPUxwkKOu4Vmkk0WNwYdNhLN59va0N7UAKDjNf2vkLNU9R6R+R M9JSfdlbyyktpabzTG7nfb8j0Af7gbXJL46S7tb2XlgpZqFI4H7+MQlYX1qtAEG5 Ye/hzQByqhIiDtkBaWiE3LN6Y7YKru/kOJwjgRwmXDOU3+fCenVNQZNZNHIswTJt 05QNRVzjqnLETmzEOzrl9lziLgCw6tqImuJUiGw+Cdlw2L1PrwpCF5BCjkqdUcRa PgO0clWlrMYZl/n/vX7OmAtTfxbq7jV4dt+3/PH5tuDs17wKi3x83OBmS0oqiNNI DLpz0IXjB3vL8yvnNpA0hL0hMnwteITPK2g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrudeftddgieehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepkfffgggfuffvvehfhfgjtgfgsehtjeertddtfeejnecuhfhrohhmpeffmhhi thhrhicuifhuthhovhcuoegumhhithhrhiesghhuthhovhdruggvvheqnecuggftrfgrth htvghrnhepiefgteevheevveffheeltdeukeeiieekueefgedugfefgefhudelgfefveel vdevnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepug hmihhtrhihsehguhhtohhvrdguvghv X-ME-Proxy: Feedback-ID: i0e71465a:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 13 Nov 2023 09:45:37 -0500 (EST) Message-ID: <383929c4-7921-1a8d-3e6c-29a753ad7e0f@gutov.dev> Date: Mon, 13 Nov 2023 16:45:36 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Content-Language: en-US References: <020a72b2-b896-4ecf-abab-111a6c1c9eac@medialab.sissa.it> <83cywfuwta.fsf@gnu.org> <83r0ktu4s7.fsf@gnu.org> <03fc7766-3d3a-394b-e08c-53eb136d40a6@gutov.dev> <83jzqlu3a6.fsf@gnu.org> From: Dmitry Gutov In-Reply-To: <83jzqlu3a6.fsf@gnu.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -2.2 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.2 (---) On 13/11/2023 16:38, Eli Zaretskii wrote: >> Date: Mon, 13 Nov 2023 16:21:43 +0200 >> Cc:67124@debbugs.gnu.org >> From: Dmitry Gutov >> >> On 13/11/2023 16:06, Eli Zaretskii wrote: >>> [Please use Reply All to reply, so that the bug tracker is CC'ed.] >>>> Date: Sun, 12 Nov 2023 23:44:43 +0100 >>>> From: Gabriele Nicolardi >>>> >>>> I tested the patch on the MWE I sent to you. Thanks! >>>> >>>> Now I'm not sure what I should do. I write elisp code used by a production team. We use Emacs to >>>> format LaTeX documents of scientific papers. I don't control which version of Emacs my >>>> collaborators use. Do you have any suggestions? >>> I guess either wait for the next Emacs release or build your own >>> Emacs? >> I haven't examined the exact problem, but in such cases some people also >> either have workarounds in their own code, or supply "advices" for the >> core functions that work around the problem there. > Then maybe a simple replacement for the offending function, defined in > an init file, would also be a possible solution? Sure. Though it might be more reliable with advice, since they don't depend on the loading order. The problems I had in mind would be more subtle and independent of the choice between these two methods. Stefan's latest patch includes changes in search.c, so it might be difficult to work around in just Lisp. Again, I haven't examined the problem itself. From unknown Sun Jun 22 04:27:25 2025 X-Loop: help-debbugs@gnu.org Subject: bug#67124: 26.3; query-replace Arg out of range with comma option (at end-buffer) Resent-From: Gabriele Nicolardi Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 13 Nov 2023 17:15:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 67124 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Dmitry Gutov , Eli Zaretskii Cc: 67124@debbugs.gnu.org Received: via spool by 67124-submit@debbugs.gnu.org id=B67124.169989567521793 (code B ref 67124); Mon, 13 Nov 2023 17:15:01 +0000 Received: (at 67124) by debbugs.gnu.org; 13 Nov 2023 17:14:35 +0000 Received: from localhost ([127.0.0.1]:59275 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r2aWA-0005fP-8i for submit@debbugs.gnu.org; Mon, 13 Nov 2023 12:14:35 -0500 Received: from smtp06.cbsolt.net ([185.97.217.45]:44116) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r2Z2Z-00032r-Si for 67124@debbugs.gnu.org; Mon, 13 Nov 2023 10:39:57 -0500 Received: from [10.0.2.15] (host-82-60-177-34.retail.telecomitalia.it [82.60.177.34]) by smtp06.cbsolt.net (Postfix) with ESMTPSA id 4STYWF6Y1Gz3wdM; Mon, 13 Nov 2023 16:39:05 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cbsolt.net; s=201504-di4k2w; t=1699889948; bh=VK9yN2AeRLCMXIpt2xtiGlfA9bXHAwg0HK9go0Lr6RQ=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=BzHTiXKc9oLqVsi3G5GOcBnU85vdxQ6qNBVE8wym5UhA8yGbXaedLrYrH9BwGKo9F paDBE/oAaxD9SdYLOKGJs1H4HvEA4plBjRb3nTKLZDG3XJcAOhogduBZJOCz4OddIv SRSOCTF0bdb9n68CbNYTrjXjH8E5/hWcXN2gUWSE= Message-ID: Date: Mon, 13 Nov 2023 16:39:04 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US References: <020a72b2-b896-4ecf-abab-111a6c1c9eac@medialab.sissa.it> <83cywfuwta.fsf@gnu.org> <83r0ktu4s7.fsf@gnu.org> <03fc7766-3d3a-394b-e08c-53eb136d40a6@gutov.dev> <83jzqlu3a6.fsf@gnu.org> <383929c4-7921-1a8d-3e6c-29a753ad7e0f@gutov.dev> From: Gabriele Nicolardi In-Reply-To: <383929c4-7921-1a8d-3e6c-29a753ad7e0f@gutov.dev> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -0.7 (/) X-Mailman-Approved-At: Mon, 13 Nov 2023 12:14:33 -0500 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) Ok, I'll wait for the next release, Thank you. Il 13/11/23 15:45, Dmitry Gutov ha scritto: > On 13/11/2023 16:38, Eli Zaretskii wrote: >>> Date: Mon, 13 Nov 2023 16:21:43 +0200 >>> Cc:67124@debbugs.gnu.org >>> From: Dmitry Gutov >>> >>> On 13/11/2023 16:06, Eli Zaretskii wrote: >>>> [Please use Reply All to reply, so that the bug tracker is CC'ed.] >>>>> Date: Sun, 12 Nov 2023 23:44:43 +0100 >>>>> From: Gabriele Nicolardi >>>>> >>>>> I tested the patch on the MWE I sent to you. Thanks! >>>>> >>>>> Now I'm not sure what I should do. I write elisp code used by a >>>>> production team. We use Emacs to >>>>> format LaTeX documents of scientific papers. I don't control which >>>>> version of Emacs my >>>>> collaborators use. Do you have any suggestions? >>>> I guess either wait for the next Emacs release or build your own >>>> Emacs? >>> I haven't examined the exact problem, but in such cases some people >>> also >>> either have workarounds in their own code, or supply "advices" for the >>> core functions that work around the problem there. >> Then maybe a simple replacement for the offending function, defined in >> an init file, would also be a possible solution? > > Sure. Though it might be more reliable with advice, since they don't > depend on the loading order. > > The problems I had in mind would be more subtle and independent of the > choice between these two methods. Stefan's latest patch includes > changes in search.c, so it might be difficult to work around in just > Lisp. Again, I haven't examined the problem itself. From unknown Sun Jun 22 04:27:25 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.505 (Entity 5.505) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: Gabriele Nicolardi Subject: bug#67124: closed (Re: bug#67124: 26.3; query-replace Arg out of range with comma option (at end-buffer)) Message-ID: References: <83zfzfqhni.fsf@gnu.org> <020a72b2-b896-4ecf-abab-111a6c1c9eac@medialab.sissa.it> X-Gnu-PR-Message: they-closed 67124 X-Gnu-PR-Package: emacs Reply-To: 67124@debbugs.gnu.org Date: Wed, 15 Nov 2023 16:08:06 +0000 Content-Type: multipart/mixed; boundary="----------=_1700064486-5884-1" This is a multi-part message in MIME format... ------------=_1700064486-5884-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #67124: 26.3; query-replace Arg out of range with comma option (at end-buff= er) which was filed against the emacs package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 67124@debbugs.gnu.org. --=20 67124: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D67124 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1700064486-5884-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 67124-done) by debbugs.gnu.org; 15 Nov 2023 16:07:35 +0000 Received: from localhost ([127.0.0.1]:52988 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r3IQQ-0001Qq-TV for submit@debbugs.gnu.org; Wed, 15 Nov 2023 11:07:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:58120) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r3IQN-0001QS-Vz for 67124-done@debbugs.gnu.org; Wed, 15 Nov 2023 11:07:33 -0500 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 1r3Fmt-0002DE-EK; Wed, 15 Nov 2023 08:18:35 -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=FyGiwxS+eU0dGDTc7xCZScv3sbLP8lGu3XzNrP32pm8=; b=qn5hOJY+gEPW oVzCOjnBv6GdgYd011Oqku6h8c1RbqlE2mFcZ6sv3YXB2KZCD+CICHXF1J+1l5Mq8vV3jO3NEHkkl pSZ6reGWB8hxC28z33QwiHEamLXjW/ddwuk5/ylg8qciIpmd1zWR4WcFSqqzVZIq2HaEWHfyurMD8 uVLUl+zOsAhconVcWszhGjmcYDI2lHp1gDcPJxOyKRsSmR9UiYb255TTbH3YI3aFEz2s1o+Q/gQ81 TmV4YuVBDLjb0SYJoV3wxV+cc35Wmkb9SRx9xrLwd1CpsHZzsAa9glDyZNIdc4lSCBbkWVnBF9GQr iSvBB85MptT1DsCGDyQTHg==; Date: Wed, 15 Nov 2023 15:18:25 +0200 Message-Id: <83zfzfqhni.fsf@gnu.org> From: Eli Zaretskii To: gabriele@medialab.sissa.it In-Reply-To: <83cywfuwta.fsf@gnu.org> (message from Eli Zaretskii on Sun, 12 Nov 2023 11:48:17 +0200) Subject: Re: bug#67124: 26.3; query-replace Arg out of range with comma option (at end-buffer) References: <020a72b2-b896-4ecf-abab-111a6c1c9eac@medialab.sissa.it> <83cywfuwta.fsf@gnu.org> X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 67124-done Cc: monnier@iro.umontreal.ca, 67124-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > Cc: 67124@debbugs.gnu.org > Date: Sun, 12 Nov 2023 11:48:17 +0200 > From: Eli Zaretskii > > > I often type `,` (`comma`) to check the replacement. It happens that, > > some times, I get the error (e.g.): > > > > match-substitute-replacement: Args out of range: #, > > 1667, 1679 > > > > The error doesn't happen if I type `y` (or `n`) > > > > Try this: > > > > (query-replace ",.\\footnote{" ".\\footnote{" nil) > > > > With the string ",.\footnote{" at the end of the buffer. To see the > > error "{" must be the last char in the buffer. > > > > (I see often this bug because I use "narrowing" a lot) > > > > Is it a known bug? > > The kludgey solution in the patch below should fix this. Please see > if it indeed fixes your real-life use cases. I've now installed this on master, and I'm closing this bug. ------------=_1700064486-5884-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 12 Nov 2023 07:51:11 +0000 Received: from localhost ([127.0.0.1]:55030 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r25FN-00088V-Os for submit@debbugs.gnu.org; Sun, 12 Nov 2023 02:51:10 -0500 Received: from lists.gnu.org ([2001:470:142::17]:50924) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r1trD-0005Hl-O1 for submit@debbugs.gnu.org; Sat, 11 Nov 2023 14:41:28 -0500 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 1r1tqR-0006wC-88 for bug-gnu-emacs@gnu.org; Sat, 11 Nov 2023 14:40:39 -0500 Received: from smtp04.cbsolt.net ([185.97.217.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r1tqO-0002eQ-WD for bug-gnu-emacs@gnu.org; Sat, 11 Nov 2023 14:40:38 -0500 Received: from [10.0.2.15] (host-82-60-177-34.retail.telecomitalia.it [82.60.177.34]) by smtp04.cbsolt.net (Postfix) with ESMTPSA id 4SSQyh5yM9z3wbv for ; Sat, 11 Nov 2023 20:40:28 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cbsolt.net; s=201504-di4k2w; t=1699731629; bh=lsZA45SwU4ePu39xBinRdLfQ4w7A6UPFPIxwz+YMK1g=; h=Date:To:Subject:From:From; b=QZjOXsRdFZ9xkTztvWFUHP7TE3knd2kFFWqtvCMzAarP9T+Tmqmk8pdPfCQq8blsL aqEKsTf0asN66NIFZb5QtN73SfJeE2E8f+728Cfh3XgAbkcz0mLXmBON0NJu5tI+ZW XI7CGGpJlDP4CXhzveolK93JrZYqXNxXaZRmEM68= Message-ID: <020a72b2-b896-4ecf-abab-111a6c1c9eac@medialab.sissa.it> Date: Sat, 11 Nov 2023 20:40:27 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: bug-gnu-emacs@gnu.org Subject: 26.3; query-replace Arg out of range with comma option (at end-buffer) Content-Language: en-US From: Gabriele Nicolardi Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=185.97.217.43; envelope-from=gabriele@medialab.sissa.it; helo=smtp04.cbsolt.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: 1.0 (+) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Sun, 12 Nov 2023 02:51:04 -0500 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) Hi, I'm resending the bug report trying to do better than the previous one. When I run `query-replace-regexp` command if I type `?` I get this explanation of the function's options: Type Space or ‘y’ to replace one match, Delete or ‘n’ to skip to next, RET or ‘q’ to exit, Period to replace one match and exit, Comma to replace but not move point immediately, C-r to enter recursive edit (C-M-c to get out again), C-w to delete match and recursive edit, C-l to clear the screen, redisplay, and offer same replacement again, ! to replace all remaining matches in this buffer with no more questions, ^ to move point back to previous match, u to undo previous replacement, U to undo all replacements, E to edit the replacement string. In multi-buffer replacements type ‘Y’ to replace all remaining matches in all remaining buffers with no more questions, ‘N’ to skip to the next buffer without replacing remaining matches in the current buffer. I often type `,` (`comma`) to check the replacement. It happens that, some times, I get the error (e.g.): match-substitute-replacement: Args out of range: #, 1667, 1679 The error doesn't happen if I type `y` (or `n`) Try this: (query-replace ",.\\footnote{" ".\\footnote{" nil) With the string ",.\footnote{" at the end of the buffer. To see the error "{" must be the last char in the buffer. (I see often this bug because I use "narrowing" a lot) Is it a known bug? My emacs version is GNU Emacs 26.3. In GNU Emacs 26.3 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.24.14) of 2020-03-26, modified by Debian built on lcy01-amd64-020 Windowing system distributor 'The X.Org Foundation', version 11.0.12013000 System Description: Ubuntu 20.04.6 LTS Recent messages: Mark set next-line: End of buffer Mark set funcall-interactively: End of buffer Quit Mark set Entering debugger... Mark set previous-line: Beginning of buffer Mark set previous-line: Beginning of buffer Configured using: 'configure --build x86_64-linux-gnu --prefix=/usr --sharedstatedir=/var/lib --libexecdir=/usr/lib --localstatedir=/var/lib --infodir=/usr/share/info --mandir=/usr/share/man --enable-libsystemd --with-pop=yes --enable-locallisppath=/etc/emacs:/usr/local/share/emacs/26.3/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/26.3/site-lisp:/usr/share/emacs/site-lisp --with-sound=alsa --without-gconf --with-mailutils --build x86_64-linux-gnu --prefix=/usr --sharedstatedir=/var/lib --libexecdir=/usr/lib --localstatedir=/var/lib --infodir=/usr/share/info --mandir=/usr/share/man --enable-libsystemd --with-pop=yes --enable-locallisppath=/etc/emacs:/usr/local/share/emacs/26.3/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/26.3/site-lisp:/usr/share/emacs/site-lisp --with-sound=alsa --without-gconf --with-mailutils --with-x=yes --with-x-toolkit=gtk3 --with-toolkit-scroll-bars 'CFLAGS=-g -O2 -fdebug-prefix-map=/build/emacs-mEZBk7/emacs-26.3+1=. -fstack-protector-strong -Wformat -Werror=format-security -Wall' 'CPPFLAGS=-Wdate-time -D_FORTIFY_SOURCE=2' 'LDFLAGS=-Wl,-Bsymbolic-functions -Wl,-z,relro'' Configured features: XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK SOUND GPM DBUS GSETTINGS GLIB NOTIFY ACL LIBSELINUX GNUTLS LIBXML2 FREETYPE M17N_FLT LIBOTF XFT ZLIB TOOLKIT_SCROLL_BARS GTK3 X11 XDBE XIM THREADS LIBSYSTEMD LCMS2 Important settings: value of $LANG: it_IT.UTF-8 locale-coding-system: utf-8-unix Major mode: Lisp Interaction Minor modes in effect: tooltip-mode: t global-eldoc-mode: t eldoc-mode: t electric-indent-mode: t mouse-wheel-mode: t tool-bar-mode: t menu-bar-mode: t file-name-shadow-mode: t global-font-lock-mode: t font-lock-mode: t blink-cursor-mode: t auto-composition-mode: t auto-encryption-mode: t auto-compression-mode: t line-number-mode: t transient-mark-mode: t Load-path shadows: None found. Features: (shadow sort mail-extr emacsbug message rmc puny seq dired dired-loaddefs format-spec rfc822 ...) Memory information: ((conses 16 97042 8905) (symbols 48 20561 1) (miscs 40 86 120) (strings 32 28945 1187) (string-bytes 1 762727) (vectors 16 14159) (vector-slots 8 504582 10748) (floats 8 56 120) (intervals 56 316 55) (buffers 992 12)) ------------=_1700064486-5884-1-- From unknown Sun Jun 22 04:27:25 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.505 (Entity 5.505) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: Gabriele Nicolardi Subject: bug#67050: closed (Re: bug#67124: 26.3; query-replace Arg out of range with comma option (at end-buffer)) Message-ID: References: <83zfzfqhni.fsf@gnu.org> <222dd6ef-3f20-488f-becc-0e654e0de45d@medialab.sissa.it> X-Gnu-PR-Message: they-closed 67050 X-Gnu-PR-Package: emacs Reply-To: 67050@debbugs.gnu.org Date: Wed, 15 Nov 2023 16:08:06 +0000 Content-Type: multipart/mixed; boundary="----------=_1700064486-5884-3" This is a multi-part message in MIME format... ------------=_1700064486-5884-3 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #67124: 26.3; query-replace Arg out of range with comma option (at end-buff= er) which was filed against the emacs package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 67050@debbugs.gnu.org. --=20 67124: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D67124 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1700064486-5884-3 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 67124-done) by debbugs.gnu.org; 15 Nov 2023 16:07:35 +0000 Received: from localhost ([127.0.0.1]:52988 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r3IQQ-0001Qq-TV for submit@debbugs.gnu.org; Wed, 15 Nov 2023 11:07:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:58120) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r3IQN-0001QS-Vz for 67124-done@debbugs.gnu.org; Wed, 15 Nov 2023 11:07:33 -0500 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 1r3Fmt-0002DE-EK; Wed, 15 Nov 2023 08:18:35 -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=FyGiwxS+eU0dGDTc7xCZScv3sbLP8lGu3XzNrP32pm8=; b=qn5hOJY+gEPW oVzCOjnBv6GdgYd011Oqku6h8c1RbqlE2mFcZ6sv3YXB2KZCD+CICHXF1J+1l5Mq8vV3jO3NEHkkl pSZ6reGWB8hxC28z33QwiHEamLXjW/ddwuk5/ylg8qciIpmd1zWR4WcFSqqzVZIq2HaEWHfyurMD8 uVLUl+zOsAhconVcWszhGjmcYDI2lHp1gDcPJxOyKRsSmR9UiYb255TTbH3YI3aFEz2s1o+Q/gQ81 TmV4YuVBDLjb0SYJoV3wxV+cc35Wmkb9SRx9xrLwd1CpsHZzsAa9glDyZNIdc4lSCBbkWVnBF9GQr iSvBB85MptT1DsCGDyQTHg==; Date: Wed, 15 Nov 2023 15:18:25 +0200 Message-Id: <83zfzfqhni.fsf@gnu.org> From: Eli Zaretskii To: gabriele@medialab.sissa.it In-Reply-To: <83cywfuwta.fsf@gnu.org> (message from Eli Zaretskii on Sun, 12 Nov 2023 11:48:17 +0200) Subject: Re: bug#67124: 26.3; query-replace Arg out of range with comma option (at end-buffer) References: <020a72b2-b896-4ecf-abab-111a6c1c9eac@medialab.sissa.it> <83cywfuwta.fsf@gnu.org> X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 67124-done Cc: monnier@iro.umontreal.ca, 67124-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > Cc: 67124@debbugs.gnu.org > Date: Sun, 12 Nov 2023 11:48:17 +0200 > From: Eli Zaretskii > > > I often type `,` (`comma`) to check the replacement. It happens that, > > some times, I get the error (e.g.): > > > > match-substitute-replacement: Args out of range: #, > > 1667, 1679 > > > > The error doesn't happen if I type `y` (or `n`) > > > > Try this: > > > > (query-replace ",.\\footnote{" ".\\footnote{" nil) > > > > With the string ",.\footnote{" at the end of the buffer. To see the > > error "{" must be the last char in the buffer. > > > > (I see often this bug because I use "narrowing" a lot) > > > > Is it a known bug? > > The kludgey solution in the patch below should fix this. Please see > if it indeed fixes your real-life use cases. I've now installed this on master, and I'm closing this bug. ------------=_1700064486-5884-3 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 10 Nov 2023 17:30:40 +0000 Received: from localhost ([127.0.0.1]:50799 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r1VL4-0002CR-Rx for submit@debbugs.gnu.org; Fri, 10 Nov 2023 12:30:40 -0500 Received: from lists.gnu.org ([2001:470:142::17]:56026) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r1UV7-0000ic-PF for submit@debbugs.gnu.org; Fri, 10 Nov 2023 11:36:59 -0500 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 1r1UUN-0003uB-Vl for bug-gnu-emacs@gnu.org; Fri, 10 Nov 2023 11:36:12 -0500 Received: from smtp04.cbsolt.net ([185.97.217.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r1UUK-0000eM-KM for bug-gnu-emacs@gnu.org; Fri, 10 Nov 2023 11:36:11 -0500 Received: from [10.0.2.15] (host-87-8-5-198.retail.telecomitalia.it [87.8.5.198]) by smtp04.cbsolt.net (Postfix) with ESMTPSA id 4SRkwJ0zTkz3wgb for ; Fri, 10 Nov 2023 17:35:59 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cbsolt.net; s=201504-di4k2w; t=1699634162; bh=lDrCW3eCXz2VQ7DMqJdbkSNC4wxFTuGsK9iQDm6HYEQ=; h=Date:To:Subject:From:From; b=lGXbkA0GvQ5n9dcfh6ue166pUlv+GucffvnXP1tinvAiYYnAvCOwkx160ZL7+ztqp Wu237lLY7NY/2r8DUMC5VBntLa6rFHyR51pcrnFPvhgqPlCqa0ZUZ2w3ejhx2DXm7H Wi1OL+T/wGe62d/77+JVT355X0yxCBdO0dwfUN2g= Message-ID: <222dd6ef-3f20-488f-becc-0e654e0de45d@medialab.sissa.it> Date: Fri, 10 Nov 2023 17:35:58 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: bug-gnu-emacs@gnu.org Subject: 26.3; query-replace Arg out of range with comma option (at end-buffer) Content-Language: en-US From: Gabriele Nicolardi Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Received-SPF: pass client-ip=185.97.217.43; envelope-from=gabriele@medialab.sissa.it; helo=smtp04.cbsolt.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: 1.0 (+) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Fri, 10 Nov 2023 12:30:36 -0500 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) Hi, I described the issue on Stackexchange: https://emacs.stackexchange.com/q/79436/15606 I hope that's enough to replicate the problem. Please let me know if you require any further information. Your prompt attention to this matter is highly valued. Gabriele Nicolardi In GNU Emacs 26.3 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.24.14) of 2020-03-26, modified by Debian built on lcy01-amd64-020 Windowing system distributor 'The X.Org Foundation', version 11.0.12013000 System Description: Ubuntu 20.04.6 LTS Recent messages: Undo! [5 times] fix-mult-punct-before-footnote Mark set La punteggiatura ripetuta contiene simboli eterogenei. Scegli quale simbolo mantenere tra "." e ",", La punteggiatura ripetuta contiene simboli eterogenei. Scegli quale simbolo mantenere tra "," e ".", Replaced 0 occurrences Making completion list... Type C-x 1 to delete the help window. Quit Configured using: 'configure --build x86_64-linux-gnu --prefix=/usr --sharedstatedir=/var/lib --libexecdir=/usr/lib --localstatedir=/var/lib --infodir=/usr/share/info --mandir=/usr/share/man --enable-libsystemd --with-pop=yes --enable-locallisppath=/etc/emacs:/usr/local/share/emacs/26.3/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/26.3/site-lisp:/usr/share/emacs/site-lisp --with-sound=alsa --without-gconf --with-mailutils --build x86_64-linux-gnu --prefix=/usr --sharedstatedir=/var/lib --libexecdir=/usr/lib --localstatedir=/var/lib --infodir=/usr/share/info --mandir=/usr/share/man --enable-libsystemd --with-pop=yes --enable-locallisppath=/etc/emacs:/usr/local/share/emacs/26.3/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/26.3/site-lisp:/usr/share/emacs/site-lisp --with-sound=alsa --without-gconf --with-mailutils --with-x=yes --with-x-toolkit=gtk3 --with-toolkit-scroll-bars 'CFLAGS=-g -O2 -fdebug-prefix-map=/build/emacs-mEZBk7/emacs-26.3+1=. -fstack-protector-strong -Wformat -Werror=format-security -Wall' 'CPPFLAGS=-Wdate-time -D_FORTIFY_SOURCE=2' 'LDFLAGS=-Wl,-Bsymbolic-functions -Wl,-z,relro'' Configured features: XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK SOUND GPM DBUS GSETTINGS GLIB NOTIFY ACL LIBSELINUX GNUTLS LIBXML2 FREETYPE M17N_FLT LIBOTF XFT ZLIB TOOLKIT_SCROLL_BARS GTK3 X11 XDBE XIM THREADS LIBSYSTEMD LCMS2 Important settings: value of $LANG: it_IT.UTF-8 locale-coding-system: utf-8-unix Major mode: Lisp Interaction Minor modes in effect: diff-auto-refine-mode: t shell-dirtrack-mode: t show-paren-mode: t tooltip-mode: t global-eldoc-mode: t eldoc-mode: t mouse-wheel-mode: t file-name-shadow-mode: t global-font-lock-mode: t font-lock-mode: t blink-cursor-mode: t auto-composition-mode: t auto-encryption-mode: t auto-compression-mode: t column-number-mode: t line-number-mode: t transient-mark-mode: t Load-path shadows: /home/gabriele/SissaMedialab/elisp/queries-helper hides ~/typeset/elisp/queries-helper /home/gabriele/SissaMedialab/elisp/config hides ~/typeset/elisp/config /home/gabriele/SissaMedialab/elisp/google-search hides ~/typeset/elisp/google-search ~/typeset/elisp/footnote hides /usr/share/emacs/26.3/lisp/mail/footnote Features: (shadow sort mail-extr emacsbug message rmc puny format-spec rfc822 mml mml-sec epa derived epg gnus-util rmail rmail-loaddefs mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr ibuf-ext ibuffer ibuffer-loaddefs jka-compr cl-extra find-dired dired dired-loaddefs grep eieio-opt speedbar sb-image ezimage dframe find-func help-fns radix-tree help-mode cl-print debug texmathp misearch multi-isearch hi-lock server vc-git diff-mode ieee-abbrevs queries-from-guidelines xml-tools typ-editing-mode typ-lib tested-macros experimental-macros proofs-editing-mode layout-and-checks-mode biblio-fix-multiple-refs-interactive xml biblio-arXivnumber-from-title biblio-duplicate-bibitem-hunter biblio-toggle-bibitems-overlay-numbering biblio-j-names-formatter biblio-uncomment-bibitem-at-point cl json-mode json-snatcher js advice sgml-mode dom json map imenu thingatpt cc-mode cc-fonts cc-guess cc-menus cc-cmds cc-styles cc-align cc-engine cc-vars cc-defs request autorevert filenotify mail-utils biblio-proceedings-fix-where-when biblio-macros biblio-revert-author-titles biblio-pybib-cleaner biblio-pybib-execute typ-macros typ-predicates biblio-tools biblio-editing-min-mode biblio-mode-defvars biblio-editing-mode biblio-links-mode equations-static-refs-to-links maths-editing-tools maths-editing-mode easy-mmode preamble-editing-mode figures-files-tools proofs-tex4author unwrapper region-to-pdf production-macros tex-mode compile shell pcomplete comint ansi-color ring latexenc elec-pair typ-backup-tools typ-defvars typ-functions typ-custom-macros edmacro kmacro google-search url url-proxy url-privacy url-expand url-methods url-history url-cookie url-domsuf url-util mailcap windmove finder-inf rx package epg-config url-handlers url-parse auth-source cl-seq eieio eieio-core cl-macs eieio-loaddefs password-cache url-vars seq byte-opt gv bytecomp byte-compile cconv cus-edit easymenu wid-edit cl-loaddefs cl-lib paren cus-start cus-load time-date mule-util tooltip eldoc electric uniquify ediff-hook vc-hooks lisp-float-type mwheel term/x-win x-win term/common-win x-dnd tool-bar dnd fontset image regexp-opt fringe tabulated-list replace newcomment text-mode elisp-mode lisp-mode prog-mode register page menu-bar rfn-eshadow isearch timer select scroll-bar mouse jit-lock font-lock syntax facemenu font-core term/tty-colors frame cl-generic cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek romanian slovak czech european ethiopic indian cyrillic chinese composite charscript charprop case-table epa-hook jka-cmpr-hook help simple abbrev obarray minibuffer cl-preloaded nadvice loaddefs button faces cus-face macroexp files text-properties overlay sha1 md5 base64 format env code-pages mule custom widget hashtable-print-readable backquote threads dbusbind inotify lcms2 dynamic-setting system-font-setting font-render-setting move-toolbar gtk x-toolkit x multi-tty make-network-process emacs) Memory information: ((conses 16 528466 58997) (symbols 48 33025 5) (miscs 40 1111 2179) (strings 32 77031 3414) (string-bytes 1 2274171) (vectors 16 32963) (vector-slots 8 1365680 143002) (floats 8 93 663) (intervals 56 33566 1183) (buffers 992 24)) ------------=_1700064486-5884-3-- From unknown Sun Jun 22 04:27:25 2025 X-Loop: help-debbugs@gnu.org Subject: bug#67124: 26.3; query-replace Arg out of range with comma option (at end-buffer) Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 16 Nov 2023 14:30:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 67124 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Eli Zaretskii Cc: gabriele@medialab.sissa.it, 67124@debbugs.gnu.org Received: via spool by 67124-submit@debbugs.gnu.org id=B67124.170014497319698 (code B ref 67124); Thu, 16 Nov 2023 14:30:03 +0000 Received: (at 67124) by debbugs.gnu.org; 16 Nov 2023 14:29:33 +0000 Received: from localhost ([127.0.0.1]:54840 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r3dN6-00057d-KB for submit@debbugs.gnu.org; Thu, 16 Nov 2023 09:29:33 -0500 Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:3203) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r3dN3-00057M-UR for 67124@debbugs.gnu.org; Thu, 16 Nov 2023 09:29:31 -0500 Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id C6E224422E5; Thu, 16 Nov 2023 09:29:24 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1700144963; bh=C9Og4+niOVp0KzjskbiIZC4Ugns5j5XGzXBLq2SQd9s=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=UXNhdOhyKu2USLC3NhFQRKEwmzb7+xLs7F0cxKLw2zZX406ag0+RHNatQ1qaEwMVW nrOBA7X64NkdjOCHQW22l6W4+NxaVZgRhwZD1CsYFz80SoKdkfiSSSvHC+6btUZfqF k+FToNrcPwDvW3u+9OtIOv1kAEAE0QKCC/UIYGjghAZNYwJSxdOp7FxGcWnrPMQUtS eH4NsfBfObanxLMvF9Pfz7bypr4NFIOYeulYyEollQG1k2Zp7Eqpk1aPczghbg1yyw b4JA5mWcMrqzqFR3LofILhtQsLqAbc68Rji0csWJlkMcKNtTiK+o7Ow75v+4Io0gg3 5nt3KsdplSJiA== Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 71FE6442319; Thu, 16 Nov 2023 09:29:23 -0500 (EST) Received: from pastel (unknown [45.72.227.120]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 45CF4120199; Thu, 16 Nov 2023 09:29:23 -0500 (EST) From: Stefan Monnier In-Reply-To: <83pm0du49e.fsf@gnu.org> (Eli Zaretskii's message of "Mon, 13 Nov 2023 16:17:17 +0200") Message-ID: References: <020a72b2-b896-4ecf-abab-111a6c1c9eac@medialab.sissa.it> <83cywfuwta.fsf@gnu.org> <83pm0du49e.fsf@gnu.org> Date: Thu, 16 Nov 2023 09:29:22 -0500 User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-SPAM-INFO: Spam detection results: 0 ALL_TRUSTED -1 Passed through trusted hosts only via SMTP AWL 0.027 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's domain DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from domain T_SCC_BODY_TEXT_LINE -0.01 - X-SPAM-LEVEL: X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) [ Sorry for my late reply, somehow I missed this reply of yours when you sent it :-( ] >> (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. It returns a different representation of the same number, agreed. But we pass that to `set-match-data` which won't keep that difference, will it? >> 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? It says that we need to adjust (match-beginning 0), while keeping (match-end 0) but it doesn't say that it's OK that we throw away the rest. Probably not important, tho, you're right. >> 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. I think the comment should mention it. >> 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: But the match data adjusted by `replace-match` is not made of markers. It's plain integers which are manually adjusted (by the code which I changed in my patch). > 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. I agree if they were markers that's what would happen. But instead the behavior we see is because the code of `update_search_regs` mimics the behavior of "insert-before" markers both for start and end boundaries of subgroups. My patch tries to make it more careful. >> > ;; `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? >> 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 ;-) :-( Stefan From unknown Sun Jun 22 04:27:25 2025 X-Loop: help-debbugs@gnu.org Subject: bug#67124: 26.3; query-replace Arg out of range with comma option (at end-buffer) Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 16 Nov 2023 14:46:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 67124 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Gabriele Nicolardi Cc: Dmitry Gutov , Eli Zaretskii , 67124@debbugs.gnu.org Received: via spool by 67124-submit@debbugs.gnu.org id=B67124.170014594721873 (code B ref 67124); Thu, 16 Nov 2023 14:46:02 +0000 Received: (at 67124) by debbugs.gnu.org; 16 Nov 2023 14:45:47 +0000 Received: from localhost ([127.0.0.1]:54849 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r3dco-0005gi-Ry for submit@debbugs.gnu.org; Thu, 16 Nov 2023 09:45:47 -0500 Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:34233) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r3dck-0005gJ-Nf for 67124@debbugs.gnu.org; Thu, 16 Nov 2023 09:45:45 -0500 Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id B10CC1000AD; Thu, 16 Nov 2023 09:45:37 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1700145937; bh=XzYXIGpDgVChF8fmzAHmMmJ/HQ+7nBDqyolOeBgK0ws=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=g0f6plbKO0jd9JHggvhvlVZAsbFoFvsi3CbDgliGTB8yS14nquSgKOZZlg0wmAmxK Vbrh6gWHNWMM+lVDCjy2ULSkaWj4CSWxNcHwVcfpAiVdHWG8u8F71N8sZ7cBkVYBTS Q0irlRaPpqGxMJSZxm1AELDmdlnA84jupDUKOYrQ7jfLb1cn5FsGaL3xSVKQU/RyZo fD2138h2Pn/OZ+p7uYYB+SiLhokCdvkJgZo2jgor4AJhtssFq/IdPbU6uupb6zk5Qs TL9f5slmDsJNm1wyyYG89LGvtRO6Bjd+Tiou5qUC8rOIKxkBrdOh49mlTkoLOCcZEW /IbSDZj2u3VXg== Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id F10A0100043; Thu, 16 Nov 2023 09:45:36 -0500 (EST) Received: from pastel (unknown [45.72.227.120]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id C3CF2120209; Thu, 16 Nov 2023 09:45:36 -0500 (EST) From: Stefan Monnier In-Reply-To: (Gabriele Nicolardi's message of "Mon, 13 Nov 2023 16:39:04 +0100") Message-ID: References: <020a72b2-b896-4ecf-abab-111a6c1c9eac@medialab.sissa.it> <83cywfuwta.fsf@gnu.org> <83r0ktu4s7.fsf@gnu.org> <03fc7766-3d3a-394b-e08c-53eb136d40a6@gutov.dev> <83jzqlu3a6.fsf@gnu.org> <383929c4-7921-1a8d-3e6c-29a753ad7e0f@gutov.dev> Date: Thu, 16 Nov 2023 09:45:35 -0500 User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-SPAM-INFO: Spam detection results: 0 ALL_TRUSTED -1 Passed through trusted hosts only via SMTP AWL -0.133 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's domain DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from domain T_SCC_BODY_TEXT_LINE -0.01 - X-SPAM-LEVEL: X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > Ok, I'll wait for the next release, Thank you. I think you might be able to use the following as a temporary fix which should also be harmless when not useful: (advice-add 'replace-match-maybe-edit :before #'my-workaround-for-bug67124) (defun my-workaround-for-bug67124 (&optional _newtext _fixedcase _literal _noedit match-data &rest _) (when (and (integerp (car-safe match-data)) (integerp (car-safe (cdr-safe match-data)))) ;; Make sure the "end" part of `match-data` is a marker ;; so it can't be pointing outside the buffer no matter ;; what the replacement does. (setf (nth 1 match-data) (copy-marker (nth 1 match-data))))) -- Stefan > Il 13/11/23 15:45, Dmitry Gutov ha scritto: >> On 13/11/2023 16:38, Eli Zaretskii wrote: >>>> Date: Mon, 13 Nov 2023 16:21:43 +0200 >>>> Cc:67124@debbugs.gnu.org >>>> From: Dmitry Gutov >>>> >>>> On 13/11/2023 16:06, Eli Zaretskii wrote: >>>>> [Please use Reply All to reply, so that the bug tracker is CC'ed.] >>>>>> Date: Sun, 12 Nov 2023 23:44:43 +0100 >>>>>> From: Gabriele Nicolardi >>>>>> >>>>>> I tested the patch on the MWE I sent to you. Thanks! >>>>>> >>>>>> Now I'm not sure what I should do. I write elisp code used by >>>>>> a production team. We use Emacs to >>>>>> format LaTeX documents of scientific papers. I don't control which >>>>>> version of Emacs my >>>>>> collaborators use. Do you have any suggestions? >>>>> I guess either wait for the next Emacs release or build your own >>>>> Emacs? >>>> I haven't examined the exact problem, but in such cases some people also >>>> either have workarounds in their own code, or supply "advices" for the >>>> core functions that work around the problem there. >>> Then maybe a simple replacement for the offending function, defined in >>> an init file, would also be a possible solution? >> >> Sure. Though it might be more reliable with advice, since they don't >> depend on the loading order. >> >> The problems I had in mind would be more subtle and independent of the >> choice between these two methods. Stefan's latest patch includes changes >> in search.c, so it might be difficult to work around in just Lisp. Again, >> I haven't examined the problem itself. From unknown Sun Jun 22 04:27:25 2025 X-Loop: help-debbugs@gnu.org Subject: bug#67124: 26.3; query-replace Arg out of range with comma option (at end-buffer) Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 16 Nov 2023 14:56:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 67124 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Stefan Monnier Cc: gabriele@medialab.sissa.it, 67124@debbugs.gnu.org Received: via spool by 67124-submit@debbugs.gnu.org id=B67124.170014656025236 (code B ref 67124); Thu, 16 Nov 2023 14:56:02 +0000 Received: (at 67124) by debbugs.gnu.org; 16 Nov 2023 14:56:00 +0000 Received: from localhost ([127.0.0.1]:56409 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r3dmh-0006YV-CI for submit@debbugs.gnu.org; Thu, 16 Nov 2023 09:55:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40850) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r3dme-0006Sx-Pq for 67124@debbugs.gnu.org; Thu, 16 Nov 2023 09:55:57 -0500 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 1r3dmY-00078n-D2; Thu, 16 Nov 2023 09:55:50 -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=T5f2o/HufzKxOW2tIdK2FGPGEP1p805VKAGqdGwbldc=; b=dI5atwS/EE7t 3PO8EP3JwfPhi5G6BlmwU7ZCcnlRrhldZBOc10be+KaUjkkT+TVwbimi8ajwgv161N/CYdwGEtivl Jib1xn3r6MJmaPfNJPYcN8oxtUgch23yxKp7E1g2rgRwcI8EeMPnxqOlU1CdLso3Vba5REKPpbKxk erZmP5kG2AXyLgQ6Yon0MOm23vLx+6Q50IpNaUNvj7oa07hWeb0Kghnf98iZ5bQa4FKPm2uAhJnLA Rg8IHjjNCtc92Z7U2DRP9DfDxSGeVmTJwe+iaRY1P0IoL8AXkB/Q+v5xoq7OA1Vk21/KMCNwABz+F b1gzaMdFUEYsLp75Pmt0hw==; Date: Thu, 16 Nov 2023 16:55:39 +0200 Message-Id: <83o7ftpx1w.fsf@gnu.org> From: Eli Zaretskii In-Reply-To: (message from Stefan Monnier on Thu, 16 Nov 2023 09:29:22 -0500) References: <020a72b2-b896-4ecf-abab-111a6c1c9eac@medialab.sissa.it> <83cywfuwta.fsf@gnu.org> <83pm0du49e.fsf@gnu.org> X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Stefan Monnier > Cc: gabriele@medialab.sissa.it, 67124@debbugs.gnu.org > Date: Thu, 16 Nov 2023 09:29:22 -0500 > > >> > ;; `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? The cause of the bug is that we force the match data back to the buffer position before the replace. As long as that is not removed, the bug will remain. What my kludge did is simply use a marker, so the adjusted position is not clobbered. From unknown Sun Jun 22 04:27:25 2025 X-Loop: help-debbugs@gnu.org Subject: bug#67124: 26.3; query-replace Arg out of range with comma option (at end-buffer) Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 16 Nov 2023 15:36:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 67124 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Eli Zaretskii Cc: Gabriele Nicolardi , 67124@debbugs.gnu.org Received: via spool by 67124-submit@debbugs.gnu.org id=B67124.170014893830267 (code B ref 67124); Thu, 16 Nov 2023 15:36:01 +0000 Received: (at 67124) by debbugs.gnu.org; 16 Nov 2023 15:35:38 +0000 Received: from localhost ([127.0.0.1]:57435 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r3eP3-0007s5-UX for submit@debbugs.gnu.org; Thu, 16 Nov 2023 10:35:38 -0500 Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:47836) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r3eP0-0007rp-2g for 67124@debbugs.gnu.org; Thu, 16 Nov 2023 10:35:36 -0500 Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id EBBD744234C; Thu, 16 Nov 2023 10:35:28 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1700148927; bh=AvCmShF2QCPxCzoNeRmgYm8rSLZ2rbT6OZN34XPFig8=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=dGRxjq2Bo0yEWlf+Z027gkI7/T1Z8uhmP4N1qweNUKHav+3j6qKdi2lnS5bsYf6TS UokjhLH3sR2IHY9QUgeVH2tyJQk8q7Qjxgp82m/aTkLJ8hIUkbELkKi/UYVMpjru5n GUfn+5vq6QZ6xwK0SjUeleMXIR/Za8RuG7JFBLuKExS3ZczPTFGDQ55TL61ONTnkeu 8oSPVT5oZHzHhKQrLkec/E0SczW5p1mHIPuEM3h6BCj0mVNxFjuwA+FuHlbVHu1+G5 TKiOZh5GBGTju6ChM4lq/OPnPSCfvz92GzvwBMkTR15Sk9uKaBAsAsd5QDb8J8h5yO HluNXD2DrYnJg== Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id B2EF2442347; Thu, 16 Nov 2023 10:35:27 -0500 (EST) Received: from pastel (unknown [45.72.227.120]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 87492120277; Thu, 16 Nov 2023 10:35:27 -0500 (EST) From: Stefan Monnier In-Reply-To: (Stefan Monnier's message of "Sun, 12 Nov 2023 22:56:16 -0500") Message-ID: References: <020a72b2-b896-4ecf-abab-111a6c1c9eac@medialab.sissa.it> <83cywfuwta.fsf@gnu.org> Date: Thu, 16 Nov 2023 10:35:26 -0500 User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-SPAM-INFO: Spam detection results: 0 ALL_TRUSTED -1 Passed through trusted hosts only via SMTP AWL 0.027 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's domain DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from domain T_SCC_BODY_TEXT_LINE -0.01 - X-SPAM-LEVEL: X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > 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. [...] > 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. Hmm... not sure what happened, because I just tried it again and it does seem to fix the OP's problem. So I suggest the patch below (adjusted to the new code on `master`). Stefan diff --git a/lisp/replace.el b/lisp/replace.el index 7fec54ecb27..acf6b8a4652 100644 --- a/lisp/replace.el +++ b/lisp/replace.el @@ -2642,16 +2642,9 @@ replace-match-maybe-edit noedit nil))) (set-match-data match-data) (replace-match newtext fixedcase literal) - ;; `query-replace' undo feature needs the beginning of the match position, - ;; but `replace-match' may change it, for instance, with a regexp like "^". - ;; Ensure that this function preserves the beginning of the match position - ;; (bug#31492). But we need to avoid clobbering the end of the match with - ;; the original match-end position, since `replace-match' could have made - ;; that incorrect or even invalid (bug#67124). - (set-match-data (list (car match-data) (nth 1 (match-data)))) ;; `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))) + (when backward (goto-char (match-beginning 0))) noedit) (defvar replace-update-post-hook nil diff --git a/src/search.c b/src/search.c index 692d8488049..177bb720641 100644 --- a/src/search.c +++ b/src/search.c @@ -3142,9 +3142,16 @@ update_search_regs (ptrdiff_t oldstart, ptrdiff_t oldend, ptrdiff_t newend) for (i = 0; i < search_regs.num_regs; i++) { - if (search_regs.start[i] >= oldend) + if (search_regs.start[i] <= oldstart) + /* If the subgroup that `replace-match` is modifying encloses the + subgroup `i`, then its `start` position should stay unchanged. + That's always true for subgroup 0. + For other subgroups it depends on details we don't have, so + we optimistically assume that it also holds for them. */ + ; + else if (search_regs.start[i] >= oldend) search_regs.start[i] += change; - else if (search_regs.start[i] > oldstart) + else search_regs.start[i] = oldstart; if (search_regs.end[i] >= oldend) search_regs.end[i] += change; From unknown Sun Jun 22 04:27:25 2025 X-Loop: help-debbugs@gnu.org Subject: bug#67124: 26.3; query-replace Arg out of range with comma option (at end-buffer) 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 X-GNU-PR-Keywords: To: Eli Zaretskii Cc: gabriele@medialab.sissa.it, 67124@debbugs.gnu.org Received: via spool by 67124-submit@debbugs.gnu.org id=B67124.17001513722186 (code B ref 67124); Thu, 16 Nov 2023 16:17:02 +0000 Received: (at 67124) by debbugs.gnu.org; 16 Nov 2023 16:16:12 +0000 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 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 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== 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) 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) From: Stefan Monnier In-Reply-To: <83o7ftpx1w.fsf@gnu.org> (Eli Zaretskii's message of "Thu, 16 Nov 2023 16:55:39 +0200") Message-ID: References: <020a72b2-b896-4ecf-abab-111a6c1c9eac@medialab.sissa.it> <83cywfuwta.fsf@gnu.org> <83pm0du49e.fsf@gnu.org> <83o7ftpx1w.fsf@gnu.org> Date: Thu, 16 Nov 2023 11:15:56 -0500 User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-SPAM-INFO: Spam detection results: 0 ALL_TRUSTED -1 Passed through trusted hosts only via SMTP AWL -0.132 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's domain DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from domain T_SCC_BODY_TEXT_LINE -0.01 - X-SPAM-LEVEL: X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) >> >> > ;; `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 From unknown Sun Jun 22 04:27:25 2025 X-Loop: help-debbugs@gnu.org Subject: bug#67124: 26.3; query-replace Arg out of range with comma option (at end-buffer) Resent-From: Gabriele Nicolardi Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 16 Nov 2023 16:28:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 67124 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Stefan Monnier Cc: Dmitry Gutov , Eli Zaretskii , 67124@debbugs.gnu.org Received: via spool by 67124-submit@debbugs.gnu.org id=B67124.17001520753381 (code B ref 67124); Thu, 16 Nov 2023 16:28:02 +0000 Received: (at 67124) by debbugs.gnu.org; 16 Nov 2023 16:27:55 +0000 Received: from localhost ([127.0.0.1]:57484 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r3fDe-0000sT-JV for submit@debbugs.gnu.org; Thu, 16 Nov 2023 11:27:54 -0500 Received: from smtp03.cbsolt.net ([185.97.217.42]:52592) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r3fDb-0000sE-VQ for 67124@debbugs.gnu.org; Thu, 16 Nov 2023 11:27:53 -0500 Received: from [10.0.2.15] (host-82-60-177-34.retail.telecomitalia.it [82.60.177.34]) by smtp03.cbsolt.net (Postfix) with ESMTPSA id 4SWQS11mvmz3wfV; Thu, 16 Nov 2023 17:27:45 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cbsolt.net; s=201504-di4k2w; t=1700152066; bh=3Vn06NugsZMgUnknAlV8T6wmNQXHYw5gxwPEykI/RKI=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=BeQCCabns/DCVglV369/ofN7ll3nqADYIy12DBHvvELth+QOmrXXKiJZMDN1DRsSH 8yc8QQZihd4+rKokyFgqyEn04DstVc8MQ9+B7whap7HhCaMRQk9Mq9lNcsvR1LSBqw 1xGaVcph23CrsjpuG3GKut0uDIm04XFknCOBdLp4= Message-ID: <6ce88bd9-7041-4cd6-a7a6-42a7e0535112@medialab.sissa.it> Date: Thu, 16 Nov 2023 17:27:44 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US References: <020a72b2-b896-4ecf-abab-111a6c1c9eac@medialab.sissa.it> <83cywfuwta.fsf@gnu.org> <83r0ktu4s7.fsf@gnu.org> <03fc7766-3d3a-394b-e08c-53eb136d40a6@gutov.dev> <83jzqlu3a6.fsf@gnu.org> <383929c4-7921-1a8d-3e6c-29a753ad7e0f@gutov.dev> From: Gabriele Nicolardi In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) Il 16/11/23 15:45, Stefan Monnier ha scritto: >> Ok, I'll wait for the next release, Thank you. > I think you might be able to use the following as a temporary fix which > should also be harmless when not useful: > > (advice-add 'replace-match-maybe-edit :before > #'my-workaround-for-bug67124) > (defun my-workaround-for-bug67124 (&optional _newtext _fixedcase > _literal _noedit match-data > &rest _) > (when (and (integerp (car-safe match-data)) > (integerp (car-safe (cdr-safe match-data)))) > ;; Make sure the "end" part of `match-data` is a marker > ;; so it can't be pointing outside the buffer no matter > ;; what the replacement does. > (setf (nth 1 match-data) > (copy-marker (nth 1 match-data))))) > > > -- Stefan Thank you! I'll study the code and l'll try it! Gabriele > >> Il 13/11/23 15:45, Dmitry Gutov ha scritto: >>> On 13/11/2023 16:38, Eli Zaretskii wrote: >>>>> Date: Mon, 13 Nov 2023 16:21:43 +0200 >>>>> Cc:67124@debbugs.gnu.org >>>>> From: Dmitry Gutov >>>>> >>>>> On 13/11/2023 16:06, Eli Zaretskii wrote: >>>>>> [Please use Reply All to reply, so that the bug tracker is CC'ed.] >>>>>>> Date: Sun, 12 Nov 2023 23:44:43 +0100 >>>>>>> From: Gabriele Nicolardi >>>>>>> >>>>>>> I tested the patch on the MWE I sent to you. Thanks! >>>>>>> >>>>>>> Now I'm not sure what I should do. I write elisp code used by >>>>>>> a production team. We use Emacs to >>>>>>> format LaTeX documents of scientific papers. I don't control which >>>>>>> version of Emacs my >>>>>>> collaborators use. Do you have any suggestions? >>>>>> I guess either wait for the next Emacs release or build your own >>>>>> Emacs? >>>>> I haven't examined the exact problem, but in such cases some people also >>>>> either have workarounds in their own code, or supply "advices" for the >>>>> core functions that work around the problem there. >>>> Then maybe a simple replacement for the offending function, defined in >>>> an init file, would also be a possible solution? >>> Sure. Though it might be more reliable with advice, since they don't >>> depend on the loading order. >>> >>> The problems I had in mind would be more subtle and independent of the >>> choice between these two methods. Stefan's latest patch includes changes >>> in search.c, so it might be difficult to work around in just Lisp. Again, >>> I haven't examined the problem itself. From unknown Sun Jun 22 04:27:25 2025 X-Loop: help-debbugs@gnu.org Subject: bug#67124: 26.3; query-replace Arg out of range with comma option (at end-buffer) Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 16 Nov 2023 16:52:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 67124 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Stefan Monnier Cc: gabriele@medialab.sissa.it, 67124@debbugs.gnu.org Received: via spool by 67124-submit@debbugs.gnu.org id=B67124.17001534856111 (code B ref 67124); Thu, 16 Nov 2023 16:52:02 +0000 Received: (at 67124) by debbugs.gnu.org; 16 Nov 2023 16:51:25 +0000 Received: from localhost ([127.0.0.1]:57494 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r3faO-0001aV-Ke for submit@debbugs.gnu.org; Thu, 16 Nov 2023 11:51:25 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:44398) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r3faJ-0001aC-SK for 67124@debbugs.gnu.org; Thu, 16 Nov 2023 11:51:23 -0500 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 1r3faD-00034b-68; Thu, 16 Nov 2023 11:51:13 -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=NsNjcXAbnxoLinpwkhQY3QBbgupBwN2qtFLCNk+4KwU=; b=FPyqWRVApgVG sDuZq2FBFpT4xF7xqeSQlCzAdm3QtwFJ3bEiV1JkthJRu0rKr9deRvyaQL7qIE5f5Oe4YUrAUaRmX dthcKGK8jvL0KLdjSJjWJ7SmNmkRT5pkUVltN5aJRPi6rXSJA7uTY1YgDBjqvusz+xUgo7NG78ntt K6oWQbdMs5Cy0jWEBGKwLP0fr0BMPLj6IZ60sqBJBhtRNxq2nfE2ERIT+Ks+z6Ww3pDSB3O18nKAS /YAkDJtXCjB988g7tBJtZ+fsyf5NcvFji5s2HNgphmBvkCkdaeQfctWV/1v7A7qttPo6AOn4okgzF u/AUe/RNBqHcP3VwIs9oEw==; Date: Thu, 16 Nov 2023 18:51:05 +0200 Message-Id: <83leaxprpi.fsf@gnu.org> From: Eli Zaretskii In-Reply-To: (message from Stefan Monnier on Thu, 16 Nov 2023 10:35:26 -0500) References: <020a72b2-b896-4ecf-abab-111a6c1c9eac@medialab.sissa.it> <83cywfuwta.fsf@gnu.org> X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Stefan Monnier > Cc: Gabriele Nicolardi , 67124@debbugs.gnu.org > Date: Thu, 16 Nov 2023 10:35:26 -0500 > > > 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. > > Hmm... not sure what happened, because I just tried it again and it does > seem to fix the OP's problem. Are you sure? > So I suggest the patch below (adjusted to the new code on `master`). > > > Stefan > > > diff --git a/lisp/replace.el b/lisp/replace.el > index 7fec54ecb27..acf6b8a4652 100644 > --- a/lisp/replace.el > +++ b/lisp/replace.el > @@ -2642,16 +2642,9 @@ replace-match-maybe-edit > noedit nil))) > (set-match-data match-data) Why do we still need this line? > ;; `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))) > + (when backward (goto-char (match-beginning 0))) Why this unrelated change? is something wrong with the original code? > --- a/src/search.c > +++ b/src/search.c > @@ -3142,9 +3142,16 @@ update_search_regs (ptrdiff_t oldstart, ptrdiff_t oldend, ptrdiff_t newend) > > for (i = 0; i < search_regs.num_regs; i++) > { > - if (search_regs.start[i] >= oldend) > + if (search_regs.start[i] <= oldstart) > + /* If the subgroup that `replace-match` is modifying encloses the > + subgroup `i`, then its `start` position should stay unchanged. > + That's always true for subgroup 0. I've read this part of the comment many times, and I still don't understand what you are trying to convey there, and thus don't understand the new 'if' clause you added. In particular, how come this was never something brought to our attention? the comment seems to imply that replace-match was somehow badly broken since forever. And please don't use Markdown's markup in our code. Still confused... From unknown Sun Jun 22 04:27:25 2025 X-Loop: help-debbugs@gnu.org Subject: bug#67124: 26.3; query-replace Arg out of range with comma option (at end-buffer) Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 16 Nov 2023 16:57:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 67124 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Stefan Monnier Cc: gabriele@medialab.sissa.it, 67124@debbugs.gnu.org Received: via spool by 67124-submit@debbugs.gnu.org id=B67124.17001537756568 (code B ref 67124); Thu, 16 Nov 2023 16:57:01 +0000 Received: (at 67124) by debbugs.gnu.org; 16 Nov 2023 16:56:15 +0000 Received: from localhost ([127.0.0.1]:57507 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r3ff4-0001hs-MQ for submit@debbugs.gnu.org; Thu, 16 Nov 2023 11:56:15 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:56572) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r3ff2-0001hf-Ms for 67124@debbugs.gnu.org; Thu, 16 Nov 2023 11:56:13 -0500 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 1r3fex-0004j0-9t; Thu, 16 Nov 2023 11:56:07 -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=5UHBzteAXGjV77DZu8WZJvfqBL+eJrC6ymmpMLN1XJY=; b=VW5SrV5h5CMi qZPg3Rkikm9NB0UJdmgGE/ivYGjLmkXQFguGNnFHPW5zFRbI1bTEfKjYv2Hvr2zWtOO1NyOr9JO3e ZFJjIvci+kx5nk1TYal3zF/KPMW+zIWJb0mPBQOk0FTZEkps/js/mjJ9mD+YKH6U2awq9FhJTurTX R/Viv3CRdBnDz/V5/NHtGvEvMPWVv8HjRF0y57RAhROKbnd5sTOTSENWUGWG3KuRBha37QA/SLJPY l9Gbgo3i0ppda4n/j9zKNPqb3WQPun2TOYGhVRZ87Sk9leGzRDyG7zThkvJUZfsz5bDK7+d6Os/ZC aYlKCYB3A7w82sCwSPZBFQ==; Date: Thu, 16 Nov 2023 18:56:00 +0200 Message-Id: <83jzqhprhb.fsf@gnu.org> From: Eli Zaretskii In-Reply-To: (message from Stefan Monnier on Thu, 16 Nov 2023 11:15:56 -0500) References: <020a72b2-b896-4ecf-abab-111a6c1c9eac@medialab.sissa.it> <83cywfuwta.fsf@gnu.org> <83pm0du49e.fsf@gnu.org> <83o7ftpx1w.fsf@gnu.org> X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Stefan Monnier > Cc: gabriele@medialab.sissa.it, 67124@debbugs.gnu.org > Date: Thu, 16 Nov 2023 11:15:56 -0500 > > > 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? Because of markers vs positions, as I've tried to explain. The difference is minor, of course. > > 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. Yes, but match-data (the function) returns updated positions, which behave like markers across the replace-match call. > 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`). Yes. > 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). Yes. From unknown Sun Jun 22 04:27:25 2025 X-Loop: help-debbugs@gnu.org Subject: bug#67124: 26.3; query-replace Arg out of range with comma option (at end-buffer) Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 16 Nov 2023 18:02:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 67124 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Eli Zaretskii Cc: gabriele@medialab.sissa.it, 67124@debbugs.gnu.org Received: via spool by 67124-submit@debbugs.gnu.org id=B67124.17001576965538 (code B ref 67124); Thu, 16 Nov 2023 18:02:02 +0000 Received: (at 67124) by debbugs.gnu.org; 16 Nov 2023 18:01:36 +0000 Received: from localhost ([127.0.0.1]:44467 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r3ggK-0001RF-2y for submit@debbugs.gnu.org; Thu, 16 Nov 2023 13:01:36 -0500 Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:42531) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r3ggH-0001R2-WD for 67124@debbugs.gnu.org; Thu, 16 Nov 2023 13:01:34 -0500 Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id CA1FC804F5; Thu, 16 Nov 2023 13:01:28 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1700157687; bh=+kimbcJuLh81j3ootCUrDw9pti/rnYQcLqY80BYFyRs=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=kFi3qNIIYiIDLVfV+v14q3uDjoSM+yhrg1rAg2MNmC1vxDZO6oZmXJxkL68NBcPCp XWWdIKUBOPuWZ2NNiRT3NCSZ+P+jvw53BFW5+4ikXOBVDGO8UYYJgefCisgITX7i/f iABrRBvIbd4X01AQkBSpzLx9pboDfCChHReG7AsN8x5ZKazxomLKtd7NTrZBrL4xAD Y5kCsCrxOqQfYyMbnaVzKBuWVfUNsaYqZUIHXjVK3EHNAFBbnTmrqqAxJnDuwe+LQs g2G/C7aJTxqFF3nzSWyj4ZoUbteT16tvFJ9+Px1882+dwsexpYmsdbmcOtOft9hwF+ KZgnClaH7mw3w== Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id D811D80385; Thu, 16 Nov 2023 13:01:27 -0500 (EST) Received: from pastel (unknown [45.72.227.120]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id AC5CA12049E; Thu, 16 Nov 2023 13:01:27 -0500 (EST) From: Stefan Monnier In-Reply-To: <83jzqhprhb.fsf@gnu.org> (Eli Zaretskii's message of "Thu, 16 Nov 2023 18:56:00 +0200") Message-ID: References: <020a72b2-b896-4ecf-abab-111a6c1c9eac@medialab.sissa.it> <83cywfuwta.fsf@gnu.org> <83pm0du49e.fsf@gnu.org> <83o7ftpx1w.fsf@gnu.org> <83jzqhprhb.fsf@gnu.org> Date: Thu, 16 Nov 2023 13:01:27 -0500 User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-SPAM-INFO: Spam detection results: 0 ALL_TRUSTED -1 Passed through trusted hosts only via SMTP AWL 0.021 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's domain DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from domain T_SCC_BODY_TEXT_LINE -0.01 - X-SPAM-LEVEL: X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) >> > 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? > > Because of markers vs positions, as I've tried to explain. The > difference is minor, of course. But `goto-char` doesn't care about that difference, and no buffer will be changed between the time we call `match-data` (thus creating the markers) and the time we use those markers, so going through markers is just extra work for no benefit. IOW, I still don't understand how "markers vs positions" is relevant in (when backward (goto-char (nth 0 match-data))) >> > 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. > > Yes, but match-data (the function) returns updated positions, which > behave like markers across the replace-match call. But the positions have already been updated. So (match-data t) would also return those updated positions, even though it doesn't use markers. Stefan From unknown Sun Jun 22 04:27:25 2025 X-Loop: help-debbugs@gnu.org Subject: bug#67124: 26.3; query-replace Arg out of range with comma option (at end-buffer) Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 16 Nov 2023 18:24:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 67124 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Eli Zaretskii Cc: gabriele@medialab.sissa.it, 67124@debbugs.gnu.org Received: via spool by 67124-submit@debbugs.gnu.org id=B67124.17001590418515 (code B ref 67124); Thu, 16 Nov 2023 18:24:02 +0000 Received: (at 67124) by debbugs.gnu.org; 16 Nov 2023 18:24:01 +0000 Received: from localhost ([127.0.0.1]:44479 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r3h20-0002DF-Vk for submit@debbugs.gnu.org; Thu, 16 Nov 2023 13:24:01 -0500 Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:32802) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r3h1v-0002Cw-TI for 67124@debbugs.gnu.org; Thu, 16 Nov 2023 13:23:59 -0500 Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id BDBF5804F5; Thu, 16 Nov 2023 13:23:50 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1700159029; bh=e3VFHjG9p11hyfYLzS3ZNReMA5FS3V5Pm4SNLqv7zUQ=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=BhB31vtLJlSZDHLnHk1xpfmhLaC5QEX7p8TrMFfYAVBoN0aZE21RraeN4PSYxnXm2 PjrWmSaPGViOr9Wn6CBaR14MWPjaqiBrqmTaGDfRPEOnT1zD6Q/B6dvRnzIeaWokO/ ugizR8HrtnScYmTQ3CiUGBM9XD5FK+0K2fi5LAV8S2XFZHdky8BhPKalleGeCXjBt9 sr2NvcH28cEeEruoyL1eEABUNFuexDX1ngd16GZUkU1RfeS2Tx4+vGBBGUXjswrRca XDA6rSr3o4N1sx5GU2zXMdOI5onoL+40eHimMyxWxnoRf5gNIcKj4IuCPRvbwPaGQi HBV8Tj44FEztg== Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id B23EA80385; Thu, 16 Nov 2023 13:23:49 -0500 (EST) Received: from pastel (unknown [45.72.227.120]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 86FB512044B; Thu, 16 Nov 2023 13:23:49 -0500 (EST) From: Stefan Monnier In-Reply-To: <83leaxprpi.fsf@gnu.org> (Eli Zaretskii's message of "Thu, 16 Nov 2023 18:51:05 +0200") Message-ID: References: <020a72b2-b896-4ecf-abab-111a6c1c9eac@medialab.sissa.it> <83cywfuwta.fsf@gnu.org> <83leaxprpi.fsf@gnu.org> Date: Thu, 16 Nov 2023 13:23:48 -0500 User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-SPAM-INFO: Spam detection results: 0 ALL_TRUSTED -1 Passed through trusted hosts only via SMTP AWL 0.021 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's domain DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from domain T_SCC_BODY_TEXT_LINE -0.01 - X-SPAM-LEVEL: X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) >> > 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. >> Hmm... not sure what happened, because I just tried it again and it does >> seem to fix the OP's problem. > Are you sure? Well, since it didn't first time I tried, no, I'm not sure. But the more I look at it, the more I'm sure that it was just a pilot error first time around. >> diff --git a/lisp/replace.el b/lisp/replace.el >> index 7fec54ecb27..acf6b8a4652 100644 >> --- a/lisp/replace.el >> +++ b/lisp/replace.el >> @@ -2642,16 +2642,9 @@ replace-match-maybe-edit >> noedit nil))) >> (set-match-data match-data) > > Why do we still need this line? IIUC this line is there because the code between the original regexp match and the `replace-match` itself is large and thus likely to mess the match data. >> ;; `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))) >> + (when backward (goto-char (match-beginning 0))) > > Why this unrelated change? is something wrong with the original code? No, indeed, it's unrelated and not really better. >> --- a/src/search.c >> +++ b/src/search.c >> @@ -3142,9 +3142,16 @@ update_search_regs (ptrdiff_t oldstart, ptrdiff_t oldend, ptrdiff_t newend) >> >> for (i = 0; i < search_regs.num_regs; i++) >> { >> - if (search_regs.start[i] >= oldend) >> + if (search_regs.start[i] <= oldstart) >> + /* If the subgroup that `replace-match` is modifying encloses the >> + subgroup `i`, then its `start` position should stay unchanged. >> + That's always true for subgroup 0. > > I've read this part of the comment many times, and I still don't > understand what you are trying to convey there, and thus don't > understand the new 'if' clause you added. In particular, how come > this was never something brought to our attention? the comment seems > to imply that replace-match was somehow badly broken since forever. `replace-match` goes through the trouble of trying to keep the match-data valid by moving the subgroup positions. The way it does it currently is sometimes flat out incorrect and other times debatable. For end positions, we do: if (search_regs.end[i] >= oldend) search_regs.end[i] += change; else if (search_regs.end[i] > oldstart) search_regs.end[i] = oldstart; which means that positions beyond (or at the end of) the change are moved appropriately, positions before (or at the beginning of) the change are left untouched and positions strictly within the change are moved to the beginning of the change. If the position is both at start and end at the same time, we move them, assuming that they're more at the end than at the start. For subgroup 0, this is definitely correct. For other subgroups, it depends on the inclusion or relative position of that subgroup with the subgroup that `replace-match` is replacing. E.g. if I matched "\\(\\)\\(\\(\\)\\)\\(\\)" and I replace subgroup 3 with "hi", then the ideal behavior would be to move the end of subgroups 0, 2, 3, and 4 but not 1. For start positions, we do the same: if (search_regs.start[i] >= oldend) search_regs.start[i] += change; else if (search_regs.start[i] > oldstart) search_regs.start[i] = oldstart; When oldstart < oldend this works OK, but when they're equal, moving the start position is definitely wrong for subgroup 0 and is often wrong for others as well. In the above regexp example, we should ideally move the start position of subgroup 4 only and we should leave the other ones unchanged. `update_search_regs` doesn't have enough information to figure out which subgroup is before/after/around/within some other subgroup and it isn't even told which subgroup is being updated by `replace-match`, so the best it can do is to either move them all or move none. The current code moves them all, which is always wrong for start[0]. My patch intends to make the other choice so it will get it wrong for start[4] in the above example (just like the current code gets it wrong for end[1]) but it will get it right for the other ones. > And please don't use Markdown's markup in our code. Oops, thanks for catching it. Stefan From unknown Sun Jun 22 04:27:25 2025 X-Loop: help-debbugs@gnu.org Subject: bug#67124: 26.3; query-replace Arg out of range with comma option (at end-buffer) Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 16 Nov 2023 18:36:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 67124 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Stefan Monnier Cc: gabriele@medialab.sissa.it, 67124@debbugs.gnu.org Received: via spool by 67124-submit@debbugs.gnu.org id=B67124.17001597389966 (code B ref 67124); Thu, 16 Nov 2023 18:36:02 +0000 Received: (at 67124) by debbugs.gnu.org; 16 Nov 2023 18:35:38 +0000 Received: from localhost ([127.0.0.1]:44501 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r3hDF-0002ag-MG for submit@debbugs.gnu.org; Thu, 16 Nov 2023 13:35:38 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35384) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r3hDC-0002aI-P6 for 67124@debbugs.gnu.org; Thu, 16 Nov 2023 13:35:35 -0500 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 1r3hD5-0004Tn-Sk; Thu, 16 Nov 2023 13:35:27 -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=5DBBTnFJN1mECBgvPZp4a98at7i1/Thpsw7C5/JiRwk=; b=lvafridFze8r uFwBlJyzbOMlGvlbPr6cjVXHTxwieBNs8u2XTGF9+lFaBYombLdBkg20UD1c/1sN/4Aoevac4JWvg DtmINhsGsGm9eAMEtohO/gjiEYCmcsPXfHPHjOJki8fELMWggqM+13ivodt3ZwaR9Ed0TFA1O6GWa nNdFjN8H9KOGNPb3/HylW2CkLyMPu4JZpcMM6WJZaUtYoOWkIpFBEr/LMb67SqJvfW7acOwvoNRKQ syEtyxpGz7gszVkZu5XNS0y+H6NcaHpAQygE0kynNf1bVWsHaUlD5SDnKpbpSLRxY055BrTt1PsBc 7hE3OzMSTGhDj/nA1SQGVQ==; Date: Thu, 16 Nov 2023 20:34:59 +0200 Message-Id: <83il61pmwc.fsf@gnu.org> From: Eli Zaretskii In-Reply-To: (message from Stefan Monnier on Thu, 16 Nov 2023 13:01:27 -0500) References: <020a72b2-b896-4ecf-abab-111a6c1c9eac@medialab.sissa.it> <83cywfuwta.fsf@gnu.org> <83pm0du49e.fsf@gnu.org> <83o7ftpx1w.fsf@gnu.org> <83jzqhprhb.fsf@gnu.org> X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Stefan Monnier > Cc: gabriele@medialab.sissa.it, 67124@debbugs.gnu.org > Date: Thu, 16 Nov 2023 13:01:27 -0500 > > >> > 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? > > > > Because of markers vs positions, as I've tried to explain. The > > difference is minor, of course. > > But `goto-char` doesn't care about that difference, and no buffer will > be changed between the time we call `match-data` (thus creating the > markers) and the time we use those markers, so going through markers is > just extra work for no benefit. > > IOW, I still don't understand how "markers vs positions" is relevant in > > (when backward (goto-char (nth 0 match-data))) > > >> > 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. > > > > Yes, but match-data (the function) returns updated positions, which > > behave like markers across the replace-match call. > > But the positions have already been updated. So > > (match-data t) > > would also return those updated positions, even though it doesn't > use markers. We are both saying the same things, just past each other. There's no disagreement or argument here between us. From unknown Sun Jun 22 04:27:25 2025 X-Loop: help-debbugs@gnu.org Subject: bug#67124: 26.3; query-replace Arg out of range with comma option (at end-buffer) Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 18 Nov 2023 10:19:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 67124 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Stefan Monnier Cc: gabriele@medialab.sissa.it, 67124@debbugs.gnu.org Received: via spool by 67124-submit@debbugs.gnu.org id=B67124.17003027052131 (code B ref 67124); Sat, 18 Nov 2023 10:19:01 +0000 Received: (at 67124) by debbugs.gnu.org; 18 Nov 2023 10:18:25 +0000 Received: from localhost ([127.0.0.1]:47855 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r4IPA-0000YI-OC for submit@debbugs.gnu.org; Sat, 18 Nov 2023 05:18:25 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37714) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r4IP8-0000Y3-J9 for 67124@debbugs.gnu.org; Sat, 18 Nov 2023 05:18:23 -0500 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 1r4IP1-0008N5-1e; Sat, 18 Nov 2023 05:18:15 -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=pYrBng2EQ0hzBtsGkz7+WAfElVjLo9mTNdv7/BbFfuk=; b=AxCFzdF/iac+ 2rq5047fqnOxhcn/OP6xidRu95QAx+gMHLWO2NS9T7sO4mwPD7ifEaVRpfEGz1T5nr6jET0rRmWkx sHL82RofunwCPUGcoQ9QNCqYPMLGMRNB/Pbl+dIFl4Xbh1u+i3HMfy1kV5QG3CVVjau5O2AONRUU4 MHXPDDSCrdQ11aTk+PuOnfk/l1sX7dHnpvLJn/nPvOdXswf6Xr7cpY+9cnP+pCL7K0pk4np08OrsY KxWWhUHAmW+4MmeaCgOA7X3NNwxX76Cxsax8osvRnUFKASapGqhhudm8tlMN75Q/9ePrz6rrI/M/z hmnWPqeeThct6zxDIQQ51Q==; Date: Sat, 18 Nov 2023 12:18:12 +0200 Message-Id: <83msvbmkkb.fsf@gnu.org> From: Eli Zaretskii In-Reply-To: (message from Stefan Monnier on Thu, 16 Nov 2023 13:23:48 -0500) References: <020a72b2-b896-4ecf-abab-111a6c1c9eac@medialab.sissa.it> <83cywfuwta.fsf@gnu.org> <83leaxprpi.fsf@gnu.org> X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Stefan Monnier > Cc: gabriele@medialab.sissa.it, 67124@debbugs.gnu.org > Date: Thu, 16 Nov 2023 13:23:48 -0500 > > >> --- a/src/search.c > >> +++ b/src/search.c > >> @@ -3142,9 +3142,16 @@ update_search_regs (ptrdiff_t oldstart, ptrdiff_t oldend, ptrdiff_t newend) > >> > >> for (i = 0; i < search_regs.num_regs; i++) > >> { > >> - if (search_regs.start[i] >= oldend) > >> + if (search_regs.start[i] <= oldstart) > >> + /* If the subgroup that `replace-match` is modifying encloses the > >> + subgroup `i`, then its `start` position should stay unchanged. > >> + That's always true for subgroup 0. > > > > I've read this part of the comment many times, and I still don't > > understand what you are trying to convey there, and thus don't > > understand the new 'if' clause you added. In particular, how come > > this was never something brought to our attention? the comment seems > > to imply that replace-match was somehow badly broken since forever. > > `replace-match` goes through the trouble of trying to keep the > match-data valid by moving the subgroup positions. > > The way it does it currently is sometimes flat out incorrect and other > times debatable. For end positions, we do: > > if (search_regs.end[i] >= oldend) > search_regs.end[i] += change; > else if (search_regs.end[i] > oldstart) > search_regs.end[i] = oldstart; > > which means that positions beyond (or at the end of) the change are > moved appropriately, positions before (or at the beginning of) the change > are left untouched and positions strictly within the change are moved to > the beginning of the change. > If the position is both at start and end at the same time, we move them, > assuming that they're more at the end than at the start. For subgroup > 0, this is definitely correct. For other subgroups, it depends on the > inclusion or relative position of that subgroup with the subgroup that > `replace-match` is replacing. E.g. if I matched > "\\(\\)\\(\\(\\)\\)\\(\\)" and I replace subgroup 3 with "hi", then the > ideal behavior would be to move the end of subgroups 0, 2, 3, and 4 but > not 1. > > For start positions, we do the same: > > if (search_regs.start[i] >= oldend) > search_regs.start[i] += change; > else if (search_regs.start[i] > oldstart) > search_regs.start[i] = oldstart; > > When oldstart < oldend this works OK, but when they're equal, moving the > start position is definitely wrong for subgroup 0 and is often wrong for > others as well. In the above regexp example, we should ideally move the > start position of subgroup 4 only and we should leave the other > ones unchanged. > > `update_search_regs` doesn't have enough information to figure out which > subgroup is before/after/around/within some other subgroup and it isn't > even told which subgroup is being updated by `replace-match`, so the > best it can do is to either move them all or move none. The current > code moves them all, which is always wrong for start[0]. > My patch intends to make the other choice so it will get it wrong for > start[4] in the above example (just like the current code gets it wrong > for end[1]) but it will get it right for the other ones. Please include at least some, if not all, of this extended explanation in the comments there. And I think you can install your changes on master. Thanks. From unknown Sun Jun 22 04:27:25 2025 X-Loop: help-debbugs@gnu.org Subject: bug#67124: 26.3; query-replace Arg out of range with comma option (at end-buffer) Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 18 Nov 2023 16:45:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 67124 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Eli Zaretskii Cc: gabriele@medialab.sissa.it, 67124@debbugs.gnu.org Received: via spool by 67124-submit@debbugs.gnu.org id=B67124.170032587220571 (code B ref 67124); Sat, 18 Nov 2023 16:45:02 +0000 Received: (at 67124) by debbugs.gnu.org; 18 Nov 2023 16:44:32 +0000 Received: from localhost ([127.0.0.1]:49417 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r4OQp-0005Li-Kk for submit@debbugs.gnu.org; Sat, 18 Nov 2023 11:44:31 -0500 Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:54682) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r4OQk-0005LQ-QC for 67124@debbugs.gnu.org; Sat, 18 Nov 2023 11:44:30 -0500 Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 6FC478024B; Sat, 18 Nov 2023 11:44:20 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1700325859; bh=O+FchGqLck0jot2g+ikrXRWmcDGeAD1E3UNguxb6Sgg=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=PzhGM5hKCjgWYNF9lYmLuQ9a17/BwkLb1jhiZ8BExYA0LfPngTlO0yq2ohby148aK OFv4wkQZ14YWJ55pntIbix1D6S+eAYk0ZWkN6V3XfE1/XYOuk6kiPjG5YPxHw+VXlg qIe/YlpGUvCFTeZM739A9kJdCd/88gqZpbCxHp+L9LNbu2k1jYZFtgc3qeSgiZJwsw Cf5PiZuBZEaIIV5yapvnLykGLZEpJTj+At5aJv4Ged38Rpe0sInRhBDi218vyNR8s7 1TSaTZ1QLi4NLOmWooJCyBsXJQ/5n6yhmPzlOi4FFlDGKV8dCXHIpSQ59epLocjxTl enUL9bj6NZOlw== Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id A9FBA80595; Sat, 18 Nov 2023 11:44:19 -0500 (EST) Received: from pastel (unknown [45.72.227.120]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 7AE581201DD; Sat, 18 Nov 2023 11:44:19 -0500 (EST) From: Stefan Monnier In-Reply-To: <83msvbmkkb.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 18 Nov 2023 12:18:12 +0200") Message-ID: References: <020a72b2-b896-4ecf-abab-111a6c1c9eac@medialab.sissa.it> <83cywfuwta.fsf@gnu.org> <83leaxprpi.fsf@gnu.org> <83msvbmkkb.fsf@gnu.org> Date: Sat, 18 Nov 2023 11:44:18 -0500 User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-SPAM-INFO: Spam detection results: 0 ALL_TRUSTED -1 Passed through trusted hosts only via SMTP AWL 0.021 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's domain DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from domain T_SCC_BODY_TEXT_LINE -0.01 - X-SPAM-LEVEL: X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > Please include at least some, if not all, of this extended explanation > in the comments there. Will do, thanks. Will add some tests as well, which should also clarify the intent/problem. Stefan From unknown Sun Jun 22 04:27:25 2025 X-Loop: help-debbugs@gnu.org Subject: bug#67124: 26.3; query-replace Arg out of range with comma option (at end-buffer) Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 18 Nov 2023 21:36:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 67124 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Eli Zaretskii Cc: gabriele@medialab.sissa.it, 67124-done@debbugs.gnu.org Received: via spool by 67124-done@debbugs.gnu.org id=D67124.170034333319694 (code D ref 67124); Sat, 18 Nov 2023 21:36:01 +0000 Received: (at 67124-done) by debbugs.gnu.org; 18 Nov 2023 21:35:33 +0000 Received: from localhost ([127.0.0.1]:49560 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r4SyT-00057a-1i for submit@debbugs.gnu.org; Sat, 18 Nov 2023 16:35:33 -0500 Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:24747) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r4SyP-00057L-7u for 67124-done@debbugs.gnu.org; Sat, 18 Nov 2023 16:35:32 -0500 Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 75CD280595; Sat, 18 Nov 2023 16:35:22 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1700343317; bh=QXTGVf7e2RKqhpBqyh5EqkMXiZAQY+BBi5Gob2fec5E=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=fezZV+ehDdgpRjjlgkJHnt2WXw7mPvqs3D06xFXLTc0TvMHEy0cEwLH+8vRNgmA58 4Rjj1/HNq/Yp+hv1BFWeSa/wPdMalZGo5d2PGokBXuJTfLbnWzB4ddhqhpCd/W95yM 9W3TJ3cp+Zyq7siItwO/ok2FgNM9hOiKpRP1SND1oNyGpGU7qZrUgIDay5Fx7iWO2K fI1TVlRGiL8N3c8BUWbUcZ7C+bJTuei0otBECQ+UHnu55Opo8QhfverpmFpaMvSQt9 LDpHvFG7vTzjyRHLHZ+AijlpdLIjsrU38ZMJfCM0D8prZ8+yE4vN1RtzSm3kIoTnS4 nvtRcU6z+WQmg== Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 6D9888007C; Sat, 18 Nov 2023 16:35:17 -0500 (EST) Received: from pastel (unknown [45.72.227.120]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 3D91E1201C1; Sat, 18 Nov 2023 16:35:17 -0500 (EST) From: Stefan Monnier In-Reply-To: (Stefan Monnier's message of "Sat, 18 Nov 2023 11:44:18 -0500") Message-ID: References: <020a72b2-b896-4ecf-abab-111a6c1c9eac@medialab.sissa.it> <83cywfuwta.fsf@gnu.org> <83leaxprpi.fsf@gnu.org> <83msvbmkkb.fsf@gnu.org> Date: Sat, 18 Nov 2023 16:35:11 -0500 User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-SPAM-INFO: Spam detection results: 0 ALL_TRUSTED -1 Passed through trusted hosts only via SMTP AWL 0.022 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's domain DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from domain T_SCC_BODY_TEXT_LINE -0.01 - X-SPAM-LEVEL: X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) >> Please include at least some, if not all, of this extended explanation >> in the comments there. > Will do, thanks. Will add some tests as well, which should also clarify > the intent/problem. Done, Stefan