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 2) Date: Mon, 01 Aug 2016 22:37:09 +0300 Message-ID: <83a8gwnuvu.fsf@gnu.org> References: <20160731121642.GB2205@acm.fritz.box> <83a8gxq288.fsf@gnu.org> <20160731172804.GD2205@acm.fritz.box> <834m75ptij.fsf@gnu.org> <20160731212635.GF2205@acm.fritz.box> <83shuoocwp.fsf@gnu.org> <20160801165323.GB15055@acm.fritz.box> Reply-To: Eli Zaretskii NNTP-Posting-Host: blaine X-Trace: blaine.gmane.org 1470080321 17210 195.159.176.226 (1 Aug 2016 19:38:41 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 1 Aug 2016 19:38:41 +0000 (UTC) Cc: ofv@wanadoo.es, rcopley@gmail.com, emacs-devel@gnu.org To: Alan Mackenzie Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Aug 01 21:38:37 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 1bUJ2p-0004FC-ER for ged-emacs-devel@m.gmane.org; Mon, 01 Aug 2016 21:38:35 +0200 Original-Received: from localhost ([::1]:52567 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bUJ2l-0006lN-4G for ged-emacs-devel@m.gmane.org; Mon, 01 Aug 2016 15:38:31 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55995) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bUJ2C-0006lB-6b for emacs-devel@gnu.org; Mon, 01 Aug 2016 15:37:57 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bUJ27-0001dj-SR for emacs-devel@gnu.org; Mon, 01 Aug 2016 15:37:55 -0400 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:48513) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bUJ27-0001da-PV; Mon, 01 Aug 2016 15:37:51 -0400 Original-Received: from 84.94.185.246.cable.012.net.il ([84.94.185.246]:1700 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.82) (envelope-from ) id 1bUJ22-0006ct-HT; Mon, 01 Aug 2016 15:37:50 -0400 In-reply-to: <20160801165323.GB15055@acm.fritz.box> (message from Alan Mackenzie on Mon, 1 Aug 2016 16:53:23 +0000) 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:206326 Archived-At: > Date: Mon, 1 Aug 2016 16:53:23 +0000 > Cc: ofv@wanadoo.es, rcopley@gmail.com, emacs-devel@gnu.org > From: Alan Mackenzie > > > I'm not suggesting a workaround. I'm suggesting a fix for a design > > flaw in CC Mode -- its assumption that before-change-functions and > > after-change-functions are always invoked in balanced pairs. CC Mode > > must not depend on that assumption, because it's false. > > The flaw lies between the Emacs core and the Elisp manual. The latter > quite clearly implies that each buffer change is accompanied by a single > before-change-functions call and a single after-change-functions call. I don't mind making the manual more explicit on this. But doing so won't fix the problem at hand. > > In practice, we need to make sure that every modification triggers at > > least one call to before-change-functions and at least one call to > > after-change-functions. The numbers of these calls do not have to > > match. > > And in such calls, what are the parameters BEG, END, and OLD-LEN supposed > to mean? That depends on whether the changes are insertions or deletions. I thought it was quite clear from the documentation, but if not, we can spell that out better as well. > > I had my share of hacking that code [insdel.c] and its callers. It's > > impossible to convey everything I learned while doing that in a > > discussion such as this one. I say more about this below. If that's > > still not enough, you will have to trust me on that. > > OK. In exchange, I'm asking you to trust me when I say that the sort of > change you're expecting in CC Mode is impractical - months of work, > rather than weeks. I trust you. I just hope you will find a simpler way of doing that, after some thought and maybe more discussions. > > Just don't assume that there will be a c-before-change call for each > > c-after-change call, that's all. > > What you seem to be saying is that before-change-functions isn't very > useful. Since lots of packages use it, you seem to be saying that these > packages are broken, just as CC Mode is broken. No, I don't think before-change-functions are useless, and I don't know about any breakage of packages that use that hook. > > Specifically, in the case in point, I believe that the "unbalanced" > > call to c-after-change clearly tells you that text has been deleted, > > so I think it should be enough for you to do the job of the "missing" > > c-before-change call as well. > > No. CC Mode also needs to know what was there before the change. It > cannot guess. I think it's fair to ask you to suggest a way for CC Mode > to get that deleted buffer section, somehow. The functions that delete text do call after-change-functions, and those functions do get this information. Or maybe I don't understand what is it that you are asking. > Here is a list of lisp files which use before-change-functions. > Currently all of them are broken due to the unreliability of > before-change-functions: It depends how they are using this hook. > Please tell me how CC Mode can get full details of any buffer change, > then I'll be (reasonably) happy. You will have to tell much more about your needs, for me to begin being helpful on that level. Right now, all I can say is that after-change-functions provide that information, AFAIK. > > But before-change-functions _are_ being called in the scenario of the > > bugs we are discussing. They just aren't balanced with calls to > > after-change-functions, that's all. > > No. In the scenario of bug #24094 there was no call to > before-change-functions whatsoever. They were on my system, I saw in GDB signal_before_change being called from that place in insert-file-contents. I wonder how come you didn't. > > insert_from_buffer (XBUFFER (conversion_buffer), > > same_at_start_charpos, inserted_chars, 0); > > > the before-change-functions are called from insert_from_buffer. So > > it's not like the replacement would be missed by the > > before-change-functions. > > It was missed in the recipe for bug #24094. How can that be? insert_from_buffer unconditionally calls insert_from_buffer_1, which unconditionally calls prepare_to_modify_buffer, which in turns calls signal_before_change. > For an atomic user action (namely C-x C-f test.c++ followed by > typing "yes" to the prompt to reload the file) there was no > invocation of before-change-functions and one of > after-change-functions. This is the bug I am complaining of. Then I guess we are not talking about the same situation, and some more digging is in order. I did reproduce this using the recipe in those bugs. > > > In the general case because information gets lost at a change; things > > > like where the beginning of a statement was, where deleted template > > > delimiters used to be, what the bounds of a macro or string used to be > > > (before backslashes were deleted). > > > I'm sure CC Mode is well equipped to recalculate all of these if > > needed. It does that when a file is first visited. > > An empty buffer is a fully defined state. A buffer immediately following > a deletion is in an undefined state, which requires to know what was > deleted to make it defined again. You mean, you cannot just throw away the entire info and recalculate it anew? IOW, pretend that you know nothing about this buffer, as if you have just visited its file?