Subject: 29.0.50; Keyboard macros do not trigger after-change-functions

From: Richard Hansen <[email-masked]>
Date: Sat, 25 Jun 2022 02:21:51 -0400

Modifying a buffer via a keyboard macro does not seem to run the `after-change-functions' buffer modification hook, at least not in a batch `ert' test.

To reproduce, save the code below as test.el and run it with:

emacs -Q -batch -l ert -t test.el -f ert-run-tests-batch-and-exit

;; -*- lexical-binding: t; -*-
(require 'ert)
(require 'ert-x)
(ert-deftest test ()
   (ert-with-test-buffer ()
     (let ((acf 0))
       (add-hook 'after-change-functions
                 (lambda (&rest _) (setq acf (1+ acf)))
                 nil t)
       (execute-kbd-macro (kbd "x"))
       (should (equal (buffer-string) "x"))
       ;; This check fails:
       (should (equal acf 1)))))

If the `execute-kbd-macro' call is replaced with the following it *does* work as expected:

       (ert-simulate-command '(self-insert-command 1 ?x))

In GNU Emacs 29.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.20, cairo version 1.16.0)
  of 2022-06-25 built on sprinkles
Repository revision: ec1fffdeca9c87a92b8c35545121b4ee3eec3ece
Repository branch: master
System Description: Ubuntu 20.04.4 LTS

Configured using:
  'configure --with-modules=yes --with-x=yes --with-x-toolkit=gtk3
  --with-xwidgets=yes --with-pgtk --enable-checking=yes,glyphs
  --enable-check-lisp-object-type 'CFLAGS=-O2 -g3''

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG
JSON LCMS2 LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 MODULES NOTIFY INOTIFY
PDUMPER PGTK PNG RSVG SECCOMP SOUND SQLITE3 THREADS TIFF
TOOLKIT_SCROLL_BARS XIM XWIDGETS GTK3 ZLIB

Important settings:
   value of $LC_MONETARY: en_US.UTF-8
   value of $LC_NUMERIC: en_US.UTF-8
   value of $LC_TIME: root.UTF-8
   value of $LANG: en_US.UTF-8
   locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect:
   tooltip-mode: t
   global-eldoc-mode: t
   eldoc-mode: t
   show-paren-mode: t
   electric-indent-mode: t
   mouse-wheel-mode: t
   tool-bar-mode: t
   menu-bar-mode: t
   file-name-shadow-mode: t
   global-font-lock-mode: t
   font-lock-mode: t
   blink-cursor-mode: t
   line-number-mode: t
   indent-tabs-mode: t
   transient-mark-mode: t
   auto-composition-mode: t
   auto-encryption-mode: t
   auto-compression-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message yank-media rmc dired
dired-loaddefs rfc822 mml url url-proxy url-privacy url-expand
url-methods url-history url-cookie rx generate-lisp-file url-domsuf
url-util url-parse auth-source eieio eieio-core eieio-loaddefs json map
url-vars mm-view mml-smime smime gnutls puny dig mailcap mml-sec
password-cache epa epg rfc6068 epg-config mm-decode mm-bodies mm-encode
mail-parse rfc2231 mailabbrev easy-mmode nnheader gnus-util
text-property-search time-date seq cl-seq subr-x byte-opt bytecomp
byte-compile cconv range gmm-utils mailheader sendmail derived rfc2047
rfc2045 ietf-drums mm-util cl-macs inline gv pcase mail-prsvr
cl-loaddefs cl-lib mail-utils iso-transl tooltip eldoc paren electric
uniquify ediff-hook vc-hooks lisp-float-type elisp-mode mwheel
term/pgtk-win pgtk-win term/common-win tool-bar dnd fontset image
regexp-opt fringe tabulated-list replace newcomment text-mode lisp-mode
prog-mode register page tab-bar menu-bar rfn-eshadow isearch easymenu
timer select scroll-bar mouse jit-lock font-lock syntax font-core
term/tty-colors frame minibuffer nadvice simple cl-generic indonesian
philippine cham georgian utf-8-lang misc-lang vietnamese tibetan thai
tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek romanian
slovak czech european ethiopic indian cyrillic chinese composite
emoji-zwj charscript charprop case-table epa-hook jka-cmpr-hook help
abbrev obarray oclosure cl-preloaded button loaddefs faces cus-face
macroexp files window text-properties overlay sha1 md5 base64 format env
code-pages mule custom widget keymap hashtable-print-readable backquote
threads xwidget-internal dbusbind inotify dynamic-setting
system-font-setting font-render-setting cairo gtk pgtk lcms2 multi-tty
make-network-process emacs)

Memory information:
((conses 16 230999 17175)
  (symbols 48 9468 0)
  (strings 32 20964 1914)
  (string-bytes 1 755167)
  (vectors 16 8263)
  (vector-slots 8 149910 14088)
  (floats 8 26 18)
  (intervals 56 223 0)
  (buffers 992 10))