summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorBasil L. Contovounesios <contovob@tcd.ie>2020-12-19 12:39:45 +0000
committerBasil L. Contovounesios <contovob@tcd.ie>2020-12-20 17:32:24 +0000
commit1a0a11f7d2d1dbecb9f754b1e129d50e489058e6 (patch)
treeca78c82ccc83b90ae3e382097fdffc928097f881 /doc
parent409a9dbe9da64b4d75fec1f511e168c94e60e35b (diff)
downloademacs-1a0a11f7d2d1dbecb9f754b1e129d50e489058e6.tar.gz
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 'doc')
-rw-r--r--doc/lispref/buffers.texi59
-rw-r--r--doc/lispref/files.texi7
-rw-r--r--doc/lispref/internals.texi11
-rw-r--r--doc/misc/gnus-faq.texi8
4 files changed, 62 insertions, 23 deletions
diff --git a/doc/lispref/buffers.texi b/doc/lispref/buffers.texi
index 28603436284..33eb23984dd 100644
--- a/doc/lispref/buffers.texi
+++ b/doc/lispref/buffers.texi
@@ -225,13 +225,22 @@ current buffer is restored even in case of an abnormal exit via
@defmac with-temp-buffer body@dots{}
@anchor{Definition of with-temp-buffer}
-The @code{with-temp-buffer} macro evaluates the @var{body} forms
-with a temporary buffer as the current buffer. It saves the identity of
+The @code{with-temp-buffer} macro evaluates the @var{body} forms with
+a temporary buffer as the current buffer. It saves the identity of
the current buffer, creates a temporary buffer and makes it current,
evaluates the @var{body} forms, and finally restores the previous
-current buffer while killing the temporary buffer. By default, undo
-information (@pxref{Undo}) is not recorded in the buffer created by
-this macro (but @var{body} can enable that, if needed).
+current buffer while killing the temporary buffer.
+
+@cindex undo in temporary buffers
+@cindex @code{kill-buffer-hook} in temporary buffers
+@cindex @code{kill-buffer-query-functions} in temporary buffers
+@cindex @code{buffer-list-update-hook} in temporary buffers
+By default, undo information (@pxref{Undo}) is not recorded in the
+buffer created by this macro (but @var{body} can enable that, if
+needed). The temporary buffer also does not run the hooks
+@code{kill-buffer-hook}, @code{kill-buffer-query-functions}
+(@pxref{Killing Buffers}), and @code{buffer-list-update-hook}
+(@pxref{Buffer List}).
The return value is the value of the last form in @var{body}. You can
return the contents of the temporary buffer by using
@@ -345,9 +354,9 @@ incrementing the number until it is not the name of an existing buffer.
If the optional second argument @var{ignore} is non-@code{nil}, it
should be a string, a potential buffer name. It means to consider
-that potential buffer acceptable, if it is tried, even it is the name
-of an existing buffer (which would normally be rejected). Thus, if
-buffers named @samp{foo}, @samp{foo<2>}, @samp{foo<3>} and
+that potential buffer acceptable, if it is tried, even if it is the
+name of an existing buffer (which would normally be rejected). Thus,
+if buffers named @samp{foo}, @samp{foo<2>}, @samp{foo<3>} and
@samp{foo<4>} exist,
@example
@@ -932,13 +941,17 @@ window.
@defvar buffer-list-update-hook
This is a normal hook run whenever the buffer list changes. Functions
(implicitly) running this hook are @code{get-buffer-create}
-(@pxref{Creating Buffers}), @code{rename-buffer} (@pxref{Buffer Names}),
-@code{kill-buffer} (@pxref{Killing Buffers}), @code{bury-buffer} (see
-above) and @code{select-window} (@pxref{Selecting Windows}).
+(@pxref{Creating Buffers}), @code{rename-buffer} (@pxref{Buffer
+Names}), @code{kill-buffer} (@pxref{Killing Buffers}),
+@code{bury-buffer} (see above), and @code{select-window}
+(@pxref{Selecting Windows}). This hook is not run for internal or
+temporary buffers created by @code{get-buffer-create} or
+@code{generate-new-buffer} with a non-@code{nil} argument
+@var{inhibit-buffer-hooks}.
Functions run by this hook should avoid calling @code{select-window}
-with a nil @var{norecord} argument or @code{with-temp-buffer} since
-either may lead to infinite recursion.
+with a @code{nil} @var{norecord} argument since this may lead to
+infinite recursion.
@end defvar
@node Creating Buffers
@@ -951,12 +964,20 @@ either may lead to infinite recursion.
with the specified name; @code{generate-new-buffer} always creates a new
buffer and gives it a unique name.
+ Both functions accept an optional argument @var{inhibit-buffer-hooks}.
+If it is non-@code{nil}, the buffer they create does not run the hooks
+@code{kill-buffer-hook}, @code{kill-buffer-query-functions}
+(@pxref{Killing Buffers}), and @code{buffer-list-update-hook}
+(@pxref{Buffer List}). This avoids slowing down internal or temporary
+buffers that are never presented to users or passed on to other
+applications.
+
Other functions you can use to create buffers include
@code{with-output-to-temp-buffer} (@pxref{Temporary Displays}) and
@code{create-file-buffer} (@pxref{Visiting Files}). Starting a
subprocess can also create a buffer (@pxref{Processes}).
-@defun get-buffer-create buffer-or-name
+@defun get-buffer-create buffer-or-name &optional inhibit-buffer-hooks
This function returns a buffer named @var{buffer-or-name}. The buffer
returned does not become the current buffer---this function does not
change which buffer is current.
@@ -980,7 +1001,7 @@ level; see @ref{Auto Major Mode}.) If the name begins with a space, the
buffer initially disables undo information recording (@pxref{Undo}).
@end defun
-@defun generate-new-buffer name
+@defun generate-new-buffer name &optional inhibit-buffer-hooks
This function returns a newly created, empty buffer, but does not make
it current. The name of the buffer is generated by passing @var{name}
to the function @code{generate-new-buffer-name} (@pxref{Buffer
@@ -1092,6 +1113,10 @@ with no arguments. The buffer being killed is the current buffer when
they are called. The idea of this feature is that these functions will
ask for confirmation from the user. If any of them returns @code{nil},
@code{kill-buffer} spares the buffer's life.
+
+This hook is not run for internal or temporary buffers created by
+@code{get-buffer-create} or @code{generate-new-buffer} with a
+non-@code{nil} argument @var{inhibit-buffer-hooks}.
@end defvar
@defvar kill-buffer-hook
@@ -1100,6 +1125,10 @@ questions it is going to ask, just before actually killing the buffer.
The buffer to be killed is current when the hook functions run.
@xref{Hooks}. This variable is a permanent local, so its local binding
is not cleared by changing major modes.
+
+This hook is not run for internal or temporary buffers created by
+@code{get-buffer-create} or @code{generate-new-buffer} with a
+non-@code{nil} argument @var{inhibit-buffer-hooks}.
@end defvar
@defopt buffer-offer-save
diff --git a/doc/lispref/files.texi b/doc/lispref/files.texi
index d49ac42bb46..6949ca29c6e 100644
--- a/doc/lispref/files.texi
+++ b/doc/lispref/files.texi
@@ -701,8 +701,11 @@ in @var{body}.
The current buffer is restored even in case of an abnormal exit via
@code{throw} or error (@pxref{Nonlocal Exits}).
-See also @code{with-temp-buffer} in @ref{Definition of
-with-temp-buffer,, The Current Buffer}.
+Like @code{with-temp-buffer} (@pxref{Definition of with-temp-buffer,,
+Current Buffer}), the temporary buffer used by this macro does not run
+the hooks @code{kill-buffer-hook}, @code{kill-buffer-query-functions}
+(@pxref{Killing Buffers}), and @code{buffer-list-update-hook}
+(@pxref{Buffer List}).
@end defmac
@node File Locks
diff --git a/doc/lispref/internals.texi b/doc/lispref/internals.texi
index fa3dacbb7ae..0adbef33cac 100644
--- a/doc/lispref/internals.texi
+++ b/doc/lispref/internals.texi
@@ -2391,6 +2391,15 @@ This flag indicates that narrowing has changed in the buffer.
This flag indicates that redisplay optimizations should not be used to
display this buffer.
+@item inhibit_buffer_hooks
+This flag indicates that the buffer should not run the hooks
+@code{kill-buffer-hook}, @code{kill-buffer-query-functions}
+(@pxref{Killing Buffers}), and @code{buffer-list-update-hook}
+(@pxref{Buffer List}). It is set at buffer creation (@pxref{Creating
+Buffers}), and avoids slowing down internal or temporary buffers, such
+as those created by @code{with-temp-buffer} (@pxref{Definition of
+with-temp-buffer,, Current Buffer}).
+
@item overlay_center
This field holds the current overlay center position. @xref{Managing
Overlays}.
@@ -2404,8 +2413,6 @@ after the current overlay center. @xref{Managing Overlays}.
and @code{overlays_after} is sorted in order of increasing beginning
position.
-@c FIXME? the following are now all Lisp_Object BUFFER_INTERNAL_FIELD (foo).
-
@item name
A Lisp string that names the buffer. It is guaranteed to be unique.
@xref{Buffer Names}. This and the following fields have their names
diff --git a/doc/misc/gnus-faq.texi b/doc/misc/gnus-faq.texi
index adb812f5728..c30e80ff565 100644
--- a/doc/misc/gnus-faq.texi
+++ b/doc/misc/gnus-faq.texi
@@ -1523,10 +1523,10 @@ Now you only have to tell Gnus to include the X-face in your postings by saying
@example
(setq message-default-headers
- (with-temp-buffer
- (insert "X-Face: ")
- (insert-file-contents "~/.xface")
- (buffer-string)))
+ (with-temp-buffer
+ (insert "X-Face: ")
+ (insert-file-contents "~/.xface")
+ (buffer-string)))
@end example
@noindent