From: dickmao Date: Mon, 19 Jul 2021 16:12:17 +0000 (+0200) Subject: Make make-indirect-buffer inherit inhibit-buffer-hook from base buffer X-Git-Tag: emacs-28.0.90~1801^2~1 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=95e31a1a328a7548efa76befa74d430925ca7f6d;p=emacs.git Make make-indirect-buffer inherit inhibit-buffer-hook from base buffer * src/buffer.c (Fmake_indirect_buffer): Match base buffer's inhibit-buffer-hooks. * test/src/buffer-tests.el (buffer-tests-inhibit-buffer-hooks-indirect): Add a test (bug#49160). --- diff --git a/src/buffer.c b/src/buffer.c index 02ca23eb2dd..a574de16723 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -834,6 +834,7 @@ CLONE nil means the indirect buffer's state is reset to default values. */) b->pt_byte = b->base_buffer->pt_byte; b->begv_byte = b->base_buffer->begv_byte; b->zv_byte = b->base_buffer->zv_byte; + b->inhibit_buffer_hooks = b->base_buffer->inhibit_buffer_hooks; b->newline_cache = 0; b->width_run_cache = 0; diff --git a/test/src/buffer-tests.el b/test/src/buffer-tests.el index 123f2e8eabb..0161927419c 100644 --- a/test/src/buffer-tests.el +++ b/test/src/buffer-tests.el @@ -1361,4 +1361,28 @@ with parameters from the *Messages* buffer modification." (should run-kbqf)) (remove-hook 'buffer-list-update-hook bluh)))) +(ert-deftest buffer-tests-inhibit-buffer-hooks-indirect () + "Indirect buffers do not call `get-buffer-create'." + (dolist (inhibit '(nil t)) + (let ((base (get-buffer-create "foo" inhibit))) + (unwind-protect + (dotimes (_i 11) + (let* (flag* + (flag (lambda () (prog1 t (setq flag* t)))) + (indirect (make-indirect-buffer base "foo[indirect]"))) + (unwind-protect + (progn + (with-current-buffer indirect + (add-hook 'kill-buffer-query-functions flag nil t)) + (kill-buffer indirect) + (if inhibit + (should-not flag*) + (should flag*))) + (let (kill-buffer-query-functions) + (when (buffer-live-p indirect) + (kill-buffer indirect)))))) + (let (kill-buffer-query-functions) + (when (buffer-live-p base) + (kill-buffer base))))))) + ;;; buffer-tests.el ends here