]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix indirect font changes incorrectly affecting original buffer
authorAndrew Hyatt <ahyatt@gmail.com>
Thu, 20 Jan 2022 13:42:31 +0000 (14:42 +0100)
committerLars Ingebrigtsen <larsi@gnus.org>
Thu, 20 Jan 2022 13:42:31 +0000 (14:42 +0100)
* 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
lisp/simple.el
src/buffer.c

index 00560f9d2e11da6770aeb64973d71b10702d76f9..95dffcadd681ea514afaf04b5ea9156b850f016f 100644 (file)
    :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
index 8b1e7fe78b01eb41688de8327ca00b62416bb281..dcc385c7ec63a6068507344e620c72d144e1e07a 100644 (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))
index a3091015d9bdbe315a1024589ab1d16f4444f372..f5f7127a6380b4bd73a603dafc8f7fd51208e7ac 100644 (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);