From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.devel Subject: Re: Lisp primitives and their calling of the change hooks Date: Thu, 4 Jan 2018 21:11:54 +0000 Message-ID: <20180104211154.GC6846@ACM> References: <20180103124543.GA5435@ACM> <20180104155111.GB6846@ACM> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1515100507 23414 195.159.176.226 (4 Jan 2018 21:15:07 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 4 Jan 2018 21:15:07 +0000 (UTC) User-Agent: Mutt/1.7.2 (2016-11-26) Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Jan 04 22:15:03 2018 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 1eXCqk-0005Ha-6J for ged-emacs-devel@m.gmane.org; Thu, 04 Jan 2018 22:14:54 +0100 Original-Received: from localhost ([::1]:43077 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eXCsj-0006Ve-A5 for ged-emacs-devel@m.gmane.org; Thu, 04 Jan 2018 16:16:57 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:56359) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eXCrv-0006VA-I9 for emacs-devel@gnu.org; Thu, 04 Jan 2018 16:16:08 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eXCrr-0007Rx-At for emacs-devel@gnu.org; Thu, 04 Jan 2018 16:16:07 -0500 Original-Received: from colin.muc.de ([193.149.48.1]:21886 helo=mail.muc.de) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1eXCrq-0007QC-Sl for emacs-devel@gnu.org; Thu, 04 Jan 2018 16:16:03 -0500 Original-Received: (qmail 50851 invoked by uid 3782); 4 Jan 2018 21:16:01 -0000 Original-Received: from acm.muc.de (p548C72B8.dip0.t-ipconnect.de [84.140.114.184]) by colin.muc.de (tmda-ofmipd) with ESMTP; Thu, 04 Jan 2018 22:16:00 +0100 Original-Received: (qmail 23758 invoked by uid 1000); 4 Jan 2018 21:11:54 -0000 Content-Disposition: inline In-Reply-To: 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.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:221601 Archived-At: Hello, Stefan. On Thu, Jan 04, 2018 at 13:16:23 -0500, Stefan Monnier wrote: > As mentioned, I'd consider that [insert-file-contents not calling > b-c-f] as a bug. > > insert-file-contents, in circumstances explored in > > summer 2016, invokes only a-c-f, not b-c-f. > And indeed, I considered it a bug and AFAIK this is now fixed. Hey! It is indeed fixed. Thanks! I didn't know that. [ .... ] > > I would be surprised indeed if there weren't others, too. > I would too. > > However, we could improve the documentation of this situation in the > > elisp manual. > We currently say: > Do @emph{not} expect the before-change hooks and the after-change > hooks be called in balanced pairs around each buffer change. Also > don't expect the before-change hooks to be called for every chunk of > text Emacs is about to delete. These hooks are provided on the > assumption that Lisp programs will use either before- or the > after-change hooks, but not both, and the boundaries of the region > where the changes happen might include more than just the actual > changed text, or even lump together several changes done piecemeal. > which is lax enough that any behavior could be argued to be acceptable. > IOW I think it's too lax. We should probably try and fix it to reflect > the fact that every change should be covered by the last preceding b-c-f > and should be followed by a corresponding call to a-c-f (and this > before the next call to b-c-f). Is that quite right? The upcase-region call in my test had no a-c-f call, almost certainly because there were no lower case letters in the buffer at the time. From your answers in this thread, I'm thinking that every primitive-call which could change the buffer will have exactly one b-c-f and zero or more a-c-f's. How about something like this to replace that paragraph from the elisp manual? The primitives which atomically insert or delete a contiguous chunk of text into or from a buffer will call `before-change-functions' and `after-change-functions' in balanced pairs, once for each change. The arguments to these hooks will exactly delimit the change being made. Calls to these primitives comprise the vast bulk of buffer changes. Other, more complex primitives aim to call `before-change-functions' once before making any changes, then to call `after-change-functions' zero, one, or several times, depending on how many individual changes the primitive makes. The `BEG' and `END' arguments to `before-change-functions' will enclose a region in which the individual changes are made, but won't necessarily be the minimal such region. The `BEG', `END', and `OLD-LEN' arguments to each successive call of `after-change-functions' will accurately delimit the current change. > Stefan -- Alan Mackenzie (Nuremberg, Germany).