From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Campbell Barton Newsgroups: gmane.emacs.bugs Subject: bug#74666: 31.0.50; Regression in replace-match with empty-adjacent groups Date: Sun, 15 Dec 2024 12:10:26 +1100 Message-ID: <8340bf95-c716-4ebe-994e-07554b6e2165@gmail.com> References: <5aad7547-5fd7-4eba-a6eb-38b1b4753dd8@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="29200"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla Thunderbird Cc: 74666@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Dec 15 02:12:19 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1tMdBC-0007RZ-G2 for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 15 Dec 2024 02:12:18 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tMdAy-0002jZ-Ge; Sat, 14 Dec 2024 20:12:04 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tMdAw-0002jJ-K9 for bug-gnu-emacs@gnu.org; Sat, 14 Dec 2024 20:12:02 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tMdAw-0005UF-Bn for bug-gnu-emacs@gnu.org; Sat, 14 Dec 2024 20:12:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=In-Reply-To:From:References:MIME-Version:Date:To:Subject; bh=CP194S5EoRlDJTZFSc6OcII2qhHR23Uiq0c72CMIoo0=; b=dRL87ref+3DAkp0il1+bQ6JxiDD84vPG4QwWJDDxTvmoTkXrI8O5gzIyhBZbkiXTUJoSU/KoRUDxm0Uefz5fPUVVI/HcqHD1kbmKlXABf4dCm2VuVFmcoG0URsCnEIO2aqzWpmZiGK5DhL/VHfSy6ClmZlrB9JHuaIp4wCZr/mY5Et8EVmjTjeOUvb2XaHwSqwily61py2ZSVoHi4CnW2lJsw7mA+bmYv6xwm/+YapP1uQ+Tdt346xUkpdfqMcyc+ExPlVFw9Ohic/Zka2xNVOBPB42B1ilmL+0ZHIXICXbHBynbRyKJwzdy9zSH80nCQgEo+QAjgds6KvzxX57MjQ==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tMdAv-0003Sr-US for bug-gnu-emacs@gnu.org; Sat, 14 Dec 2024 20:12:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Campbell Barton Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 15 Dec 2024 01:12:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74666 X-GNU-PR-Package: emacs Original-Received: via spool by 74666-submit@debbugs.gnu.org id=B74666.173422509713264 (code B ref 74666); Sun, 15 Dec 2024 01:12:01 +0000 Original-Received: (at 74666) by debbugs.gnu.org; 15 Dec 2024 01:11:37 +0000 Original-Received: from localhost ([127.0.0.1]:48944 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tMdAW-0003Rs-Qh for submit@debbugs.gnu.org; Sat, 14 Dec 2024 20:11:37 -0500 Original-Received: from mail-pl1-f173.google.com ([209.85.214.173]:57735) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tMdAS-0003RY-2R for 74666@debbugs.gnu.org; Sat, 14 Dec 2024 20:11:36 -0500 Original-Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-21628b3fe7dso23494755ad.3 for <74666@debbugs.gnu.org>; Sat, 14 Dec 2024 17:11:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734225031; x=1734829831; darn=debbugs.gnu.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=CP194S5EoRlDJTZFSc6OcII2qhHR23Uiq0c72CMIoo0=; b=egmVce5A2r91RywgbbnWhXUl93z+MkRb5EvLPs0KGjBvXOAod02B3X+kArJEoMPIlK OIaotDJmhYYiJXKepS8TVO0zvKOJlmNV3Zit/hmfgsVhPSVLRa9M64rxP6IPPo1POldY SWLy2Xz2HOBgaDuv1M6QROv+8Heqt38fYME7jqAxV+MqWKyo4Su4VqsrZWEihaH3qJYp i1QgNLJFsS3bn4+49z2ap14LQjLxmD/494JFYe4XM2plRQSpe5839A+JA8sjPZzikY79 zayk3jItUDSi+U7pZCEfMd06kO/xxJ3lGD1CwNh3Cj2DcXbI8odBAn6ROJvGL48XBI37 35GA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734225031; x=1734829831; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=CP194S5EoRlDJTZFSc6OcII2qhHR23Uiq0c72CMIoo0=; b=bYXJPfOntk7sECZSLjFr00LWgkVHUCR+HT/tlLLAD4sjpi973jREcmxhkg1VgTl9oI f7UcarNH1QLrKRAIF5z643Gjp/p3KQgxkeSnQBxlktYFrThawBXg05kt1GjvdfvHqFZ2 TUctpeLBNTT4ga4rC9tf5RQfIN6SqMIiETujJATGjlDFRSdJxoeSnco1MvQK0BZI+blG HEI7/Hd+URc2Sxnsi0X78Y9kpJCvIXSAOMXstqW1UXBDsE24EPInUjzlTeo9Z1Y0SoO1 S2/rdOO1CXFhvq6MDIc7G0o+n2drj9woCZ9CEgV4hEjuH8L4Kxf/mKeByvmLgacgPuMm O+pw== X-Gm-Message-State: AOJu0Yxs9x/quLqLLNIhrGf5l53PRKTu/PQx6PfZDHIZJuBeQFiXM0// C06VEHtKqViVNi/Pl1Sl6/2ZLjgHalty1xFq0w+7rHdPhK38bqsEzxn8Zg== X-Gm-Gg: ASbGncvpOeX6OMa10aopvqAYN3BIs+I3QIs8yCYlHfaKpbIpoXdAPx8ezeoK7s0/aaK jLQaaUIY9briI0GAqryYV5L2tgtzsQe8pHxEwwt00zWJ5k7UBSjPoM6W51nnuFB0PuNDGcWbwBE PC6vjCA4aqHt3r9KoiEfdCCN4GzVEm8Jl2jyzpuBPDrkLmwYq3edzp2YwajExC30uBwco7gt5Dd XRk5QXnO14GNOtbSOIlN9P8X6TYGfF00V64MtphkyshuFH9KzEuPQsosJmoyIM= X-Google-Smtp-Source: AGHT+IEruzi3YmPJdNoMaw0K4gzLsN8DqlvqHvg0H13k7bBONTx1UUxiUO3aF8j/ET3NT/KOEi741A== X-Received: by 2002:a17:902:f64c:b0:216:2804:a241 with SMTP id d9443c01a7336-21892a546e5mr127022045ad.37.1734225031187; Sat, 14 Dec 2024 17:10:31 -0800 (PST) Original-Received: from ?IPV6:2402:b801:2c65:4b00::1? ([2402:b801:2c65:4b00::1]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2f142f9e193sm5426647a91.32.2024.12.14.17.10.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 14 Dec 2024 17:10:30 -0800 (PST) Content-Language: en-US In-Reply-To: X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:297080 Archived-At: On 24-12-15 3:11 AM, Stefan Monnier wrote: >> (defun test-me (is-forward) >> (let ((result "")) >> (with-temp-buffer >> (insert "__B_\n") >> (save-match-data >> (set-match-data (list 2 4 2 2 2 4)) >> (cond >> (is-forward >> (replace-match "HELLO" t t nil 1) >> (replace-match "WORLD" t t nil 2)) >> (t >> (replace-match "WORLD" t t nil 2) >> (replace-match "HELLO" t t nil 1)))) >> (setq result (buffer-substring-no-properties (point-min) >> (point-max)))) >> result)) > [...] >> In emacs 29.4 this prints: >> >> A: _HELLOWORLD_ >> B: _HELLOWORLD_ >> >> In emacs 31.0.50 this prints: >> >> A: _WORLD_ >> B: _HELLOWORLD_ > > The problem is that the `set-match-data` doesn't give us any information > about the intended inclusion relationship between the subgroups. > > I agree that the behavior you see is not the one you want if it's the > result of: > > (goto-char (point-min)) > (looking-at "_\\(\\)\\(_B\\)") > > But OTOH it is the one we want if it is the result of: > > (goto-char (point-min)) > (looking-at "_\\(?2:\\(?1:\\)_B\\)") > > We can try and guess the inclusion relationship based on circumstantial > evidence (e.g. a "_\\(\\)\\(_B\\)" regexp is more likely than > "_\\(?2:\\(?1:\\)_B\\)"), but that would make the code of > `update_search_regs` tricky, with various heuristics. > And we'll never handle all cases right unless we make significant > changes to the match-data (and the regexp compiler) to keep track of > inclusion relationships. > > Could you give us some information about the larger context in which you > bumped into this problem? On the user side - I ran into this bug when decrementing numbers broke for me in the evil-numbers package [0]. Numbers would fail to become negative. Decrementing 0 would become 1. In this case, the match data is set with `set-match-data' using calculated ranges. Since this used to work I think it's reasonable to consider it a regression. I've since committed a workaround to evil-numbers [1], although I'd suspect this would impact others. [0]: https://melpa.org/#/evil-numbers [1]: https://github.com/juliapath/evil-numbers/commit/f93258b706fa5cf9259e815c2d8258fcc6262804