File tree Expand file tree Collapse file tree 3 files changed +25
-16
lines changed Expand file tree Collapse file tree 3 files changed +25
-16
lines changed Original file line number Diff line number Diff line change 139
139
; ; Show trailing whitespace in `prog-mode' and `conf-mode'
140
140
(+setq-hook! (prog-mode conf-mode) show-trailing-whitespace t )
141
141
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)
144
144
(with-eval-after-load 'faces
145
145
(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)))))
152
148
153
149
(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 ))
155
151
156
152
; ; By default, Emacs asks before quitting with "C-x C-c", but when running an
157
153
; ; Emacs Client session, it won't ask unless a file is not saved. I hit "C-x
Original file line number Diff line number Diff line change @@ -1027,6 +1027,25 @@ scaling factor for the font in Emacs' `face-font-rescale-alist'. See the
1027
1027
:overline (face-attribute 'default :foreground nil t )
1028
1028
:background (face-attribute 'default :background nil t )))
1029
1029
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
+
1030
1049
1031
1050
1032
1051
; ;; Lazy on-demand modules
Original file line number Diff line number Diff line change @@ -126,13 +126,7 @@ In some files, there is a mix of spaces and tabs. This uses
126
126
(with-eval-after-load 'selection-highlight-mode
127
127
(with-eval-after-load 'isearch
128
128
(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 )))
136
130
(set-face-background 'selection-highlight-mode-match-face new-color)
137
131
(set-face-background 'selection-highlight-mode-alternate-match-face new-color))))))))
138
132
You can’t perform that action at this time.
0 commit comments