From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Lars Ingebrigtsen Newsgroups: gmane.emacs.bugs Subject: bug#42424: 27.0.90; replace-match: point is NOT left at the end of replacement Date: Sat, 31 Jul 2021 16:49:52 +0200 Message-ID: <87wnp6edwv.fsf@gnus.org> References: <87zh4ltc5l.fsf@gnus.org> <83tuussr1v.fsf@gnu.org> <87tuusj618.fsf@gnus.org> <87r1fefum7.fsf@gnus.org> <835ywqpntr.fsf@gnu.org> <871r7eftg9.fsf@gnus.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="19873"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: 42424@debbugs.gnu.org, victorhge@gmail.com To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Jul 31 16:51:11 2021 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 1m9qKU-0004xi-Tz for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 31 Jul 2021 16:51:11 +0200 Original-Received: from localhost ([::1]:51460 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m9qKS-0000jR-Qf for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 31 Jul 2021 10:51:08 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:45540) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m9qKN-0000jB-00 for bug-gnu-emacs@gnu.org; Sat, 31 Jul 2021 10:51:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:51282) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m9qKM-000545-OE for bug-gnu-emacs@gnu.org; Sat, 31 Jul 2021 10:51:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1m9qKM-0002Ji-Is for bug-gnu-emacs@gnu.org; Sat, 31 Jul 2021 10:51:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Lars Ingebrigtsen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 31 Jul 2021 14:51:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 42424 X-GNU-PR-Package: emacs Original-Received: via spool by 42424-submit@debbugs.gnu.org id=B42424.16277430068820 (code B ref 42424); Sat, 31 Jul 2021 14:51:02 +0000 Original-Received: (at 42424) by debbugs.gnu.org; 31 Jul 2021 14:50:06 +0000 Original-Received: from localhost ([127.0.0.1]:34592 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m9qJR-0002I9-QB for submit@debbugs.gnu.org; Sat, 31 Jul 2021 10:50:06 -0400 Original-Received: from quimby.gnus.org ([95.216.78.240]:54380) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m9qJP-0002HW-IJ for 42424@debbugs.gnu.org; Sat, 31 Jul 2021 10:50:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org; s=20200322; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date: References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=EF6n1xQUzuZb/KSaT7QArAs9Nr4wjEaURsMTiojimlo=; b=f4IdaZ2m83glxaIQ0/j1vDpc98 jsoRYi25Mhp6eij8/9n1SxxugKixAu+SjDNy7g/pZZ0Gh/xxth/DM1r2B71wsODpeXVNKMbVOtHy1 4rQsOVHvP0GlXHNuSZ462KwBXqnvm2zu1jjW6P+x0F2R2h9WIgmelGNbimXeXuxhtOK0=; Original-Received: from 2.149.45.105.tmi.telenormobil.no ([2.149.45.105] helo=elva) by quimby.gnus.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m9qJF-0004fG-Me; Sat, 31 Jul 2021 16:49:56 +0200 In-Reply-To: <871r7eftg9.fsf@gnus.org> (Lars Ingebrigtsen's message of "Sat, 31 Jul 2021 16:28:54 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:210994 Archived-At: Lars Ingebrigtsen writes: > But that does not seem to call the modification hook at all in the test > case. Am I doing something obviously wrong here? Er. I may just have been testing the wrong thing or something. I redid the patch by adding a new parameter to replace_range to inhibit it calling the hook, and now the test case works fine, and it doesn't break any tests. (And it seems to work more logically all over.) Any comments? I've tried to imagine how it might regress something for somebody, but I don't think it should -- we're calling the modification hook at the same point as before (I think), for instance. diff --git a/src/cmds.c b/src/cmds.c index c8a96d918c..00fde0ef79 100644 --- a/src/cmds.c +++ b/src/cmds.c @@ -455,7 +455,7 @@ internal_self_insert (int c, EMACS_INT n) ptrdiff_t to; if (INT_ADD_WRAPV (PT, chars_to_delete, &to)) to = PTRDIFF_MAX; - replace_range (PT, to, string, 1, 1, 1, 0); + replace_range (PT, to, string, 1, 1, 1, 0, false); Fforward_char (make_fixnum (n)); } else if (n > 1) diff --git a/src/editfns.c b/src/editfns.c index 8ab17ebc9f..c8219decb0 100644 --- a/src/editfns.c +++ b/src/editfns.c @@ -2371,7 +2371,7 @@ #define COMBINING_BOTH (COMBINING_BEFORE | COMBINING_AFTER) /* replace_range is less efficient, because it moves the gap, but it handles combining correctly. */ replace_range (pos, pos + 1, string, - false, false, true, false); + false, false, true, false, false); pos_byte_next = CHAR_TO_BYTE (pos); if (pos_byte_next > pos_byte) /* Before combining happened. We should not increment @@ -2578,7 +2578,7 @@ DEFUN ("translate-region-internal", Ftranslate_region_internal, but it should handle multibyte characters correctly. */ string = make_multibyte_string ((char *) str, 1, str_len); replace_range (pos, pos + 1, string, - true, false, true, false); + true, false, true, false, false); len = str_len; } else @@ -2613,7 +2613,8 @@ DEFUN ("translate-region-internal", Ftranslate_region_internal, = (VECTORP (val) ? Fconcat (1, &val) : Fmake_string (make_fixnum (1), val, Qnil)); - replace_range (pos, pos + len, string, true, false, true, false); + replace_range (pos, pos + len, string, true, false, true, false, + false); pos_byte += SBYTES (string); pos += SCHARS (string); characters_changed += SCHARS (string); diff --git a/src/insdel.c b/src/insdel.c index e66120eb08..92ee2c42ea 100644 --- a/src/insdel.c +++ b/src/insdel.c @@ -1392,7 +1392,7 @@ adjust_after_insert (ptrdiff_t from, ptrdiff_t from_byte, void replace_range (ptrdiff_t from, ptrdiff_t to, Lisp_Object new, bool prepare, bool inherit, bool markers, - bool adjust_match_data) + bool adjust_match_data, bool inhibit_update_compositions) { ptrdiff_t inschars = SCHARS (new); ptrdiff_t insbytes = SBYTES (new); @@ -1552,8 +1552,11 @@ replace_range (ptrdiff_t from, ptrdiff_t to, Lisp_Object new, if (adjust_match_data) update_search_regs (from, to, from + SCHARS (new)); - signal_after_change (from, nchars_del, GPT - from); - update_compositions (from, GPT, CHECK_BORDER); + if (!inhibit_update_compositions) + { + signal_after_change (from, nchars_del, GPT - from); + update_compositions (from, GPT, CHECK_BORDER); + } } /* Replace the text from character positions FROM to TO with diff --git a/src/lisp.h b/src/lisp.h index 15a42a4456..1206a0d1f6 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -3717,7 +3717,8 @@ verify (FLT_RADIX == 2 || FLT_RADIX == 16); ptrdiff_t, ptrdiff_t); extern void adjust_markers_bytepos (ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t, int); -extern void replace_range (ptrdiff_t, ptrdiff_t, Lisp_Object, bool, bool, bool, bool); +extern void replace_range (ptrdiff_t, ptrdiff_t, Lisp_Object, bool, bool, + bool, bool, bool); extern void replace_range_2 (ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t, const char *, ptrdiff_t, ptrdiff_t, bool); extern void syms_of_insdel (void); diff --git a/src/search.c b/src/search.c index df384e1dcf..a295ca12bd 100644 --- a/src/search.c +++ b/src/search.c @@ -30,6 +30,7 @@ Copyright (C) 1985-1987, 1993-1994, 1997-1999, 2001-2021 Free Software #include "blockinput.h" #include "intervals.h" #include "pdumper.h" +#include "composite.h" #include "regex-emacs.h" @@ -2725,8 +2726,8 @@ DEFUN ("replace-match", Freplace_match, Sreplace_match, 1, 5, 0, newpoint = sub_start + SCHARS (newtext); /* Replace the old text with the new in the cleanest possible way. */ - replace_range (sub_start, sub_end, newtext, 1, 0, 1, true); - + replace_range (sub_start, sub_end, newtext, 1, 0, 1, true, true); + if (case_action == all_caps) Fupcase_region (make_fixnum (search_regs.start[sub]), make_fixnum (newpoint), @@ -2750,6 +2751,9 @@ DEFUN ("replace-match", Freplace_match, Sreplace_match, 1, 5, 0, /* Now move point "officially" to the end of the inserted replacement. */ move_if_not_intangible (newpoint); + signal_after_change (sub_start, sub_end - sub_start, SCHARS (newtext)); + update_compositions (sub_start, newpoint, CHECK_BORDER); + return Qnil; } diff --git a/test/src/search-tests.el b/test/src/search-tests.el new file mode 100644 index 0000000000..b7b4ab9a8f --- /dev/null +++ b/test/src/search-tests.el @@ -0,0 +1,42 @@ +;;; search-tests.el --- tests for search.c functions -*- lexical-binding: t -*- + +;; Copyright (C) 2015-2016, 2018-2021 Free Software Foundation, Inc. + +;; This file is part of GNU Emacs. + +;; GNU Emacs is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; GNU Emacs is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs. If not, see . + +;;; Code: + +(require 'ert) + +(ert-deftest test-replace-match-modification-hooks () + (let ((ov-set nil)) + (with-temp-buffer + (insert "1 abc") + (setq ov-set (make-overlay 3 5)) + (overlay-put + ov-set 'modification-hooks + (list (lambda (o after &rest _args) + (when after + (let ((inhibit-modification-hooks t)) + (save-excursion + (goto-char 2) + (insert "234"))))))) + (goto-char 3) + (if (search-forward "bc") + (replace-match "bcd")) + (should (= (point) 10))))) + +;;; search-tests.el ends here -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no