From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.devel Subject: Re: /* FIXME: Call signal_after_change! */ in callproc.c. Well, why not? Date: Tue, 24 Dec 2019 09:47:24 +0000 Message-ID: <20191224094724.GA3992@ACM> References: <20191221172324.GA8692@ACM> <83k16pzgzu.fsf@gnu.org> <20191221214751.GB8692@ACM> <83sglcxl1q.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="90672"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mutt/1.10.1 (2018-07-13) Cc: emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Dec 24 10:47:48 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1ijgn5-000NSP-T8 for ged-emacs-devel@m.gmane.org; Tue, 24 Dec 2019 10:47:48 +0100 Original-Received: from localhost ([::1]:37620 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ijgn4-0000qI-5Y for ged-emacs-devel@m.gmane.org; Tue, 24 Dec 2019 04:47:46 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:58000) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ijgmo-0000q9-4T for emacs-devel@gnu.org; Tue, 24 Dec 2019 04:47:32 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ijgmm-0002zi-8T for emacs-devel@gnu.org; Tue, 24 Dec 2019 04:47:29 -0500 Original-Received: from colin.muc.de ([193.149.48.1]:45978 helo=mail.muc.de) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1ijgml-0002zA-Um for emacs-devel@gnu.org; Tue, 24 Dec 2019 04:47:28 -0500 Original-Received: (qmail 3834 invoked by uid 3782); 24 Dec 2019 09:47:27 -0000 Original-Received: from acm.muc.de (p4FE15B64.dip0.t-ipconnect.de [79.225.91.100]) by colin.muc.de (tmda-ofmipd) with ESMTP; Tue, 24 Dec 2019 10:47:25 +0100 Original-Received: (qmail 5212 invoked by uid 1000); 24 Dec 2019 09:47:24 -0000 Content-Disposition: inline In-Reply-To: <83sglcxl1q.fsf@gnu.org> X-Delivery-Agent: TMDA/1.1.12 (Macallan) X-Primary-Address: acm@muc.de X-detected-operating-system: by eggs.gnu.org: FreeBSD 9.x [fuzzy] X-Received-From: 193.149.48.1 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 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:243605 Archived-At: Hello, Eli. On Sun, Dec 22, 2019 at 20:38:41 +0200, Eli Zaretskii wrote: > > Date: Sat, 21 Dec 2019 21:47:52 +0000 > > Cc: emacs-devel@gnu.org > > From: Alan Mackenzie > > > > else if (NILP (BVAR (current_buffer, enable_multibyte_characters)) > > && ! CODING_MAY_REQUIRE_DECODING (&process_coding)) > > - insert_1_both (buf, nread, nread, 0, 1, 0); > > + { > > + beg = PT; > > + insert_1_both (buf, nread, nread, 0, prepared_position < PT, 0); > > + if (prepared_position < PT) > > + prepared_position = PT; > > + signal_after_change (beg, 0, PT - beg); > ^^^^^^^^ > 'PT - beg' is just 'nread' in this case, since we are inserting > 'nread' characters. Right? Er, yes. ;-). So BEG is silly, and as you say, PT - beg should just be nread. > And I don't think you need the prepared_position stuff here, since PT > doesn't move in signal_after_change. The point is not to call prepare_to_modify_buffer twice at the same position. prepared_position records the most recent place p_t_m_b was called, thus enabling us to avoid calling it there again, should we remove the already inserted text, decode it, and insert it again. > > @@ -788,7 +796,11 @@ call_process (ptrdiff_t nargs, Lisp_Object *args, int filefd, > > > > XSETBUFFER (curbuf, current_buffer); > > /* FIXME: Call signal_after_change! */ > > - prepare_to_modify_buffer (PT, PT, NULL); > > + if (prepared_position < PT) > > + { > > + prepare_to_modify_buffer (PT, PT, NULL); > > + prepared_position = PT; > > + } > > /* We cannot allow after-change-functions be run > > during decoding, because that might modify the > > buffer, while we rely on process_coding.produced to > > @@ -822,6 +834,7 @@ call_process (ptrdiff_t nargs, Lisp_Object *args, int filefd, > > continue; > > } > > > > + signal_after_change (PT, 0, process_coding.produced_char); > > TEMP_SET_PT_BOTH (PT + process_coding.produced_char, > > PT_BYTE + process_coding.produced); > > carryover = process_coding.carryover_bytes; > This really ugly, IMO. And the code logic is very hard to follow and > verify its correctness, given the various use cases. Well, call_process was already ugly, with its inserting text once, sometimes deleting it and inserting a modified version. But I see my changes don't help its readability. > I think you should simply call signal_after_change after the call to > del_range_2 (telling the after-change hooks that actually nothing was > inserted or deleted). Then you won't need the prepared_position > thingy. After thinking it over a couple of days, I can't agree this is a good idea. Calling before/after-change-functions for a non-change would be very unusual in Emacs - I don't know of anywhere where this is currently done - and would surely cause problems somewhere, and would certainly cause some inefficiency. Also we would have to amend the Change Hooks page in the Elisp manual to warn of this possibility. And all that because a low level C function is a little tricky. I think the basic idea of my change is sound, but it is suboptimally coded. My confusion, I think, arose from the use of the PREPARE parameter in the call to insert_1_both, which creates several different cases. This is a bad idea. If instead we put in a single call to prepare_to_modify_buffer, this should be relatively easy to follow. One or two comments would also be helpful. > Thanks. -- Alan Mackenzie (Nuremberg, Germany).