Subject: bug#78042: 31.0.50; Improper sequence of `before/after-change-functions` calls

From: Eli Zaretskii <[email-masked]>
Date: Fri, 25 Apr 2025 21:39:46 +0300

> From: Stefan Monnier <[email-masked]>
> Cc: [email-masked]
> Date: Fri, 25 Apr 2025 12:37:34 -0400
> 
> > Sorry, I don't think I understand the problem.  Is the problem that we
> > have "nested" notifications, whereby you have
> >
> >   before-change-functions A1 B1
> >   before-change-functions A2 B2
> >   after-change-functions  A2 B2
> >   after-change-functions  A1 B1
> >
> > IOW, _any_ situation where we have nested pairs of notifications is
> > "breaking our promise"?
> 
> Yup: the `before-change-functions A2 B2` promises that there won't be
> any changes to the buffer outside of A2...B2 until the next
> `before-change-functions`.
> 
> > If so, how can that be avoided in principle in Emacs, given its
> > recursive nature, except by some mechanism which collects all the
> > notifications and rearranges them to "keep our promise"?
> 
> There is currently no attempt in the C code to solve this "by
> construction" or "by design".  Instead we fix the offenders as we bump
> into them.

I submit that we will never be able to solve all of them.