Skip to content

Commit c39dc7f

Browse files
committed
refactor: move subtle color hack to +color-subtle and fix an edge case
1 parent 005870c commit c39dc7f

File tree

3 files changed

+25
-16
lines changed

3 files changed

+25
-16
lines changed

core/me-builtin.el

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,19 +139,15 @@
139139
;; Show trailing whitespace in `prog-mode' and `conf-mode'
140140
(+setq-hook! (prog-mode conf-mode) show-trailing-whitespace t)
141141

142-
;; Lighter color for trailing whitespaces
143-
(defun +face--lighter-trailing-whitespace-h (&rest _args)
142+
;; Subtle color for trailing whitespaces
143+
(defun +face--subtle-trailing-whitespace-h (&rest _args)
144144
(with-eval-after-load 'faces
145145
(when (display-graphic-p)
146-
(require 'color)
147-
(set-face-background
148-
'trailing-whitespace
149-
(funcall (if (eq 'light (frame-parameter nil 'background-mode)) #'color-lighten-name #'color-darken-name)
150-
(face-attribute 'error :foreground nil t)
151-
50)))))
146+
(when-let* ((new-color (+color-subtle 'error 50)))
147+
(set-face-background 'trailing-whitespace new-color)))))
152148

153149
(dolist (hook '(enable-theme-functions disable-theme-functions server-after-make-frame-hook))
154-
(add-hook hook #'+face--lighter-trailing-whitespace-h))
150+
(add-hook hook #'+face--subtle-trailing-whitespace-h))
155151

156152
;; By default, Emacs asks before quitting with "C-x C-c", but when running an
157153
;; Emacs Client session, it won't ask unless a file is not saved. I hit "C-x

core/me-lib.el

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,25 @@ scaling factor for the font in Emacs' `face-font-rescale-alist'. See the
10271027
:overline (face-attribute 'default :foreground nil t)
10281028
:background (face-attribute 'default :background nil t)))
10291029

1030+
(autoload 'color-darken-name "color")
1031+
(autoload 'color-lighten-name "color")
1032+
1033+
(defun +color-subtle (base-color percentage &optional face-attr)
1034+
"Make a more subtle color based on BASE-COLOR and PERCENTAGE.
1035+
1036+
We mean by subtle here, a darker color in dark themes and a lighter
1037+
color in light themes.
1038+
1039+
BASE-COLOR can be a color (string) or a face.
1040+
When it is a face, the FACE-ATTR needs to be provided, otherwise, the
1041+
:background attribute will be used."
1042+
(let ((base-color (if (facep base-color)
1043+
(face-attribute base-color (or face-attr :background) nil t)
1044+
base-color)))
1045+
(when (color-defined-p base-color)
1046+
(funcall (if (eq 'light (frame-parameter nil 'background-mode)) #'color-lighten-name #'color-darken-name)
1047+
base-color percentage))))
1048+
10301049

10311050

10321051
;;; Lazy on-demand modules

modules/me-editor.el

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,7 @@ In some files, there is a mix of spaces and tabs. This uses
126126
(with-eval-after-load 'selection-highlight-mode
127127
(with-eval-after-load 'isearch
128128
(when (display-graphic-p)
129-
(require 'color)
130-
(let ((new-color (funcall
131-
(if (eq 'light (frame-parameter nil 'background-mode))
132-
#'color-lighten-name
133-
#'color-darken-name)
134-
(face-attribute 'isearch :background nil t)
135-
5)))
129+
(when-let* ((new-color (+color-subtle 'isearch 5)))
136130
(set-face-background 'selection-highlight-mode-match-face new-color)
137131
(set-face-background 'selection-highlight-mode-alternate-match-face new-color))))))))
138132

0 commit comments

Comments
 (0)