[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 27b3948a8a 2/3: Fix indirect font changes incorrectly affecting o
From: |
Lars Ingebrigtsen |
Subject: |
master 27b3948a8a 2/3: Fix indirect font changes incorrectly affecting original buffer |
Date: |
Thu, 20 Jan 2022 08:53:25 -0500 (EST) |
branch: master
commit 27b3948a8a29f263272d10c1ee1c50d87797ff50
Author: Andrew Hyatt <ahyatt@gmail.com>
Commit: Lars Ingebrigtsen <larsi@gnus.org>
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.
---
lisp/face-remap.el | 7 +++++++
lisp/simple.el | 5 -----
src/buffer.c | 10 ++++++++++
3 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/lisp/face-remap.el b/lisp/face-remap.el
index 00560f9d2e..95dffcadd6 100644
--- a/lisp/face-remap.el
+++ b/lisp/face-remap.el
@@ -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
diff --git a/lisp/simple.el b/lisp/simple.el
index 8b1e7fe78b..dcc385c7ec 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -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))
diff --git a/src/buffer.c b/src/buffer.c
index a3091015d9..f5f7127a63 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -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);