emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/auto-dim-other-buffers 62c936d502 78/82: Fix buffer undimm


From: ELPA Syncer
Subject: [nongnu] elpa/auto-dim-other-buffers 62c936d502 78/82: Fix buffer undimming when local variables are killed
Date: Mon, 12 Dec 2022 20:58:47 -0500 (EST)

branch: elpa/auto-dim-other-buffers
commit 62c936d502f35d168b9e59a66c994d74a62ad2cf
Author: Michal Nazarewicz <mina86@mina86.com>
Commit: Michal Nazarewicz <mina86@mina86.com>

    Fix buffer undimming when local variables are killed
    
    The ‘kill-all-local-variables’ function kills all local variables and
    face remapping.  This is a problem because adob is never notified of
    the face remapping being removed.  If the buffer is not selected but
    visible the result is that it becomes undimmed.
    
    To reproduce the issue evaluate from a buffer using ‘eval-last-sexp’
    (C-x C-e) or equivalent.  Do not use interactive ‘eval-expression’.
    
        (with-current-buffer (get-buffer "*adob-test*")
          (kill-all-local-variables))
    
    Now set up at lest two windows one of which showing ‘*adob-test*’
    buffer.  Select another window (‘*adob-test*’ should dim) and evaluate
    the above again.  The test buffer should remain dimmed but becomes
    undimmed even though it’s not the selected window.
    
    There’s no hook that is called after the removal of face remapping and
    marking ‘face-remapping-alist’ as a ‘permanent-local’ doesn’t sound
    like a good idea so to fix the issue I’ve ended up adding an advice
    around the ‘kill-all-local-variables’ function.
---
 auto-dim-other-buffers.el | 25 +++++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/auto-dim-other-buffers.el b/auto-dim-other-buffers.el
index 79f22bdea1..f7fc4a5036 100644
--- a/auto-dim-other-buffers.el
+++ b/auto-dim-other-buffers.el
@@ -2,7 +2,7 @@
 ;; Author: Michal Nazarewicz <mina86@mina86.com>
 ;; Maintainer: Michal Nazarewicz <mina86@mina86.com>
 ;; URL: https://github.com/mina86/auto-dim-other-buffers.el
-;; Version: 2.0.4
+;; Version: 2.0.5
 
 ;; This file is not part of GNU Emacs.
 
@@ -116,6 +116,7 @@ dimmed.  In addition to that, outside of adow-mode (see
 
 (defvar-local adob--face-mode-remapping nil
   "Current face remapping cookie for `auto-dim-other-buffers-mode'.")
+(put 'adob--face-mode-remapping 'permanent-local nil)
 
 (defun adob--remap-face (buffer object)
   "Make sure face remapping is active in BUFFER unless its never-dim.
@@ -142,6 +143,17 @@ Return non-nil if remapping has been added to BUFFER."
       (force-window-update object)
       wants)))
 
+(defun adob--kill-all-local-variables-advice (kill)
+  "Restores face remapping after killing all local variables.
+This is intended as an advice around ‘kill-all-local-variables’
+function which removes all buffer face remapping which is
+something we don’t want."
+  (unless (prog1 (not adob--face-mode-remapping)
+          (funcall kill))
+    (setq adob--face-mode-remapping
+          (face-remap-add-relative 'default adob--remap-face))
+    nil))
+
 (defun adob--unmap-face (buffer object)
   "Make sure face remapping is inactive in BUFFER.
 
@@ -364,9 +376,14 @@ behaviour is where the mode gets its name from."
 
   (save-current-buffer
     (if auto-dim-other-buffers-mode
-        ;; Dim all except for selected buffer.
-        (adob--initialize)
-
+        (progn
+          (advice-add #'kill-all-local-variables :around
+                      #'adob--kill-all-local-variables-advice)
+          ;; Dim all except for selected buffer.
+          (adob--initialize))
+
+      (advice-remove #'kill-all-local-variables
+                     #'adob--kill-all-local-variables-advice)
       ;; Clean up by removing all face remaps.
       (setq adob--last-buffer nil
             adob--last-window nil)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]