mina86 / auto-dim-other-buffers.el

Visually makes non-selected windows less prominent
GNU General Public License v3.0
92 stars 13 forks source link

Unable to change auto-dim-other-buffers-face on theme change #9

Closed jschaf closed 8 years ago

jschaf commented 8 years ago

Hi,

I'm having a bunch of trouble trying to change the auto-dim-other-buffers-face when the theme changes. The new face to remap default doesn't seem to get changed. When I start emacs, I expect the other buffers to be slightly dimmed (3.5%) compared to the background. Instead, they are the default black color.

I can't figure out why the color isn't changing. Any ideas?

(defun my:reset-auto-dim-face (&rest args)
  "Adjust `auto-dim-other-buffers-face' to the current background color.
ARGs are unused and are only for when this funciton is used as advice."
  (interactive)
  (let* ((percent-to-darken 3.5)
         (current-background-color (face-background 'default))
         (new-auto-dim-color
          (color-darken-name current-background-color percent-to-darken)))
    (setq auto-dim-other-buffers-face
          `((t :background ,new-auto-dim-color)))
    ;; Remove all face remappings.
    (adob--dim-all-buffers nil)
    ;; Re-add all face remappings.
    (adob--dim-all-buffers t)
    ;; Un-dim current buffer.
    (adob--dim-buffer nil)))

(add-hook 'after-init-hook #'auto-dim-other-buffers-mode)

(add-hook 'after-init-hook #'my:reset-auto-dim-face)

(advice-add 'load-theme :after 'my:reset-auto-dim-face)
mina86 commented 8 years ago

Use set-face-background to change background colour of a face. You also won’t need to call any of the adob--* private functions.

jschaf commented 8 years ago

Awesome, works like a charm. Here's the working code if anyone else stumbles onto this.


(defun my:reset-auto-dim-face (&rest args)
  "Adjust `auto-dim-other-buffers-face' to the current background color.
ARGs is unused and are only for when this function is used as advice."
  (interactive)
  (let* ((percent-to-darken 3.5)
         (current-background-color (face-background 'default))
         (new-auto-dim-background-color
          (color-darken-name current-background-color percent-to-darken)))
    (set-face-background 'auto-dim-other-buffers-face
                         new-auto-dim-background-color)))
(add-hook 'after-init-hook #'auto-dim-other-buffers-mode)
(add-hook 'after-init-hook #'my:reset-auto-dim-face)
(advice-add 'load-theme :after 'my:reset-auto-dim-face)