unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#65451: 30.0.50; `after-change-functions' are not triggered in the same order the changes are made
@ 2023-08-22  9:30 Ihor Radchenko
  2023-08-22 12:22 ` Eli Zaretskii
  0 siblings, 1 reply; 34+ messages in thread
From: Ihor Radchenko @ 2023-08-22  9:30 UTC (permalink / raw)
  To: 65451


Consider the following reproducer:

1. Create /tmp/bug.el with the following contents

(defun my/setup ()
  (interactive)
  (defun my/before-change (beg end)
    (warn "Before: %d %d" beg end))
  (add-hook 'before-change-functions #'my/before-change nil 'local)

  (defun my/after-change (beg end pre)
    (warn "After: %d %d delta: %d" beg end (- end beg pre)))
  (add-hook 'after-change-functions #'my/after-change nil 'local))

2. Create /tmp/bug.org

https://www.gnu.org/software/emacs/manual/html_node/emacs/Mode-Line.html

-UUU: @**-   F2  UTF-8-demo.txt   Top   (1,0)     <N>   (Text s-/ WS Wrap)

| string | meaning                                  | note                                                                 |
|--------+------------------------------------------+----------------------------------------------------------------------|
| -      | input method                             |                                                                      |
| UUU    | coding system (keyboard terminal buffer) | (U utf-8-unix)                                                       |
| :      | end-of-line convention                   | (: LF) (/ CR) (\ CRLF)                                               |
| @      | emacsclient                              |                                                                      |
| **     | buffer status                            | (-- unmodified) (** modified) (%% read-only) (%* read-only_modified) |
| -      | default-directory                        | (- local) (@ remote)                                                 |
| F2     | frame name                               | (F2 the-2nd-frame)                                                   |
|        |                                          |                                                                      |

3. emacs -Q -l /tmp/bug.el /tmp/bug.org
4. M-x my/setup
5. Move point to

| F2     | frame name                               | (F2 the-2nd-frame)                                                   |
| <point>       |                                          |                                                                      |

6. Insert "UTF"
7. M-x dabbrev-expand
8. Observe the following in the *Warnings* buffer

⛔ Warning (emacs): Before: 1278 1278
⛔ Warning (emacs): After: 1278 1279 delta: 1
⛔ Warning (emacs): Before: 1284 1285
⛔ Warning (emacs): After: 1284 1284 delta: -1
⛔ Warning (emacs): Before: 1279 1279
⛔ Warning (emacs): After: 1279 1280 delta: 1
⛔ Warning (emacs): Before: 1284 1285
⛔ Warning (emacs): After: 1284 1284 delta: -1
⛔ Warning (emacs): Before: 1280 1280
⛔ Warning (emacs): After: 1280 1281 delta: 1
⛔ Warning (emacs): Before: 1284 1285
⛔ Warning (emacs): After: 1284 1284 delta: -1
⛔ Warning (emacs): Before: 1278 1281
⛔ Warning (emacs): Before: 1278 1288
⛔ Warning (emacs): After: 1278 1288 delta: 0
⛔ Warning (emacs): After: 1278 1288 delta: 7

The last bit of the messages corresponds to dabbrev expansion of "UTF"
to "utf-8-unix":

⛔ 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".

The order of after-change notifications thus do not correspond to the
order of buffer changes. Org mode is relying upon the correct change
order to update parser cache with buffer modifications.

The same recipe using Emacs 27 yields the correct order

<...>
Warning (emacs): Before: 1278 1281
Warning (emacs): After: 1278 1288 delta: 7
Warning (emacs): Before: 1278 1288
Warning (emacs): After: 1278 1288 delta: 0


In GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
 3.24.38, cairo version 1.17.8) of 2023-08-14 built on localhost
Repository revision: d483b38070120f17b1d00975081d27191d1deacc
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12101008
System Description: Gentoo Linux

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>





^ permalink raw reply	[flat|nested] 34+ messages in thread

end of thread, other threads:[~2024-04-08 19:10 UTC | newest]

Thread overview: 34+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-22  9:30 bug#65451: 30.0.50; `after-change-functions' are not triggered in the same order the changes are made Ihor Radchenko
2023-08-22 12:22 ` Eli Zaretskii
2023-08-22 12:42   ` Ihor Radchenko
2023-08-22 12:58     ` Eli Zaretskii
2023-08-22 13:41       ` Ihor Radchenko
2023-08-22 16:02         ` Eli Zaretskii
2023-08-23  8:52           ` Ihor Radchenko
2023-08-23 17:58             ` Eli Zaretskii
2023-08-24  7:46               ` Ihor Radchenko
2023-08-24  8:08                 ` Eli Zaretskii
2023-08-24 11:24                   ` Ihor Radchenko
2023-08-24 12:08                     ` Eli Zaretskii
2023-08-24 13:27                       ` Ihor Radchenko
2023-08-24 14:53                         ` Eli Zaretskii
2023-08-25  6:37                           ` Eli Zaretskii
2023-08-25  9:09                             ` Ihor Radchenko
2023-08-26  7:10                               ` Eli Zaretskii
2023-08-27  8:13                                 ` Ihor Radchenko
2023-08-27  8:29                                   ` Eli Zaretskii
2023-08-29  7:39                                     ` Ihor Radchenko
2023-08-25  8:09                           ` Ihor Radchenko
2023-08-25 10:25                             ` Eli Zaretskii
2023-08-25 10:49                               ` Ihor Radchenko
2024-03-30 13:51   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-30 14:11     ` Eli Zaretskii
2024-03-30 15:38       ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-30 16:47         ` Eli Zaretskii
2024-03-31  3:04           ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-31  3:02     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-31  6:06       ` Eli Zaretskii
2024-03-31 13:57         ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-07 18:19       ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-08 19:10         ` Ihor Radchenko
2024-04-07 18:19       ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).