Skip to content

Commit

Permalink
refactor: Add helper for overriding icon args
Browse files Browse the repository at this point in the history
  • Loading branch information
mohkale committed May 14, 2023
1 parent a684cdf commit 313c83f
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions all-the-icons.el
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,17 @@ for performance sake.")
;; Functions Start
;; ====================

(cl-defsubst all-the-icons--override-args (args overrides)
"Override an `all-the-icons' icon arg list ARGS with OVERRIDES.
ARGS should be a list of arguments supplied to an all-the-icons icon
function such as `all-the-icons-octicon'. The first entry in ARGS
should be the icon name, the remaining entries should be overrides
for that icon. OVERRIDES should be a new set of OVERRIDES that will
take precedence over (cdr args)."
(when overrides
(setq args (append (list (car args)) overrides (cdr args))))
args)

(defun all-the-icons-auto-mode-match? (&optional file)
"Whether or not FILE's `major-mode' match against its `auto-mode-alist'."
(let* ((file (or file (buffer-file-name) (buffer-name)))
Expand Down Expand Up @@ -961,7 +972,9 @@ This is used by `all-the-icons--web-mode'."
(defun all-the-icons--web-mode (&optional family arg-overrides)
"Return icon or FAMILY for `web-mode' based on `web-mode-content-type'.
Providing ARG-OVERRIDES will modify the creation of the icon."
(let* ((non-nil-args (cl-reduce (lambda (acc it) (if it (append acc (list it)) acc)) arg-overrides :initial-value '()))
(let* ((non-nil-args (cl-reduce (lambda (acc it)
(if it (append acc (list it)) acc))
arg-overrides :initial-value '()))
(icon (cdr
(or
(when (boundp 'web-mode-content-type)
Expand All @@ -972,7 +985,7 @@ Providing ARG-OVERRIDES will modify the creation of the icon."
(if family
(funcall (intern (format "%s-family" (car icon))))
(when non-nil-args
(setq args (append `(,(car args)) non-nil-args (cdr args))))
(setq args (all-the-icons--override-args args non-nil-args)))
(apply (car icon) args)))))

;; Icon Functions
Expand Down Expand Up @@ -1016,7 +1029,8 @@ Note: You want chevron, please use `all-the-icons-icon-for-dir-with-chevron'."
(setq icon (car icon-override)
args (append (cdr icon-override) (cdr args))))

(when arg-overrides (setq args (append `(,(car args)) arg-overrides (cdr args))))
(when arg-overrides
(setq args (all-the-icons--override-args args arg-overrides)))
(apply (car icon) args)))

;;;###autoload
Expand All @@ -1032,7 +1046,8 @@ inserting functions."
all-the-icons-extension-icon-alist)))
all-the-icons-default-file-icon))
(args (cdr icon)))
(when arg-overrides (setq args (append `(,(car args)) arg-overrides (cdr args))))
(when arg-overrides
(setq args (all-the-icons--override-args args arg-overrides)))
(apply (car icon) args)))

;;;###autoload
Expand All @@ -1044,7 +1059,8 @@ inserting functions."
(let* ((icon (cdr (or (assoc mode all-the-icons-mode-icon-alist)
(assoc (get mode 'derived-mode-parent) all-the-icons-mode-icon-alist))))
(args (cdr icon)))
(when arg-overrides (setq args (append `(,(car args)) arg-overrides (cdr args))))
(when arg-overrides
(setq args (all-the-icons--override-args args arg-overrides)))
(if icon (apply (car icon) args) mode)))

;;;###autoload
Expand All @@ -1058,7 +1074,8 @@ inserting functions."
(or (all-the-icons-match-to-alist url all-the-icons-url-alist)
(alist-get t all-the-icons-url-alist)))
(args (cdr icon)))
(when arg-overrides (setq args (append `(,(car args)) arg-overrides (cdr args))))
(when arg-overrides
(setq args (all-the-icons--override-args args arg-overrides)))
(apply (car icon) args)))

(defcustom all-the-icons--cache-limit 2048
Expand Down

0 comments on commit 313c83f

Please sign in to comment.