Subject: Re: bug#51766: 29.0.50; Return value of buffer-chars-modified-tick changes when buffer text is not yet changed before inserting a character for non-latin input methods

From: Ihor Radchenko <[email-masked]>
Date: Thu, 11 Nov 2021 23:50:31 +0800

Eli Zaretskii <[email-masked]> writes:

> How do you know there was no changes in the buffer?  You call your
> function from pre/post-command-hook, but why is it guaranteed that
> there was no change in the buffer between post-command-hook and the
> following pre-command-hook?

I also tested the bug by setting debug-on-entry for self-insert-command.
Try the following:
1. emacs -Q
2. M-\ russian-computer <RET>
3. M-\
4. M-: (buffer-chars-modified-tick) <RET>. Note the return value.
5. M-x debug-on-entry <RET> self-insert-command <RET>
6. Insert ?a
7. The debugger window appears. ?a is not yet inserted
8. In the debugger window: e M-p <RET> (call
   buffer-chars-modified-tick). The return value should be the same with
   4.
9. Continue execution of self-insert-command in the debugger (c). The ?a
   is inserted
10. Repeat 8. The return value correctly changes. Note the return value.
11. Continue execution to exit the debugger window (c)
12. Switch to russian input method (M-\)
13. Run M-: M-p <RET>. Note the return value. It is same with 10.
14. Run M-: (buffer-hash) <RET>. "(buffer-hash)" should by yanked to
    avoid triggering debugger. Note that hash value.
13. Type ?ф (?a on qwerty keyboard)
14. The debugger appears again. ?ф is _not_ yet inserted
15. Repeat 8. The return value is different from 10 even though the
    buffer text is not changed (and it can be confirmed if you run
    e (buffer-hash) <RET>)

Of course, there might be some kind of invisible change in buffer. I.e.
text is added and immediately deleted from the buffer without redisplay.
However, even if there is any change like that, before-change-functions
and after-change-functions are not triggered. That would be another bug
then.

Best,
Ihor