Subject: bug#75949: kill-buffer-quit-windows breaks kill-buffer-hook

From: martin rudalics <[email-masked]>
Date: Sun, 2 Feb 2025 09:52:49 +0100

> Since a new argument can't be added, another variant would be at least
 > to set the current buffer before every call of the hook functions.
 > I.e. instead of
 >
 >    (run-hooks 'kill-buffer-hook)
 >
 > to do something like
 >
 >    (run-hook-wrapped 'kill-buffer-hook
 >                      (lambda (fun)
 >                        (with-current-buffer current-buffer
 >                          (funcall fun))
 >                        nil))
 >
 > But this won't help when buffers are switched inside hook functions.

The problem is that we run hooks completely in C so wrapping is at least
not that simple.  Whatever it is, nesting 'kill-buffer-hook' as in

  (add-hook 'kill-buffer-hook (lambda () (kill-buffer (get-buffer "bar")))
	    nil t)

is not really recommended.

martin