From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: Unbalanced change hooks (part 1) Date: Tue, 02 Aug 2016 05:34:22 +0300 Message-ID: <8337mnoq4x.fsf@gnu.org> References: <20160731101617.GA2205@acm.fritz.box> Reply-To: Eli Zaretskii NNTP-Posting-Host: blaine Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1470105301 13109 195.159.176.226 (2 Aug 2016 02:35:01 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 2 Aug 2016 02:35:01 +0000 (UTC) Cc: ofv@wanadoo.es, acm@muc.de, emacs-devel@gnu.org To: Richard Copley Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Aug 02 04:34:52 2016 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bUPXf-0002ic-1B for ged-emacs-devel@m.gmane.org; Tue, 02 Aug 2016 04:34:51 +0200 Original-Received: from localhost ([::1]:53676 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bUPXb-0004Tu-NE for ged-emacs-devel@m.gmane.org; Mon, 01 Aug 2016 22:34:47 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36454) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bUPXV-0004Tk-UK for emacs-devel@gnu.org; Mon, 01 Aug 2016 22:34:42 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bUPXR-0007rm-Oo for emacs-devel@gnu.org; Mon, 01 Aug 2016 22:34:40 -0400 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:52505) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bUPXR-0007rh-LH; Mon, 01 Aug 2016 22:34:37 -0400 Original-Received: from 84.94.185.246.cable.012.net.il ([84.94.185.246]:2018 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.82) (envelope-from ) id 1bUPXQ-0007NI-MT; Mon, 01 Aug 2016 22:34:37 -0400 In-reply-to: (message from Richard Copley on Mon, 1 Aug 2016 21:13:01 +0100) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4830:134:3::e X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:206339 Archived-At: > From: Richard Copley > Date: Mon, 1 Aug 2016 21:13:01 +0100 > Cc: Óscar Fuentes , > Emacs Development > > > diff --git a/src/fileio.c b/src/fileio.c > > index b1f9d3c..0431cbc 100644 > > --- a/src/fileio.c > > +++ b/src/fileio.c > > @@ -3440,6 +3440,7 @@ by calling `format-decode', which see. */) > > /* SAME_AT_END_CHARPOS counts characters, because > > restore_window_points needs the old character count. */ > > ptrdiff_t same_at_end_charpos = ZV; > > + bool run_change_hooks; > > > > if (current_buffer->base_buffer && ! NILP (visit)) > > error ("Cannot do file visiting in an indirect buffer"); > > @@ -4077,7 +4078,9 @@ by calling `format-decode', which see. */) > > /* For a special file, all we can do is guess. */ > > total = READ_BUF_SIZE; > > > > - if (NILP (visit) && total > 0) > > + run_change_hooks = ((NILP (visit) || !NILP (replace)) > > + && total > 0); > > + if (run_change_hooks) > > { > > if (!NILP (BVAR (current_buffer, file_truename)) > > /* Make binding buffer-file-name to nil effective. */ > > @@ -4313,8 +4316,7 @@ by calling `format-decode', which see. */) > > /* 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))) > > + if (run_change_hooks) > > { > > signal_after_change (PT, 0, inserted); > > update_compositions (PT, PT, CHECK_BORDER); > > > > > > Unfortunately, this amendment, by itself, doesn't fix #240[79]4, since > > there are other causes for the change hooks being improperly invoked. > > > > -- > > Alan Mackenzie (Nuremberg, Germany). > > LGTM. It's hard to imagine anyone relying on the before-change hooks > _not_ being run, so it should be safe, at least, to make this change. That code is almost never run when REPLACE is non-nil, so doing that won't help. See an earlier message that explained why.