aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modules/nerd-icons-config.el46
-rw-r--r--tests/test-nerd-icons-config--apply-tint.el63
2 files changed, 7 insertions, 102 deletions
diff --git a/modules/nerd-icons-config.el b/modules/nerd-icons-config.el
index d3d55b864..e2edb0717 100644
--- a/modules/nerd-icons-config.el
+++ b/modules/nerd-icons-config.el
@@ -1,4 +1,4 @@
-;;; nerd-icons-config.el --- Nerd-icons setup, integrations, and tinting -*- lexical-binding: t; -*-
+;;; nerd-icons-config.el --- Nerd-icons setup and integrations -*- lexical-binding: t; -*-
;; author: Craig Jennings <c@cjennings.net>
;;; Commentary:
@@ -16,51 +16,21 @@
;; - the package itself
;; - completion integration (`nerd-icons-completion')
;; - ibuffer integration (`nerd-icons-ibuffer')
-;; - bulk color tinting of every `nerd-icons-*' color face
;; - dir-icon color advice (so directory glyphs carry a color face like
;; file glyphs do, instead of falling through to the buffer default
;; face)
;;
+;; Icon colors are theme-driven: nerd-icons' 34 `nerd-icons-*' color faces are
+;; owned by the theme (themeable in theme-studio), not overwritten at load time.
+;;
;; Per-feature USE of nerd-icons stays in the feature module that consumes
;; it: `dashboard-icon-type', `dirvish-attributes', and the keyboard-compat
;; terminal-frame icon-blanking advice are not centralized here.
;;; Code:
-;; ----------------------------- Customization ---------------------------------
-
-(defcustom cj/nerd-icons-tint-color "darkgoldenrod"
- "Single foreground color applied to every `nerd-icons-*' color face.
-Set via Customize or by `setq' before this module loads, then call
-`cj/nerd-icons-apply-tint' to re-apply on demand."
- :type 'string
- :group 'cj)
-
-(defconst cj/--nerd-icons-color-faces
- '(nerd-icons-red nerd-icons-lred nerd-icons-dred nerd-icons-red-alt
- nerd-icons-green nerd-icons-lgreen nerd-icons-dgreen
- nerd-icons-yellow nerd-icons-lyellow nerd-icons-dyellow
- nerd-icons-orange nerd-icons-lorange nerd-icons-dorange
- nerd-icons-blue nerd-icons-blue-alt nerd-icons-lblue nerd-icons-dblue
- nerd-icons-cyan nerd-icons-cyan-alt nerd-icons-lcyan nerd-icons-dcyan
- nerd-icons-purple nerd-icons-purple-alt nerd-icons-lpurple nerd-icons-dpurple
- nerd-icons-pink nerd-icons-lpink nerd-icons-dpink
- nerd-icons-maroon nerd-icons-lmaroon nerd-icons-dmaroon
- nerd-icons-silver nerd-icons-lsilver nerd-icons-dsilver)
- "Every color face nerd-icons attaches to glyphs via `:inherit'.")
-
;; ------------------------------- Helpers -------------------------------------
-(defun cj/nerd-icons-apply-tint (&optional color)
- "Set every face in `cj/--nerd-icons-color-faces' to foreground COLOR.
-COLOR defaults to `cj/nerd-icons-tint-color'. Faces that are not yet
-defined (nerd-icons not loaded) are silently skipped."
- (interactive)
- (let ((c (or color cj/nerd-icons-tint-color)))
- (dolist (f cj/--nerd-icons-color-faces)
- (when (facep f)
- (set-face-foreground f c)))))
-
(defun cj/--nerd-icons-color-dir (icon)
"Layer `nerd-icons-yellow' onto ICON's face stack and return ICON.
ICON is the propertized string returned by `nerd-icons-icon-for-dir'.
@@ -87,17 +57,15 @@ every call. The `memq' check skips when the face is already present."
(use-package nerd-icons
:demand t
:config
- (advice-add 'nerd-icons-icon-for-dir :filter-return #'cj/--nerd-icons-color-dir)
- (cj/nerd-icons-apply-tint))
+ (advice-add 'nerd-icons-icon-for-dir :filter-return #'cj/--nerd-icons-color-dir))
;; Safety net: if this module is re-evaluated in a running Emacs where
;; nerd-icons is already loaded, `:config' above won't fire again --
-;; ensure the advice and tint still apply.
+;; ensure the dir advice still applies.
(with-eval-after-load 'nerd-icons
(unless (advice-member-p #'cj/--nerd-icons-color-dir 'nerd-icons-icon-for-dir)
(advice-add 'nerd-icons-icon-for-dir
- :filter-return #'cj/--nerd-icons-color-dir))
- (cj/nerd-icons-apply-tint))
+ :filter-return #'cj/--nerd-icons-color-dir)))
(use-package nerd-icons-completion
:demand t
diff --git a/tests/test-nerd-icons-config--apply-tint.el b/tests/test-nerd-icons-config--apply-tint.el
deleted file mode 100644
index ef723352c..000000000
--- a/tests/test-nerd-icons-config--apply-tint.el
+++ /dev/null
@@ -1,63 +0,0 @@
-;;; test-nerd-icons-config--apply-tint.el --- Tests for cj/nerd-icons-apply-tint -*- lexical-binding: t; -*-
-
-;;; Commentary:
-;; Tests for the bulk-tint helper. Mocks `set-face-foreground' and `facep'
-;; at the framework boundary so the tests don't depend on nerd-icons being
-;; loaded — only on the symbol list and the dispatch logic.
-
-;;; Code:
-
-(require 'ert)
-(require 'cl-lib)
-
-(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
-(require 'nerd-icons-config)
-
-(defmacro test-nerd-icons-config--capture-set-face-foreground (calls-var &rest body)
- "Run BODY with `set-face-foreground' and `facep' stubbed.
-Each (face color) pair gets pushed onto CALLS-VAR. `facep' returns t
-for every symbol so all faces in the list count as defined."
- (declare (indent 1) (debug t))
- `(cl-letf (((symbol-function 'set-face-foreground)
- (lambda (face color &rest _) (push (cons face color) ,calls-var)))
- ((symbol-function 'facep)
- (lambda (_) t)))
- ,@body))
-
-(ert-deftest test-nerd-icons-config--apply-tint-covers-every-face ()
- "Normal: apply-tint calls set-face-foreground once per face in the list."
- (let ((calls nil))
- (test-nerd-icons-config--capture-set-face-foreground calls
- (cj/nerd-icons-apply-tint "test-color"))
- (should (= (length calls) (length cj/--nerd-icons-color-faces)))
- (dolist (face cj/--nerd-icons-color-faces)
- (should (assq face calls)))))
-
-(ert-deftest test-nerd-icons-config--apply-tint-passes-color-arg ()
- "Normal: apply-tint forwards COLOR to every set-face-foreground call."
- (let ((calls nil))
- (test-nerd-icons-config--capture-set-face-foreground calls
- (cj/nerd-icons-apply-tint "rebeccapurple"))
- (dolist (call calls)
- (should (equal (cdr call) "rebeccapurple")))))
-
-(ert-deftest test-nerd-icons-config--apply-tint-defaults-to-customvar ()
- "Normal: with no COLOR arg, uses `cj/nerd-icons-tint-color'."
- (let ((calls nil))
- (test-nerd-icons-config--capture-set-face-foreground calls
- (let ((cj/nerd-icons-tint-color "default-test-color"))
- (cj/nerd-icons-apply-tint)))
- (should (cl-every (lambda (call) (equal (cdr call) "default-test-color")) calls))))
-
-(ert-deftest test-nerd-icons-config--apply-tint-skips-undefined-faces ()
- "Boundary: faces that fail `facep' are silently skipped, not errored."
- (let ((calls nil))
- (cl-letf (((symbol-function 'set-face-foreground)
- (lambda (face color &rest _) (push (cons face color) calls)))
- ((symbol-function 'facep)
- (lambda (_) nil)))
- (cj/nerd-icons-apply-tint "any"))
- (should (null calls))))
-
-(provide 'test-nerd-icons-config--apply-tint)
-;;; test-nerd-icons-config--apply-tint.el ends here