GNU bug report logs - #65451
30.0.50; `after-change-functions' are not triggered in the same order the changes are made

Previous Next

Package: emacs;

Reported by: Ihor Radchenko <yantar92 <at> posteo.net>

Date: Tue, 22 Aug 2023 09:31:01 UTC

Severity: normal

Found in version 30.0.50

Done: Stefan Monnier <monnier <at> iro.umontreal.ca>

Bug is archived. No further changes may be made.

Full log


Message #74 received at 65451 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: Alan Mackenzie <acm <at> muc.de>, Ihor Radchenko <yantar92 <at> posteo.net>,
 65451 <at> debbugs.gnu.org
Subject: Re: bug#65451: 30.0.50; `after-change-functions' are not triggered
 in the same order the changes are made
Date: Sat, 30 Mar 2024 09:51:59 -0400
>> ⛔ Warning (emacs): Before: 1278 1281
>> ⛔ Warning (emacs): Before: 1278 1288
>> ⛔ Warning (emacs): After: 1278 1288 delta: 0
>> ⛔ Warning (emacs): After: 1278 1288 delta: 7
>> 
>> Note how "After: 1278 1288 delta: 0" reports a change of "utf-8-unix"
>> that did not alter the buffer text size. It is trigerred _before_
>> "After: 1278 1288 delta: 7" that corresponds to replacing "UTF" with
>> "utf-8-unix".

Hmm... yes, that's bad.  Alan, have you looked at this?

I suspect the best option in the above case is to inhibit the inner
calls to before/after (assuming we're sure they change only the "new
text"), so we'd be down to:

    ⛔ Warning (emacs): Before: 1278 1281
    ⛔ Warning (emacs): After: 1278 1288 delta: 7

> I think Org mode is relying on something it should not.  This
> particular use case aside, Emacs is allowed to call a function that
> changes the buffer from a function that itself changes the buffer, and
> it is allowed to call that inner function _before_ it did all the
> changes it intended to do.

AFAIK the above sequences breaks the promise we make about
`before-change-functions` and `after-change-functions`.

Almost all the non-trivial users of those hooks (i.e. basically those
that need to use both hooks) have extra sanity and raise the heads up in
despair when faced with things like the above (my `track-changes.el`
lacks such sanity checks, but that's because it's a PoC).


        Stefan





This bug report was last modified 1 year and 105 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.