From unknown Sun Aug 10 16:51:07 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#10117 <10117@debbugs.gnu.org> To: bug#10117 <10117@debbugs.gnu.org> Subject: Status: duplicate evaluation of after-change-functions hooks in revert-buffer Reply-To: bug#10117 <10117@debbugs.gnu.org> Date: Sun, 10 Aug 2025 23:51:07 +0000 retitle 10117 duplicate evaluation of after-change-functions hooks in rever= t-buffer reassign 10117 emacs submitter 10117 Tiphaine Turpin severity 10117 normal tag 10117 moreinfo thanks From debbugs-submit-bounces@debbugs.gnu.org Wed Nov 23 06:20:05 2011 Received: (at submit) by debbugs.gnu.org; 23 Nov 2011 11:20:05 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1RTAs1-0000Ue-Jd for submit@debbugs.gnu.org; Wed, 23 Nov 2011 06:20:05 -0500 Received: from eggs.gnu.org ([140.186.70.92]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1RTArz-0000UX-GU for submit@debbugs.gnu.org; Wed, 23 Nov 2011 06:20:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RTAqU-00049f-Do for submit@debbugs.gnu.org; Wed, 23 Nov 2011 06:18:38 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-8.1 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD autolearn=unavailable version=3.3.1 Received: from lists.gnu.org ([140.186.70.17]:33467) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RTAqU-00049Z-6C for submit@debbugs.gnu.org; Wed, 23 Nov 2011 06:18:30 -0500 Received: from eggs.gnu.org ([140.186.70.92]:47660) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RTAqP-0006Fu-0H for bug-gnu-emacs@gnu.org; Wed, 23 Nov 2011 06:18:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RTAqJ-00043o-Af for bug-gnu-emacs@gnu.org; Wed, 23 Nov 2011 06:18:24 -0500 Received: from mail1-relais-roc.national.inria.fr ([192.134.164.82]:56884) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RTAqJ-00043V-1c for bug-gnu-emacs@gnu.org; Wed, 23 Nov 2011 06:18:19 -0500 X-IronPort-AV: E=Sophos;i="4.69,558,1315173600"; d="scan'208";a="132249737" Received: from chercheurs2-241.saclay.inria.fr (HELO [193.55.250.241]) ([193.55.250.241]) by mail1-relais-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-CAMELLIA256-SHA; 23 Nov 2011 12:18:16 +0100 Message-ID: <4ECCD677.1090900@inria.fr> Date: Wed, 23 Nov 2011 12:18:15 +0100 From: Tiphaine Turpin User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.23) Gecko/20110922 Thunderbird/3.1.15 MIME-Version: 1.0 To: bug-gnu-emacs@gnu.org Subject: duplicate evaluation of after-change-functions hooks in revert-buffer Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 140.186.70.17 X-Spam-Score: -6.6 (------) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -6.6 (------) Hi, I'm having a strange behavior while trying to track the modifications to a buffer: calling revert-buffer triggers the following calls to my after-change-functions hook - a region deletion (which is exactly the changed region between the buffer and the file) - a region insertion (the new contents for the changed region) - the same insertion again. I don't care about how many modifications the reverting is splited into, or whether these are minimal or all the buffer contents is considered new, but the duplicate insertion leads me into invalid assumptions about the new contents (I use this to maintain a exact mapping of the buffer into an external tool). Am I wrong when I assume that the sequence of modifications passed to the after-change-functions is an exact trace of the buffer contents evolution ? What could possibly cause such a duplicate event ? Note: I'm not doing anything strange in the hook like changing the buffers' contents. This is just a numeric computation which update some buffer-local variables which track the set of "unprocessed" modifications. The hook is added as buffer-local (and global value of after-change-functions is nil). Regards, Tiphaine Turpin From debbugs-submit-bounces@debbugs.gnu.org Wed Nov 23 09:44:02 2011 Received: (at 10117) by debbugs.gnu.org; 23 Nov 2011 14:44:02 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1RTE3M-00062h-La for submit@debbugs.gnu.org; Wed, 23 Nov 2011 09:44:02 -0500 Received: from ironport2-out.teksavvy.com ([206.248.154.181]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1RTE3K-00062a-KU for 10117@debbugs.gnu.org; Wed, 23 Nov 2011 09:43:59 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Av0EAO8FzU5FxIbt/2dsb2JhbABEqmqBBoFyAQEEAVYjBQsLNBIUGA0kiBi0QYpiBIggmgKETg X-IronPort-AV: E=Sophos;i="4.69,559,1315195200"; d="scan'208";a="149155053" Received: from 69-196-134-237.dsl.teksavvy.com (HELO pastel.home) ([69.196.134.237]) by ironport2-out.teksavvy.com with ESMTP/TLS/ADH-AES256-SHA; 23 Nov 2011 09:42:31 -0500 Received: by pastel.home (Postfix, from userid 20848) id 7059658E47; Wed, 23 Nov 2011 09:42:31 -0500 (EST) From: Stefan Monnier To: Tiphaine Turpin Subject: Re: bug#10117: duplicate evaluation of after-change-functions hooks in revert-buffer Message-ID: References: <4ECCD677.1090900@inria.fr> Date: Wed, 23 Nov 2011 09:42:31 -0500 In-Reply-To: <4ECCD677.1090900@inria.fr> (Tiphaine Turpin's message of "Wed, 23 Nov 2011 12:18:15 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.91 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -2.6 (--) X-Debbugs-Envelope-To: 10117 Cc: 10117@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.6 (--) > Am I wrong when I assume that the sequence of modifications passed to the > after-change-functions is an exact trace of the buffer contents evolution ? Well, it should be, yes. > What could possibly cause such a duplicate event ? A bug in revert-buffer? revert-buffer modifies the buffer on its own rather than via calls to delete and insert, so it runs those change-functions "by hand". Do you have a small test case reproducing the problem? Stefan From debbugs-submit-bounces@debbugs.gnu.org Thu Dec 01 15:23:43 2011 Received: (at 10117-done) by debbugs.gnu.org; 1 Dec 2011 20:23:43 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1RWDAV-0003J6-DE for submit@debbugs.gnu.org; Thu, 01 Dec 2011 15:23:43 -0500 Received: from relais.videotron.ca ([24.201.245.36]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1RWDAT-0003Ix-I4 for 10117-done@debbugs.gnu.org; Thu, 01 Dec 2011 15:23:42 -0500 MIME-version: 1.0 Content-transfer-encoding: 7BIT Content-type: text/plain; CHARSET=US-ASCII Received: from ceviche.home ([173.176.12.77]) by VL-VM-MR001.ip.videotron.ca (Oracle Communications Messaging Exchange Server 7u4-22.01 64bit (built Apr 21 2011)) with ESMTP id <0LVJ00AJKKL2HY60@VL-VM-MR001.ip.videotron.ca> for 10117-done@debbugs.gnu.org; Thu, 01 Dec 2011 15:22:14 -0500 (EST) Received: by ceviche.home (Postfix, from userid 20848) id AB7FD660D4; Thu, 01 Dec 2011 15:23:29 -0500 (EST) From: Stefan Monnier To: Tiphaine Turpin Subject: Re: bug#10117: duplicate evaluation of after-change-functions hooks in revert-buffer Message-id: References: <4ECCD677.1090900@inria.fr> <4ECD0A5D.90907@inria.fr> Date: Thu, 01 Dec 2011 15:23:29 -0500 In-reply-to: <4ECD0A5D.90907@inria.fr> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.91 (gnu/linux) X-Spam-Score: -2.2 (--) X-Debbugs-Envelope-To: 10117-done Cc: 10117-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.2 (--) >> change-functions "by hand". Do you have a small test case reproducing >> the problem? > Here is an example: > First open the attached file in Emacs and evaluate it. Then: > echo ';Hi!' >>revert-bug.el > The *Messages* buffer shows the following: > modify [175, 180[ (old-len=0) [2 times] Indeed, I see that too. I've installed the patch below which should fix it. Thanks for the simple test case. Stefan === modified file 'src/fileio.c' --- src/fileio.c 2011-11-26 21:40:41 +0000 +++ src/fileio.c 2011-12-01 20:14:53 +0000 @@ -4100,6 +4100,16 @@ adjust_after_insert (PT, PT_BYTE, PT + inserted, PT_BYTE + inserted, inserted); + /* Call after-change hooks for the inserted text, aside from the case + of normal visiting (not with REPLACE), which is done in a new buffer + "before" the buffer is changed. */ + if (inserted > 0 && total > 0 + && (NILP (visit) || !NILP (replace))) + { + signal_after_change (PT, 0, inserted); + update_compositions (PT, PT, CHECK_BORDER); + } + /* Now INSERTED is measured in characters. */ handled: @@ -4270,16 +4280,6 @@ unbind_to (count1, Qnil); } - /* Call after-change hooks for the inserted text, aside from the case - of normal visiting (not with REPLACE), which is done in a new buffer - "before" the buffer is changed. */ - if (inserted > 0 && total > 0 - && (NILP (visit) || !NILP (replace))) - { - signal_after_change (PT, 0, inserted); - update_compositions (PT, PT, CHECK_BORDER); - } - if (!NILP (visit) && current_buffer->modtime == -1) { From unknown Sun Aug 10 16:51:07 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Fri, 30 Dec 2011 12:24:03 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator