GNU bug report logs - #56210
29.0.50; Keyboard macros do not trigger after-change-functions

Previous Next

Package: emacs;

Reported by: Richard Hansen <rhansen <at> rhansen.org>

Date: Sat, 25 Jun 2022 06:23:02 UTC

Severity: normal

Found in version 29.0.50

Done: Richard Hansen <rhansen <at> rhansen.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Eli Zaretskii <eliz <at> gnu.org>
To: Richard Hansen <rhansen <at> rhansen.org>
Cc: 56210 <at> debbugs.gnu.org, larsi <at> gnus.org
Subject: bug#56210: 29.0.50; Keyboard macros do not trigger after-change-functions
Date: Mon, 27 Jun 2022 19:54:36 +0300
> Date: Sun, 26 Jun 2022 23:21:24 -0400
> Cc: larsi <at> gnus.org, 56210 <at> debbugs.gnu.org
> From: Richard Hansen <rhansen <at> rhansen.org>
> 
> > Is the temporary buffer indeed modified, and is the hook set in that
> > buffer?
> 
> Yes on both accounts.  See updated test below.
> 
> I changed the test to switch to the temporary buffer in the selected window and it now reliably inserts "x" into the temporary buffer.  It still doesn't run the `after-change-functions' hook, however.  Updated test code:
> 
> ;; -*- lexical-binding: t; -*-
> (require 'ert)
> (require 'ert-x)
> (defvar-local acf 0)
> (defun acf (&rest _) (setq-local acf (1+ acf)))
> (ert-deftest test ()
>    (ert-with-test-buffer ()
>      (let ((b (current-buffer)))
>        (save-window-excursion
>          (with-current-buffer-window b
>              `(display-buffer-below-selected
>                (body-function
>                 . ,(lambda (window)
>                      (select-window window t)
>                      (should (eq (current-buffer) b))
>                      (setq-local acf 0)
>                      ;; Note that LOCAL is t:
>                      (add-hook 'after-change-functions #'acf nil t)
>                      (should (memq #'acf after-change-functions))
>                      (execute-kbd-macro (kbd "x"))
>                      (should (equal (buffer-string) "x"))
>                      ;; The above checks pass, this check fails:
>                      (should (equal acf 1)))))
>              nil)))))

Your test calls with-current-buffer-window, which calls
temp-buffer-window-setup, which inhibits modification hooks:

  (defun temp-buffer-window-setup (buffer-or-name)
    "Set up temporary buffer specified by BUFFER-OR-NAME.
  Return the buffer."
    (let ((old-dir default-directory)
	  (buffer (get-buffer-create buffer-or-name)))
      (with-current-buffer buffer
	(kill-all-local-variables)
	(setq default-directory old-dir)
	(delete-all-overlays)
	(setq buffer-read-only nil)
	(setq buffer-file-name nil)
	(setq buffer-undo-list t)
	(let ((inhibit-read-only t)
	      (inhibit-modification-hooks t))  <<<<<<<<<<<<<<<<<<<<<<
	  (erase-buffer)
	  (run-hooks 'temp-buffer-window-setup-hook))
	;; Return the buffer.
	buffer)))




This bug report was last modified 2 years and 329 days ago.

Previous Next


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