@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
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
@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
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.
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
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
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
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
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}.
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
@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
a copy of the string. This helps avoid trouble when strings are
shared or constants.
++++
+** Temporary buffers no longer run certain buffer hooks.
+The macros 'with-temp-buffer' and 'with-temp-file' no longer run the
+hooks 'kill-buffer-hook', 'kill-buffer-query-functions', and
+'buffer-list-update-hook' for the temporary buffers they create. This
+avoids slowing them down when a lot of these hooks are defined.
+
---
** The obsolete function 'thread-alive-p' has been removed.
** The error 'ftp-error' belongs also to category 'remote-file-error'.
++++
+** Buffers can now be created with certain hooks disabled.
+The functions 'get-buffer-create' and 'generate-new-buffer' accept a
+new optional argument 'inhibit-buffer-hooks'. If non-nil, the new
+buffer does not run the hooks 'kill-buffer-hook',
+'kill-buffer-query-functions', and 'buffer-list-update-hook'. This
+avoids slowing down internal or temporary buffers that are never
+presented to users or passed on to other applications.
+
\f
* Changes in Emacs 28.1 on Non-Free Operating Systems
The buffer being killed is current while the hook is running.
See `kill-buffer'.
+This hook is not run for internal or temporary buffers created by
+`get-buffer-create' or `generate-new-buffer' with argument
+INHIBIT-BUFFER-HOOKS non-nil.
+
Note: Be careful with let-binding this hook considering it is
frequently used for cleanup.")
(let ((lastname (file-name-nondirectory filename)))
(if (string= lastname "")
(setq lastname filename))
- (generate-new-buffer (if (string-match-p "\\` " lastname)
+ (generate-new-buffer (if (string-prefix-p " " lastname)
(concat "|" lastname)
lastname))))
(save-excursion
(switch-to-buffer (current-buffer))
(delete-other-windows)
- (let ((buffer (get-buffer-create (generate-new-buffer-name
- "*Warning*"))))
+ (let ((buffer (generate-new-buffer "*Warning*")))
(unless
(unwind-protect
(with-current-buffer buffer
(and (null noerror)
(signal 'file-error (list "Cannot open load file" file)))
;; Read file with code conversion, and then eval.
- (let* ((buffer
- ;; We can't use `generate-new-buffer' because files.el
- ;; is not yet loaded.
- (get-buffer-create (generate-new-buffer-name " *load*")))
- (load-in-progress t)
- (source (save-match-data (string-match "\\.el\\'" fullname))))
+ (let ((buffer (generate-new-buffer " *load*"))
+ (load-in-progress t)
+ (source (string-suffix-p ".el" fullname)))
(unless nomessage
(if source
(message "Loading %s (source)..." file)
(concat "\"" (substring-no-properties string) "\"")
(with-current-buffer
(or json--string-buffer
- (with-current-buffer (generate-new-buffer " *json-string*")
+ (with-current-buffer (generate-new-buffer " *json-string*" t)
;; This seems to afford decent performance gains.
(setq-local inhibit-modification-hooks t)
(setq json--string-buffer (current-buffer))))
be displayed in a buffer and position specified by MARKER. The
actual display is carried out by the SENTINEL function."
(if mh-wget-executable
- (let ((buffer (get-buffer-create (generate-new-buffer-name
- mh-temp-fetch-buffer)))
+ (let ((buffer (generate-new-buffer mh-temp-fetch-buffer))
(filename (or (mh-funcall-if-exists make-temp-file "mhe-fetch")
(expand-file-name (make-temp-name "~/mhe-fetch")))))
(with-current-buffer buffer
(when (funcall (nth 1 (assq stream imap-stream-alist)) buffer)
;; Stream changed?
(if (not (eq imap-default-stream stream))
- (with-current-buffer (get-buffer-create
- (generate-new-buffer-name " *temp*"))
+ (with-current-buffer (generate-new-buffer " *temp*")
(mapc 'make-local-variable imap-local-variables)
(set-buffer-multibyte nil)
(buffer-disable-undo)
(when
(save-window-excursion
(delete-other-windows)
- (let ((buffer (get-buffer-create (generate-new-buffer-name
- "*Warning*"))))
+ (let ((buffer (generate-new-buffer "*Warning*")))
(unwind-protect
(with-current-buffer buffer
(insert (substitute-command-keys
(defun flymake-proc--read-file-to-temp-buffer (file-name)
"Insert contents of FILE-NAME into newly created temp buffer."
- (let* ((temp-buffer (get-buffer-create (generate-new-buffer-name (concat "flymake:" (file-name-nondirectory file-name))))))
- (with-current-buffer temp-buffer
- (insert-file-contents file-name))
- temp-buffer))
+ (with-current-buffer (generate-new-buffer
+ (concat "flymake:" (file-name-nondirectory file-name)))
+ (insert-file-contents file-name)
+ (current-buffer)))
(defun flymake-proc--copy-buffer-to-temp-buffer (buffer)
"Copy contents of BUFFER into newly created temp buffer."
- (with-current-buffer
- (get-buffer-create (generate-new-buffer-name
- (concat "flymake:" (buffer-name buffer))))
+ (with-current-buffer (generate-new-buffer
+ (concat "flymake:" (buffer-name buffer)))
(insert-buffer-substring buffer)
(current-buffer)))
(defun shell-command-to-string (command)
"Execute shell command COMMAND and return its output as a string."
(with-output-to-string
- (with-current-buffer
- standard-output
+ (with-current-buffer standard-output
(shell-command command t))))
(defun process-file (program &optional infile buffer display &rest args)
(when (window-live-p (nth 1 state))
(select-window (nth 1 state) 'norecord)))
-(defun generate-new-buffer (name)
+(defun generate-new-buffer (name &optional inhibit-buffer-hooks)
"Create and return a buffer with a name based on NAME.
-Choose the buffer's name using `generate-new-buffer-name'."
- (get-buffer-create (generate-new-buffer-name name)))
+Choose the buffer's name using `generate-new-buffer-name'.
+See `get-buffer-create' for the meaning of INHIBIT-BUFFER-HOOKS."
+ (get-buffer-create (generate-new-buffer-name name) inhibit-buffer-hooks))
(defmacro with-selected-window (window &rest body)
"Execute the forms in BODY with WINDOW as the selected window.
(defmacro with-temp-file (file &rest body)
"Create a new buffer, evaluate BODY there, and write the buffer to FILE.
The value returned is the value of the last form in BODY.
+The buffer does not run the hooks `kill-buffer-hook',
+`kill-buffer-query-functions', and `buffer-list-update-hook'.
See also `with-temp-buffer'."
(declare (indent 1) (debug t))
(let ((temp-file (make-symbol "temp-file"))
(temp-buffer (make-symbol "temp-buffer")))
`(let ((,temp-file ,file)
- (,temp-buffer (generate-new-buffer " *temp file*")))
+ (,temp-buffer (generate-new-buffer " *temp file*" t)))
(unwind-protect
(prog1
(with-current-buffer ,temp-buffer
(defmacro with-temp-buffer (&rest body)
"Create a temporary buffer, and evaluate BODY there like `progn'.
+The buffer does not run the hooks `kill-buffer-hook',
+`kill-buffer-query-functions', and `buffer-list-update-hook'.
See also `with-temp-file' and `with-output-to-string'."
(declare (indent 0) (debug t))
(let ((temp-buffer (make-symbol "temp-buffer")))
- `(let ((,temp-buffer (generate-new-buffer " *temp*")))
+ `(let ((,temp-buffer (generate-new-buffer " *temp*" t)))
;; `kill-buffer' can change current-buffer in some odd cases.
(with-current-buffer ,temp-buffer
(unwind-protect
(defmacro with-output-to-string (&rest body)
"Execute BODY, return the text it sent to `standard-output', as a string."
(declare (indent 0) (debug t))
- `(let ((standard-output (generate-new-buffer " *string-output*")))
+ `(let ((standard-output (generate-new-buffer " *string-output*" t)))
(unwind-protect
(progn
(let ((standard-output standard-output))
#include "window.h"
#include "commands.h"
#include "character.h"
-#include "coding.h"
#include "buffer.h"
#include "region-cache.h"
#include "indent.h"
return Qnil;
}
-DEFUN ("get-buffer-create", Fget_buffer_create, Sget_buffer_create, 1, 1, 0,
+/* Run buffer-list-update-hook if Vrun_hooks is non-nil, and BUF is NULL
+ or does not have buffer hooks inhibited. BUF is NULL when called by
+ make-indirect-buffer, since it does not inhibit buffer hooks. */
+
+static void
+run_buffer_list_update_hook (struct buffer *buf)
+{
+ if (! (NILP (Vrun_hooks) || (buf && buf->inhibit_buffer_hooks)))
+ call1 (Vrun_hooks, Qbuffer_list_update_hook);
+}
+
+DEFUN ("get-buffer-create", Fget_buffer_create, Sget_buffer_create, 1, 2, 0,
doc: /* Return the buffer specified by BUFFER-OR-NAME, creating a new one if needed.
If BUFFER-OR-NAME is a string and a live buffer with that name exists,
return that buffer. If no such buffer exists, create a new buffer with
-that name and return it. If BUFFER-OR-NAME starts with a space, the new
-buffer does not keep undo information.
+that name and return it.
+
+If BUFFER-OR-NAME starts with a space, the new buffer does not keep undo
+information. If optional argument INHIBIT-BUFFER-HOOKS is non-nil, the
+new buffer does not run the hooks `kill-buffer-hook',
+`kill-buffer-query-functions', and `buffer-list-update-hook'. This
+avoids slowing down internal or temporary buffers that are never
+presented to users or passed on to other applications.
If BUFFER-OR-NAME is a buffer instead of a string, return it as given,
even if it is dead. The return value is never nil. */)
- (register Lisp_Object buffer_or_name)
+ (register Lisp_Object buffer_or_name, Lisp_Object inhibit_buffer_hooks)
{
register Lisp_Object buffer, name;
register struct buffer *b;
set_string_intervals (name, NULL);
bset_name (b, name);
- b->inhibit_buffer_hooks
- = (STRINGP (Vcode_conversion_workbuf_name)
- && strncmp (SSDATA (name), SSDATA (Vcode_conversion_workbuf_name),
- SBYTES (Vcode_conversion_workbuf_name)) == 0);
-
+ b->inhibit_buffer_hooks = !NILP (inhibit_buffer_hooks);
bset_undo_list (b, SREF (name, 0) != ' ' ? Qnil : Qt);
reset_buffer (b);
/* Put this in the alist of all live buffers. */
XSETBUFFER (buffer, b);
Vbuffer_alist = nconc2 (Vbuffer_alist, list1 (Fcons (name, buffer)));
- /* And run buffer-list-update-hook. */
- if (!NILP (Vrun_hooks) && !b->inhibit_buffer_hooks)
- call1 (Vrun_hooks, Qbuffer_list_update_hook);
+
+ run_buffer_list_update_hook (b);
return buffer;
}
set_buffer_internal_1 (old_b);
}
- /* Run buffer-list-update-hook. */
- if (!NILP (Vrun_hooks))
- call1 (Vrun_hooks, Qbuffer_list_update_hook);
+ run_buffer_list_update_hook (NULL);
return buf;
}
&& !NILP (BVAR (current_buffer, auto_save_file_name)))
call0 (intern ("rename-auto-save-file"));
- /* Run buffer-list-update-hook. */
- if (!NILP (Vrun_hooks) && !current_buffer->inhibit_buffer_hooks)
- call1 (Vrun_hooks, Qbuffer_list_update_hook);
+ run_buffer_list_update_hook (current_buffer);
/* Refetch since that last call may have done GC. */
return BVAR (current_buffer, name);
buf = Fget_buffer (scratch);
if (NILP (buf))
{
- buf = Fget_buffer_create (scratch);
+ buf = Fget_buffer_create (scratch, Qnil);
Fset_buffer_major_mode (buf);
}
return buf;
buf = Fget_buffer (scratch);
if (NILP (buf))
{
- buf = Fget_buffer_create (scratch);
+ buf = Fget_buffer_create (scratch, Qnil);
Fset_buffer_major_mode (buf);
}
the buffer is not killed. The hook `kill-buffer-hook' is run before the
buffer is actually killed. The buffer being killed will be current
while the hook is running. Functions called by any of these hooks are
-supposed to not change the current buffer.
+supposed to not change the current buffer. Neither hook is run for
+internal or temporary buffers created by `get-buffer-create' or
+`generate-new-buffer' with argument INHIBIT-BUFFER-HOOKS non-nil.
Any processes that have this buffer as the `process-buffer' are killed
with SIGHUP. This function calls `replace-buffer-in-windows' for
bset_width_table (b, Qnil);
unblock_input ();
- /* Run buffer-list-update-hook. */
- if (!NILP (Vrun_hooks) && !b->inhibit_buffer_hooks)
- call1 (Vrun_hooks, Qbuffer_list_update_hook);
+ run_buffer_list_update_hook (b);
return Qt;
}
fset_buffer_list (f, Fcons (buffer, Fdelq (buffer, f->buffer_list)));
fset_buried_buffer_list (f, Fdelq (buffer, f->buried_buffer_list));
- /* Run buffer-list-update-hook. */
- if (!NILP (Vrun_hooks) && !XBUFFER (buffer)->inhibit_buffer_hooks)
- call1 (Vrun_hooks, Qbuffer_list_update_hook);
+ run_buffer_list_update_hook (XBUFFER (buffer));
}
fset_buried_buffer_list
(f, Fcons (buffer, Fdelq (buffer, f->buried_buffer_list)));
- /* Run buffer-list-update-hook. */
- if (!NILP (Vrun_hooks) && !XBUFFER (buffer)->inhibit_buffer_hooks)
- call1 (Vrun_hooks, Qbuffer_list_update_hook);
+ run_buffer_list_update_hook (XBUFFER (buffer));
return Qnil;
}
Fput (Qkill_buffer_hook, Qpermanent_local, Qt);
/* Super-magic invisible buffer. */
- Vprin1_to_string_buffer = Fget_buffer_create (build_pure_c_string (" prin1"));
+ Vprin1_to_string_buffer =
+ Fget_buffer_create (build_pure_c_string (" prin1"), Qt);
Vbuffer_alist = Qnil;
- Fset_buffer (Fget_buffer_create (build_pure_c_string ("*scratch*")));
+ Fset_buffer (Fget_buffer_create (build_pure_c_string ("*scratch*"), Qnil));
inhibit_modification_hooks = 0;
}
#endif /* USE_MMAP_FOR_BUFFERS */
AUTO_STRING (scratch, "*scratch*");
- Fset_buffer (Fget_buffer_create (scratch));
+ Fset_buffer (Fget_buffer_create (scratch, Qnil));
if (NILP (BVAR (&buffer_defaults, enable_multibyte_characters)))
Fset_buffer_multibyte (Qnil);
DEFVAR_LISP ("kill-buffer-query-functions", Vkill_buffer_query_functions,
doc: /* List of functions called with no args to query before killing a buffer.
The buffer being killed will be current while the functions are running.
+See `kill-buffer'.
If any of them returns nil, the buffer is not killed. Functions run by
-this hook are supposed to not change the current buffer. */);
+this hook are supposed to not change the current buffer.
+
+This hook is not run for internal or temporary buffers created by
+`get-buffer-create' or `generate-new-buffer' with argument
+INHIBIT-BUFFER-HOOKS non-nil. */);
Vkill_buffer_query_functions = Qnil;
DEFVAR_LISP ("change-major-mode-hook", Vchange_major_mode_hook,
doc: /* Hook run when the buffer list changes.
Functions (implicitly) running this hook are `get-buffer-create',
`make-indirect-buffer', `rename-buffer', `kill-buffer', `bury-buffer'
-and `select-window'. Functions run by this hook should avoid calling
-`select-window' with a nil NORECORD argument or `with-temp-buffer'
-since either may lead to infinite recursion. */);
+and `select-window'. This hook is not run for internal or temporary
+buffers created by `get-buffer-create' or `generate-new-buffer' with
+argument INHIBIT-BUFFER-HOOKS non-nil.
+
+Functions run by this hook should avoid calling `select-window' with a
+nil NORECORD argument since it may lead to infinite recursion. */);
Vbuffer_list_update_hook = Qnil;
DEFSYM (Qbuffer_list_update_hook, "buffer-list-update-hook");
/* Non-zero whenever the narrowing is changed in this buffer. */
bool_bf clip_changed : 1;
- /* Non-zero for internally used temporary buffers that don't need to
- run hooks kill-buffer-hook, buffer-list-update-hook, and
- kill-buffer-query-functions. This is used in coding.c to avoid
- slowing down en/decoding when there are a lot of these hooks
- defined. */
+ /* Non-zero for internal or temporary buffers that don't need to
+ run hooks kill-buffer-hook, kill-buffer-query-functions, and
+ buffer-list-update-hook. This is used in coding.c to avoid
+ slowing down en/decoding when a lot of these hooks are
+ defined, as well as by with-temp-buffer, for example. */
bool_bf inhibit_buffer_hooks : 1;
/* List of overlays that end at or before the current center,
if (! (NILP (buffer) || EQ (buffer, Qt) || FIXNUMP (buffer)))
{
- Lisp_Object spec_buffer;
- spec_buffer = buffer;
- buffer = Fget_buffer_create (buffer);
+ Lisp_Object spec_buffer = buffer;
+ buffer = Fget_buffer_create (buffer, Qnil);
/* Mention the buffer name for a better error message. */
if (NILP (buffer))
CHECK_BUFFER (spec_buffer);
/* A string that serves as name of the reusable work buffer, and as base
name of temporary work buffers used for code-conversion operations. */
-Lisp_Object Vcode_conversion_workbuf_name;
+static Lisp_Object Vcode_conversion_workbuf_name;
/* The reusable working buffer, created once and never killed. */
static Lisp_Object Vcode_conversion_reused_workbuf;
if (! NILP (workbuf))
{
if (EQ (workbuf, Vcode_conversion_reused_workbuf))
- reused_workbuf_in_use = 0;
+ reused_workbuf_in_use = false;
else
Fkill_buffer (workbuf);
}
{
Lisp_Object name
= Fgenerate_new_buffer_name (Vcode_conversion_workbuf_name, Qnil);
- workbuf = Fget_buffer_create (name);
+ workbuf = Fget_buffer_create (name, Qt);
}
else
{
if (NILP (Fbuffer_live_p (Vcode_conversion_reused_workbuf)))
Vcode_conversion_reused_workbuf
- = Fget_buffer_create (Vcode_conversion_workbuf_name);
+ = Fget_buffer_create (Vcode_conversion_workbuf_name, Qt);
workbuf = Vcode_conversion_reused_workbuf;
}
}
bset_undo_list (current_buffer, Qt);
bset_enable_multibyte_characters (current_buffer, multibyte ? Qt : Qnil);
if (EQ (workbuf, Vcode_conversion_reused_workbuf))
- reused_workbuf_in_use = 1;
+ reused_workbuf_in_use = true;
set_buffer_internal (current);
}
staticpro (&Vcode_conversion_workbuf_name);
Vcode_conversion_workbuf_name = build_pure_c_string (" *code-conversion-work*");
- reused_workbuf_in_use = 0;
+ reused_workbuf_in_use = false;
PDUMPER_REMEMBER_SCALAR (reused_workbuf_in_use);
DEFSYM (Qcharset, "charset");
extern Lisp_Object Vcoding_system_hash_table;
-/* Name (or base name) of work buffer for code conversion. */
-extern Lisp_Object Vcode_conversion_workbuf_name;
-
/* Enumeration of index to an attribute vector of a coding system. */
enum coding_attr_index
record_unwind_current_buffer ();
- workbuf = Fget_buffer_create (name);
+ workbuf = Fget_buffer_create (name, Qt);
buf = XBUFFER (workbuf);
delete_all_overlays (buf);
static char const name_fmt[] = " *Minibuf-%"pI"d*";
char name[sizeof name_fmt + INT_STRLEN_BOUND (EMACS_INT)];
AUTO_STRING_WITH_LEN (lname, name, sprintf (name, name_fmt, depth));
- buf = Fget_buffer_create (lname);
+ buf = Fget_buffer_create (lname, Qnil);
/* Although the buffer's name starts with a space, undo should be
enabled in it. */
record_unwind_current_buffer ();
- Fset_buffer (Fget_buffer_create (build_string (bufname)));
+ Fset_buffer (Fget_buffer_create (build_string (bufname), Qnil));
Fkill_all_local_variables ();
delete_all_overlays (current_buffer);
buffer = Fplist_get (contact, QCbuffer);
if (!NILP (buffer))
- buffer = Fget_buffer_create (buffer);
+ buffer = Fget_buffer_create (buffer, Qnil);
/* Make sure that the child will be able to chdir to the current
buffer's current directory, or its unhandled equivalent. We
QCname,
concat2 (name, build_string (" stderr")),
QCbuffer,
- Fget_buffer_create (xstderr),
+ Fget_buffer_create (xstderr, Qnil),
QCnoquery,
query_on_exit ? Qnil : Qt);
}
buffer = Fplist_get (contact, QCbuffer);
if (NILP (buffer))
buffer = name;
- buffer = Fget_buffer_create (buffer);
+ buffer = Fget_buffer_create (buffer, Qnil);
pset_buffer (p, buffer);
pset_childp (p, contact);
buffer = Fplist_get (contact, QCbuffer);
if (NILP (buffer))
buffer = name;
- buffer = Fget_buffer_create (buffer);
+ buffer = Fget_buffer_create (buffer, Qnil);
pset_buffer (p, buffer);
pset_childp (p, contact);
open_socket:
if (!NILP (buffer))
- buffer = Fget_buffer_create (buffer);
+ buffer = Fget_buffer_create (buffer, Qnil);
/* Unwind bind_polling_period. */
unbind_to (count, Qnil);
if (!NILP (buffer))
{
args[1] = buffer;
- buffer = Fget_buffer_create (Fformat (nargs, args));
+ buffer = Fget_buffer_create (Fformat (nargs, args), Qnil);
}
}
tip_f = XFRAME (tip_frame);
window = FRAME_ROOT_WINDOW (tip_f);
- tip_buf = Fget_buffer_create (tip);
+ tip_buf = Fget_buffer_create (tip, Qnil);
/* We will mark the tip window a "pseudo-window" below, and such
windows cannot have display margins. */
bset_left_margin_cols (XBUFFER (tip_buf), make_fixnum (0));
Run `buffer-list-update-hook' unless NORECORD is non-nil. Note that
applications and internal routines often select a window temporarily for
various purposes; mostly, to simplify coding. As a rule, such
-selections should be not recorded and therefore will not pollute
+selections should not be recorded and therefore will not pollute
`buffer-list-update-hook'. Selections that "really count" are those
causing a visible change in the next redisplay of WINDOW's frame and
-should be always recorded. So if you think of running a function each
-time a window gets selected put it on `buffer-list-update-hook'.
+should always be recorded. So if you think of running a function each
+time a window gets selected, put it on `buffer-list-update-hook' or
+`window-selection-change-functions'.
Also note that the main editor command loop sets the current buffer to
the buffer of the selected window before each command. */)
/* Ensure the Messages buffer exists, and switch to it.
If we created it, set the major-mode. */
bool newbuffer = NILP (Fget_buffer (Vmessages_buffer_name));
- Fset_buffer (Fget_buffer_create (Vmessages_buffer_name));
+ Fset_buffer (Fget_buffer_create (Vmessages_buffer_name, Qnil));
if (newbuffer
&& !NILP (Ffboundp (intern ("messages-buffer-mode"))))
call0 (intern ("messages-buffer-mode"));
static char const name_fmt[] = " *Echo Area %d*";
char name[sizeof name_fmt + INT_STRLEN_BOUND (int)];
AUTO_STRING_WITH_LEN (lname, name, sprintf (name, name_fmt, i));
- echo_buffer[i] = Fget_buffer_create (lname);
+ echo_buffer[i] = Fget_buffer_create (lname, Qnil);
bset_truncate_lines (XBUFFER (echo_buffer[i]), Qnil);
/* to force word wrap in echo area -
it was decided to postpone this*/
tip_f = XFRAME (tip_frame);
window = FRAME_ROOT_WINDOW (tip_f);
- tip_buf = Fget_buffer_create (tip);
+ tip_buf = Fget_buffer_create (tip, Qnil);
/* We will mark the tip window a "pseudo-window" below, and such
windows cannot have display margins. */
bset_left_margin_cols (XBUFFER (tip_buf), make_fixnum (0));
Lisp_Object val;
xw->type = type;
xw->title = title;
- xw->buffer = NILP (buffer) ? Fcurrent_buffer () : Fget_buffer_create (buffer);
+ xw->buffer = (NILP (buffer) ? Fcurrent_buffer ()
+ : Fget_buffer_create (buffer, Qnil));
xw->height = XFIXNAT (height);
xw->width = XFIXNAT (width);
xw->kill_without_query = false;
;;; Code:
-(require 'ert)
-(require 'seq)
-(eval-when-compile (require 'cl-lib))
+(require 'cl-lib)
(ert-deftest overlay-modification-hooks-message-other-buf ()
"Test for bug#21824.
(with-temp-buffer
(should (assq 'buffer-undo-list (buffer-local-variables)))))
+(ert-deftest buffer-tests-inhibit-buffer-hooks ()
+ "Test `get-buffer-create' argument INHIBIT-BUFFER-HOOKS."
+ (let* (run-bluh (bluh (lambda () (setq run-bluh t))))
+ (unwind-protect
+ (let* ( run-kbh (kbh (lambda () (setq run-kbh t)))
+ run-kbqf (kbqf (lambda () (setq run-kbqf t))) )
+
+ ;; Inhibited.
+ (add-hook 'buffer-list-update-hook bluh)
+ (with-current-buffer (generate-new-buffer " foo" t)
+ (add-hook 'kill-buffer-hook kbh nil t)
+ (add-hook 'kill-buffer-query-functions kbqf nil t)
+ (kill-buffer))
+ (with-temp-buffer)
+ (with-output-to-string)
+ (should-not run-bluh)
+ (should-not run-kbh)
+ (should-not run-kbqf)
+
+ ;; Not inhibited.
+ (with-current-buffer (generate-new-buffer " foo")
+ (should run-bluh)
+ (add-hook 'kill-buffer-hook kbh nil t)
+ (add-hook 'kill-buffer-query-functions kbqf nil t)
+ (kill-buffer))
+ (should run-kbh)
+ (should run-kbqf))
+ (remove-hook 'buffer-list-update-hook bluh))))
+
;;; buffer-tests.el ends here