This variable holds a list of functions that Emacs should call before redisplaying a window with scrolling. Displaying a different buffer in the window also runs these functions.
(add-hook 'window-buffer-change-functions
(lambda (window)
(message "%s is active" (current-buffer))
)
nil
t ; buffer-locally
)
文档:
Documentation:
Functions called during redisplay when window buffers have changed.
The value should be a list of functions that take one argument.
Functions specified buffer-locally are called for each window showing
the corresponding buffer if and only if that window has been added or
changed its buffer since the last redisplay. In this case the window
is passed as argument.
Functions specified by the default value are called for each frame if
at least one window on that frame has been added, deleted or changed
its buffer since the last redisplay. In this case the frame is passed
as argument.