Fix indirect font changes incorrectly affecting original buffer

* lisp/face-remap.el (face-attrs--make-indirect-safe):
(clone-indirect-buffer-hook): Set up a face remapping alist
(bug#53294).

* lisp/simple.el (clone-indirect-buffer): Move the point the hook
is run.

* src/buffer.c (Fmake_indirect_buffer, syms_of_buffer): Move the
place where the clone-indirect-buffer-hook variable is defined, so
that we can call it from C.
This commit is contained in:
Andrew Hyatt 2022-01-20 14:42:31 +01:00 committed by Lars Ingebrigtsen
parent 4450c8bdd9
commit 27b3948a8a
3 changed files with 17 additions and 5 deletions

View file

@ -70,6 +70,13 @@
:foreground :background :stipple :overline :strike-through :box
:font :inherit :fontset :distant-foreground :extend :vector])
(defun face-attrs--make-indirect-safe ()
"Deep copy `face-remapping-alist' on cloning for safety."
(setq-local face-remapping-alist
(mapcar #'copy-sequence face-remapping-alist)))
(add-hook 'clone-indirect-buffer-hook #'face-attrs--make-indirect-safe)
(defun face-attrs-more-relative-p (attrs1 attrs2)
"Return true if ATTRS1 contains a greater number of relative
face-attributes than ATTRS2. A face attribute is considered

View file

@ -9441,9 +9441,6 @@ PREFIX is the string that represents this modifier in an event type symbol."
(defvar clone-buffer-hook nil
"Normal hook to run in the new buffer at the end of `clone-buffer'.")
(defvar clone-indirect-buffer-hook nil
"Normal hook to run in the new buffer at the end of `clone-indirect-buffer'.")
(defun clone-process (process &optional newname)
"Create a twin copy of PROCESS.
If NEWNAME is nil, it defaults to PROCESS' name;
@ -9596,8 +9593,6 @@ Returns the newly created indirect buffer."
(setq newname (substring newname 0 (match-beginning 0))))
(let* ((name (generate-new-buffer-name newname))
(buffer (make-indirect-buffer (current-buffer) name t)))
(with-current-buffer buffer
(run-hooks 'clone-indirect-buffer-hook))
(when display-flag
(pop-to-buffer buffer nil norecord))
buffer))

View file

@ -912,6 +912,10 @@ does not run the hooks `kill-buffer-hook',
Fset (intern ("buffer-save-without-query"), Qnil);
Fset (intern ("buffer-file-number"), Qnil);
Fset (intern ("buffer-stale-function"), Qnil);
/* Cloned buffers need extra setup, to do things such as deep
variable copies for list variables that might be mangled due
to destructive operations in the indirect buffer. */
run_hook (Qclone_indirect_buffer_hook);
set_buffer_internal_1 (old_b);
}
@ -5569,6 +5573,8 @@ syms_of_buffer (void)
Fput (Qprotected_field, Qerror_message,
build_pure_c_string ("Attempt to modify a protected field"));
DEFSYM (Qclone_indirect_buffer_hook, "clone-indirect-buffer-hook");
DEFVAR_PER_BUFFER ("tab-line-format",
&BVAR (current_buffer, tab_line_format),
Qnil,
@ -6392,6 +6398,10 @@ If `delete-auto-save-files' is nil, any autosave deletion is inhibited. */);
This is the default. If nil, auto-save file deletion is inhibited. */);
delete_auto_save_files = 1;
DEFVAR_LISP ("clone-indirect-buffer-hook", Vclone_indirect_buffer_hook,
doc: /* Normal hook to run in the new buffer at the end of `clone-indirect-buffer'. */);
Vclone_indirect_buffer_hook = Qnil;
defsubr (&Sbuffer_live_p);
defsubr (&Sbuffer_list);
defsubr (&Sget_buffer);