aboutsummaryrefslogtreecommitdiffstats
path: root/test/src
diff options
context:
space:
mode:
authorBasil L. Contovounesios2020-12-19 12:39:45 +0000
committerBasil L. Contovounesios2020-12-20 17:32:24 +0000
commit1a0a11f7d2d1dbecb9f754b1e129d50e489058e6 (patch)
treeca78c82ccc83b90ae3e382097fdffc928097f881 /test/src
parent409a9dbe9da64b4d75fec1f511e168c94e60e35b (diff)
downloademacs-1a0a11f7d2d1dbecb9f754b1e129d50e489058e6.tar.gz
emacs-1a0a11f7d2d1dbecb9f754b1e129d50e489058e6.zip
Inhibit buffer hooks in temporary buffers
Give get-buffer-create an optional argument to inhibit buffer hooks in internal or temporary buffers for efficiency (bug#34765). * etc/NEWS: Announce new parameter of get-buffer-create and generate-new-buffer, and that with-temp-buffer and with-temp-file now inhibit buffer hooks. * doc/lispref/buffers.texi (Buffer Names): Fix typo. (Creating Buffers): Document new parameter of get-buffer-create and generate-new-buffer. (Buffer List, Killing Buffers): Document when buffer hooks are inhibited. (Current Buffer): * doc/lispref/files.texi (Writing to Files): Document that with-temp-buffer and with-temp-file inhibit buffer hooks. * doc/lispref/internals.texi (Buffer Internals): Document inhibit_buffer_hooks flag. Remove stale comment. * doc/misc/gnus-faq.texi (FAQ 5-8): * lisp/simple.el (shell-command-on-region): Fix indentation. * lisp/files.el (kill-buffer-hook): Document when hook is inhibited. (create-file-buffer): * lisp/gnus/gnus-uu.el (gnus-uu-unshar-article): * lisp/international/mule.el (load-with-code-conversion): * lisp/mh-e/mh-xface.el (mh-x-image-url-fetch-image): * lisp/net/imap.el (imap-open): * lisp/net/mailcap.el (mailcap-maybe-eval): * lisp/progmodes/flymake-proc.el (flymake-proc--read-file-to-temp-buffer) (flymake-proc--copy-buffer-to-temp-buffer): Simplify. * lisp/subr.el (generate-new-buffer): Forward new optional argument to inhibit buffer hooks to get-buffer-create. (with-temp-file, with-temp-buffer, with-output-to-string): * lisp/json.el (json-encode-string): Inhibit buffer hooks in buffer used. * src/buffer.c (run_buffer_list_update_hook): New helper function. (Fget_buffer_create): Use it. Add optional argument to set inhibit_buffer_hooks flag instead of comparing the buffer name to Vcode_conversion_workbuf_name. All callers changed. (Fmake_indirect_buffer, Frename_buffer, Fbury_buffer_internal) (record_buffer): Use run_buffer_list_update_hook. (Fkill_buffer): Document when buffer hooks are inhibited. Use run_buffer_list_update_hook. (init_buffer_once): Inhibit buffer hooks in Vprin1_to_string_buffer. (Vkill_buffer_query_functions, Vbuffer_list_update_hook): Document when hooks are inhibited. * src/buffer.h (struct buffer): Update inhibit_buffer_hooks commentary. * src/coding.h (Vcode_conversion_workbuf_name): * src/coding.c (Vcode_conversion_workbuf_name): Make static again since it is no longer needed in src/buffer.c. (code_conversion_restore, code_conversion_save, syms_of_coding): Prefer boolean over integer constants. * src/fileio.c (Finsert_file_contents): Inhibit buffer hooks in " *code-converting-work*" buffer. * src/window.c (Fselect_window): Fix grammar. Mention window-selection-change-functions alongside buffer-list-update-hook. * test/src/buffer-tests.el: Fix requires. (buffer-tests-inhibit-buffer-hooks): New test.
Diffstat (limited to 'test/src')
-rw-r--r--test/src/buffer-tests.el33
1 files changed, 30 insertions, 3 deletions
diff --git a/test/src/buffer-tests.el b/test/src/buffer-tests.el
index 0db66f97517..dd8927457ae 100644
--- a/test/src/buffer-tests.el
+++ b/test/src/buffer-tests.el
@@ -19,9 +19,7 @@
19 19
20;;; Code: 20;;; Code:
21 21
22(require 'ert) 22(require 'cl-lib)
23(require 'seq)
24(eval-when-compile (require 'cl-lib))
25 23
26(ert-deftest overlay-modification-hooks-message-other-buf () 24(ert-deftest overlay-modification-hooks-message-other-buf ()
27 "Test for bug#21824. 25 "Test for bug#21824.
@@ -1334,4 +1332,33 @@ with parameters from the *Messages* buffer modification."
1334 (with-temp-buffer 1332 (with-temp-buffer
1335 (should (assq 'buffer-undo-list (buffer-local-variables))))) 1333 (should (assq 'buffer-undo-list (buffer-local-variables)))))
1336 1334
1335(ert-deftest buffer-tests-inhibit-buffer-hooks ()
1336 "Test `get-buffer-create' argument INHIBIT-BUFFER-HOOKS."
1337 (let* (run-bluh (bluh (lambda () (setq run-bluh t))))
1338 (unwind-protect
1339 (let* ( run-kbh (kbh (lambda () (setq run-kbh t)))
1340 run-kbqf (kbqf (lambda () (setq run-kbqf t))) )
1341
1342 ;; Inhibited.
1343 (add-hook 'buffer-list-update-hook bluh)
1344 (with-current-buffer (generate-new-buffer " foo" t)
1345 (add-hook 'kill-buffer-hook kbh nil t)
1346 (add-hook 'kill-buffer-query-functions kbqf nil t)
1347 (kill-buffer))
1348 (with-temp-buffer)
1349 (with-output-to-string)
1350 (should-not run-bluh)
1351 (should-not run-kbh)
1352 (should-not run-kbqf)
1353
1354 ;; Not inhibited.
1355 (with-current-buffer (generate-new-buffer " foo")
1356 (should run-bluh)
1357 (add-hook 'kill-buffer-hook kbh nil t)
1358 (add-hook 'kill-buffer-query-functions kbqf nil t)
1359 (kill-buffer))
1360 (should run-kbh)
1361 (should run-kbqf))
1362 (remove-hook 'buffer-list-update-hook bluh))))
1363
1337;;; buffer-tests.el ends here 1364;;; buffer-tests.el ends here