gonewest818 / dimmer.el

Interactively highlight which buffer is active by dimming the others.
GNU General Public License v3.0
267 stars 14 forks source link

mode line highlighting with perspective.el and the darkburn theme #39

Closed gonewest818 closed 4 years ago

gonewest818 commented 4 years ago

This issue came up in discussion at the Emacs SF user group. When using the perspective package and the darkburn theme, the part of the modeline that shows which perspective you are using doesn't look correct when dimmed. In particular, the name of the selected perspective seems to get the wrong color.

Here's the repro (see this article for an explanation)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 
;; to show visual artifact when using darkburn, dimmer, and perspective packages
;;
;; run with:
;;           # copy the my-init.el gist somewhere, e.g. ~/Downloads
;;           mkdir ./target # or rm -rf ./target/*
;;           cp my-init.el ./target
;;           cd ./target
;;           /usr/local/bin/emacs -q -l init.el --batch # ignore the ivy-switch-buffer warning
;;           /usr/local/bin/emacs -q -l init.el
;;
;;           M-x persp-switch \r foo \r
;;           C-x 2
;;           M-x persp-switch \r bar \r
;;           C-x 2
;;           C-x o
;;
;;           Note that "bar" is a different color in the dimmed modeline
;;           this is probably correct behavior, not sure what would be better, changing color?
;;
;;           M-x persp-next
;;           M-x persp-next
;;           M-x persp-next
;;           C-x o
;;           C-x o

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; set user-emacs-directory to the directory where this file lives
;; do not read or write anything in $HOME/.emacs.d

(setq user-init-file (or load-file-name (buffer-file-name)))
(setq user-emacs-directory (file-name-directory user-init-file))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; set custom-file to write into a separate place

(setq custom-file (concat user-emacs-directory ".custom.el"))
(when (file-readable-p custom-file) (load custom-file))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; configure melpa (and other repos if needed)

(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
(setq package-enable-at-startup nil)
(package-initialize)
(when (not package-archive-contents)
    (package-refresh-contents))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; bootstrap `use-package'

(setq package-pinned-packages
      '((bind-key           . "melpa")
        (diminish           . "melpa")
        (use-package        . "melpa")))

(dolist (p (mapcar 'car package-pinned-packages))
  (unless (package-installed-p p)
    (package-install p)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; install and configure packages

(use-package darkburn-theme
  :ensure t
  :init
  (load-theme 'darkburn t))

(use-package dimmer
  :ensure t
  :config
  (setq dimmer-fraction 0.4)
  (setq dimmer-debug-messages 3)
  (dimmer-mode t))

(use-package perspective
  :defer 1
  :ensure t
  :config
  (persp-mode))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
gonewest818 commented 4 years ago

I was able to reproduce this without dimmer active at all. The problem lies in the darkburn theme. darkburn re-defines a face named persp-selected-face to highlight the text in the modeline. The definition of that face is

   `(persp-selected-face ((t (:foreground ,darkburn-yellow-2 :inherit mode-line))))

The :inherit mode-line suggests the background color is meant to match whatever the modeline says. However, there is also a mode-line-inactive face which uses a darker background for any window that isn't active. And this is the problem, because this face can't adjust when it is used in an inactive modeline. So even when dimmer is not used, you can see this highlighting looks wrong when you split the frame into two windows.

Workaround is to override persp-selected-face and just remove the :inherit mode-line attribute:

(use-package darkburn-theme
  :ensure t
  :init
  (load-theme 'darkburn t)
  (darkburn-with-color-variables
   (custom-theme-set-faces
    'darkburn
    `(persp-selected-face ((t (:foreground ,darkburn-yellow-2)))))))

Arguably this could be fixed upstream in the theme as well.