mirror of
https://github.com/ryuslash/mode-icons.git
synced 2024-11-24 10:30:30 +01:00
One face function
This commit is contained in:
parent
0f1c9fcefa
commit
dfdfb573e4
1 changed files with 40 additions and 63 deletions
101
mode-icons.el
101
mode-icons.el
|
@ -423,6 +423,11 @@ This only works with xpm files."
|
||||||
(defvar mode-icons-get-icon-display (make-hash-table :test 'equal)
|
(defvar mode-icons-get-icon-display (make-hash-table :test 'equal)
|
||||||
"Hash table of `mode-icons-get-icon-display'.")
|
"Hash table of `mode-icons-get-icon-display'.")
|
||||||
|
|
||||||
|
(defun mode-icons-get-face (&optional face active)
|
||||||
|
"If FACE is unspecified, use ACTIVE to determine the face.
|
||||||
|
ACTIVE tells if current window is active."
|
||||||
|
(or face (and active 'mode-line) 'mode-line-inactive))
|
||||||
|
|
||||||
(defun mode-icons-get-icon-display (icon type &optional face active)
|
(defun mode-icons-get-icon-display (icon type &optional face active)
|
||||||
"Get the value for the display property of ICON having TYPE.
|
"Get the value for the display property of ICON having TYPE.
|
||||||
|
|
||||||
|
@ -434,7 +439,7 @@ FACE should be the face for rendering black and white xpm icons
|
||||||
specified by type 'xpm-bw.
|
specified by type 'xpm-bw.
|
||||||
|
|
||||||
ACTIVE is an indicator that the current window is active."
|
ACTIVE is an indicator that the current window is active."
|
||||||
(let* ((face (or face (and active 'mode-line) 'mode-line-inactive))
|
(let* ((face (mode-icons-get-face face active))
|
||||||
(key (list icon type face active
|
(key (list icon type face active
|
||||||
mode-icons-desaturate-inactive mode-icons-desaturate-active
|
mode-icons-desaturate-inactive mode-icons-desaturate-active
|
||||||
mode-icons-grayscale-transform custom-enabled-themes))
|
mode-icons-grayscale-transform custom-enabled-themes))
|
||||||
|
@ -966,18 +971,18 @@ ACTIVE is a flag telling if the current window is active."
|
||||||
(xpm-name (mode-icons--get-png-xpm-file icon-spec t))
|
(xpm-name (mode-icons--get-png-xpm-file icon-spec t))
|
||||||
(xpm-p (file-readable-p xpm))
|
(xpm-p (file-readable-p xpm))
|
||||||
(png (mode-icons-get-icon-file (concat (nth 1 icon-spec) ".png")))
|
(png (mode-icons-get-icon-file (concat (nth 1 icon-spec) ".png")))
|
||||||
(png-p (file-readable-p png)))
|
(png-p (file-readable-p png))
|
||||||
|
(face (mode-icons-get-face face active)))
|
||||||
(if xpm-p
|
(if xpm-p
|
||||||
(propertize (format "%s" mode) 'display
|
(propertize (format "%s" mode) 'display
|
||||||
(mode-icons-get-icon-display
|
(mode-icons-get-icon-display
|
||||||
xpm-name 'xpm
|
xpm-name 'xpm
|
||||||
(or face
|
face active)
|
||||||
(and (mode-icons--selected-window-active)
|
'face face
|
||||||
'mode-line)
|
|
||||||
'mode-line-inactive) active)
|
|
||||||
'mode-icons-p (list (nth 0 icon-spec) xpm-name 'xpm))
|
'mode-icons-p (list (nth 0 icon-spec) xpm-name 'xpm))
|
||||||
(if (not png-p)
|
(if (not png-p)
|
||||||
(propertize (format "%s" mode)
|
(propertize (format "%s" mode)
|
||||||
|
'face face
|
||||||
'mode-icons-p icon-spec)
|
'mode-icons-p icon-spec)
|
||||||
(mode-icons--convert-png-to-xpm png xpm)
|
(mode-icons--convert-png-to-xpm png xpm)
|
||||||
(propertize (format "%s" mode)
|
(propertize (format "%s" mode)
|
||||||
|
@ -992,6 +997,7 @@ ACTIVE is a flag telling if the current window is active."
|
||||||
:ascent 'center
|
:ascent 'center
|
||||||
:heuristic-mask t
|
:heuristic-mask t
|
||||||
:face face)
|
:face face)
|
||||||
|
'face face
|
||||||
'mode-icons-p icon-spec)))))
|
'mode-icons-p icon-spec)))))
|
||||||
|
|
||||||
(defcustom mode-icons-prefer-xpm-over-emoji nil
|
(defcustom mode-icons-prefer-xpm-over-emoji nil
|
||||||
|
@ -1011,17 +1017,14 @@ the actual font."
|
||||||
ACTIVE is a flag for if the current window is active."
|
ACTIVE is a flag for if the current window is active."
|
||||||
(let* ((xpm (mode-icons--get-emoji-xpm-file icon-spec))
|
(let* ((xpm (mode-icons--get-emoji-xpm-file icon-spec))
|
||||||
(xpm-name (mode-icons--get-emoji-xpm-file icon-spec t))
|
(xpm-name (mode-icons--get-emoji-xpm-file icon-spec t))
|
||||||
(xpm-p (file-readable-p xpm)))
|
(xpm-p (file-readable-p xpm))
|
||||||
|
(face (mode-icons-get-face face active)))
|
||||||
(if (or (and mode-icons-prefer-xpm-over-emoji xpm-p)
|
(if (or (and mode-icons-prefer-xpm-over-emoji xpm-p)
|
||||||
(and xpm-p (not (featurep 'emojify)))
|
(and xpm-p (not (featurep 'emojify)))
|
||||||
(and xpm-p (not (image-type-available-p 'png))))
|
(and xpm-p (not (image-type-available-p 'png))))
|
||||||
(propertize (format "%s" mode) 'display
|
(propertize (format "%s" mode) 'display
|
||||||
(mode-icons-get-icon-display
|
(mode-icons-get-icon-display
|
||||||
xpm-name 'xpm
|
xpm-name 'xpm face active)
|
||||||
(or face
|
|
||||||
(and (mode-icons--selected-window-active)
|
|
||||||
'mode-line)
|
|
||||||
'mode-line-inactive) active)
|
|
||||||
'mode-icons-p (list (nth 0 icon-spec) xpm-name 'xpm))
|
'mode-icons-p (list (nth 0 icon-spec) xpm-name 'xpm))
|
||||||
(unless emojify-emojis
|
(unless emojify-emojis
|
||||||
(emojify-set-emoji-data))
|
(emojify-set-emoji-data))
|
||||||
|
@ -1030,6 +1033,7 @@ ACTIVE is a flag for if the current window is active."
|
||||||
(image-type (intern (upcase (file-name-extension image-file)))))
|
(image-type (intern (upcase (file-name-extension image-file)))))
|
||||||
(if (not (file-exists-p image-file))
|
(if (not (file-exists-p image-file))
|
||||||
(propertize (format "%s" mode)
|
(propertize (format "%s" mode)
|
||||||
|
'face face
|
||||||
'mode-icons-p icon-spec)
|
'mode-icons-p icon-spec)
|
||||||
(when mode-icons-generate-emoji-xpms
|
(when mode-icons-generate-emoji-xpms
|
||||||
(mode-icons--convert-png-to-xpm image-file xpm))
|
(mode-icons--convert-png-to-xpm image-file xpm))
|
||||||
|
@ -1048,6 +1052,7 @@ ACTIVE is a flag for if the current window is active."
|
||||||
;; :background (emojify--get-image-background beg end)
|
;; :background (emojify--get-image-background beg end)
|
||||||
;; no-op if imagemagick is not available
|
;; no-op if imagemagick is not available
|
||||||
:height (emojify-default-font-height))
|
:height (emojify-default-font-height))
|
||||||
|
'face face
|
||||||
'mode-icons-p icon-spec))))))
|
'mode-icons-p icon-spec))))))
|
||||||
|
|
||||||
(defcustom mode-icons-prefer-xpm-over-font nil
|
(defcustom mode-icons-prefer-xpm-over-font nil
|
||||||
|
@ -1068,18 +1073,15 @@ ACTIVE if a flag for if the current window is active."
|
||||||
;; Use `compose-region' because it allows clicable text.
|
;; Use `compose-region' because it allows clicable text.
|
||||||
(let* ((xpm (mode-icons--get-font-xpm-file icon-spec))
|
(let* ((xpm (mode-icons--get-font-xpm-file icon-spec))
|
||||||
(xpm-name (mode-icons--get-font-xpm-file icon-spec t))
|
(xpm-name (mode-icons--get-font-xpm-file icon-spec t))
|
||||||
(xpm-p (file-readable-p xpm)))
|
(xpm-p (file-readable-p xpm))
|
||||||
|
(face (mode-icons-get-face face active)))
|
||||||
(when (and (not xpm-p) mode-icons-generate-font-xpms)
|
(when (and (not xpm-p) mode-icons-generate-font-xpms)
|
||||||
(mode-icons--create-font-xpm-file icon-spec))
|
(mode-icons--create-font-xpm-file icon-spec))
|
||||||
(if (and xpm-p (or mode-icons-prefer-xpm-over-font
|
(if (and xpm-p (or mode-icons-prefer-xpm-over-font
|
||||||
(not (mode-icons-supported-font-p (nth 1 icon-spec) (nth 2 icon-spec)))))
|
(not (mode-icons-supported-font-p (nth 1 icon-spec) (nth 2 icon-spec)))))
|
||||||
(propertize (format "%s" mode) 'display
|
(propertize (format "%s" mode) 'display
|
||||||
(mode-icons-get-icon-display
|
(mode-icons-get-icon-display
|
||||||
xpm-name 'xpm
|
xpm-name 'xpm face active)
|
||||||
(or face
|
|
||||||
(and (mode-icons--selected-window-active)
|
|
||||||
'mode-line)
|
|
||||||
'mode-line-inactive) active)
|
|
||||||
'mode-icons-p (list (nth 0 icon-spec) xpm-name 'xpm-bw)
|
'mode-icons-p (list (nth 0 icon-spec) xpm-name 'xpm-bw)
|
||||||
'face face)
|
'face face)
|
||||||
(with-temp-buffer
|
(with-temp-buffer
|
||||||
|
@ -1092,10 +1094,7 @@ ACTIVE if a flag for if the current window is active."
|
||||||
(make-string 1 (nth 1 icon-spec)))
|
(make-string 1 (nth 1 icon-spec)))
|
||||||
(nth 1 icon-spec)))
|
(nth 1 icon-spec)))
|
||||||
(put-text-property (point-min) (point-max)
|
(put-text-property (point-min) (point-max)
|
||||||
'face (or face
|
'face face)
|
||||||
(and (mode-icons--selected-window-active)
|
|
||||||
'mode-line)
|
|
||||||
'mode-line-inactive))
|
|
||||||
(put-text-property (point-min) (point-max)
|
(put-text-property (point-min) (point-max)
|
||||||
'mode-icons-p icon-spec)
|
'mode-icons-p icon-spec)
|
||||||
(buffer-string)))))
|
(buffer-string)))))
|
||||||
|
@ -1127,20 +1126,11 @@ ACTIVE is a flag to tell if the current window is active."
|
||||||
((and (stringp (nth 1 icon-spec)) (eq (nth 2 icon-spec) 'ext))
|
((and (stringp (nth 1 icon-spec)) (eq (nth 2 icon-spec) 'ext))
|
||||||
(propertize (format "%s" mode) 'display
|
(propertize (format "%s" mode) 'display
|
||||||
(mode-icons-get-icon-display
|
(mode-icons-get-icon-display
|
||||||
(concat "ext-" (nth 1 icon-spec)) 'xpm-bw
|
(concat "ext-" (nth 1 icon-spec)) 'xpm-bw face active)
|
||||||
(or face
|
|
||||||
(and (mode-icons--selected-window-active)
|
|
||||||
'mode-line)
|
|
||||||
'mode-line-inactive) active)
|
|
||||||
'mode-icons-p (list (nth 0 icon-spec)
|
'mode-icons-p (list (nth 0 icon-spec)
|
||||||
(concat "ext-" (nth 1 icon-spec))
|
(concat "ext-" (nth 1 icon-spec))
|
||||||
'xpm-bw)))
|
'xpm-bw)))
|
||||||
(t (setq tmp (mode-icons-get-icon-display
|
(t (setq tmp (mode-icons-get-icon-display (nth 1 icon-spec) (nth 2 icon-spec) face active))
|
||||||
(nth 1 icon-spec) (nth 2 icon-spec)
|
|
||||||
(or face
|
|
||||||
(and (mode-icons--selected-window-active)
|
|
||||||
'mode-line)
|
|
||||||
'mode-line-inactive) active))
|
|
||||||
(cond
|
(cond
|
||||||
((and (plist-get tmp :xpm-bw) (plist-get tmp :icon))
|
((and (plist-get tmp :xpm-bw) (plist-get tmp :icon))
|
||||||
(setq new-icon-spec (list (nth 0 icon-spec) (plist-get tmp :icon) 'xpm-bw)))
|
(setq new-icon-spec (list (nth 0 icon-spec) (plist-get tmp :icon) 'xpm-bw)))
|
||||||
|
@ -1195,6 +1185,7 @@ FACE represents the face used when the icon is a xpm-bw image.
|
||||||
ACTIVE represents if the window is active."
|
ACTIVE represents if the window is active."
|
||||||
(let* ((mode-name (format-mode-line mode))
|
(let* ((mode-name (format-mode-line mode))
|
||||||
(icon-spec (mode-icons-get-icon-spec mode-name))
|
(icon-spec (mode-icons-get-icon-spec mode-name))
|
||||||
|
(face (mode-icons-get-face face active))
|
||||||
ret)
|
ret)
|
||||||
(if icon-spec
|
(if icon-spec
|
||||||
(setq ret
|
(setq ret
|
||||||
|
@ -1219,7 +1210,7 @@ ACTIVE represents if the window is active."
|
||||||
(set (make-local-variable 'mode-icons-cached-mode-name)
|
(set (make-local-variable 'mode-icons-cached-mode-name)
|
||||||
mode-name)
|
mode-name)
|
||||||
(set (make-local-variable 'mode-icons--mode-name)
|
(set (make-local-variable 'mode-icons--mode-name)
|
||||||
(mode-icons-get-mode-icon mode))
|
(mode-icons-get-mode-icon mode nil t))
|
||||||
(when mode-icons-change-mode-name
|
(when mode-icons-change-mode-name
|
||||||
(setq mode-name mode-icons--mode-name))))
|
(setq mode-name mode-icons--mode-name))))
|
||||||
|
|
||||||
|
@ -1287,11 +1278,10 @@ When DONT-UPDATE is non-nil, don't call `force-mode-line-update'"
|
||||||
(defun mode-icons--generate-major-mode-item (&optional face)
|
(defun mode-icons--generate-major-mode-item (&optional face)
|
||||||
"Give rich strings needed for `major-mode' viewing.
|
"Give rich strings needed for `major-mode' viewing.
|
||||||
FACE is the face that the major mode item should be rendered in."
|
FACE is the face that the major mode item should be rendered in."
|
||||||
(let ((active (mode-icons--selected-window-active)))
|
(let* ((active (mode-icons--selected-window-active))
|
||||||
|
(face (mode-icons-get-face face active)))
|
||||||
(eval `(propertize ,(mode-icons--recolor-string (or mode-icons--mode-name mode-name) active face)
|
(eval `(propertize ,(mode-icons--recolor-string (or mode-icons--mode-name mode-name) active face)
|
||||||
'face ',(or face
|
'face ',face
|
||||||
(and active 'mode-line)
|
|
||||||
'mode-line-inactive)
|
|
||||||
,@mode-icons-major-mode-base-text-properties))))
|
,@mode-icons-major-mode-base-text-properties))))
|
||||||
|
|
||||||
;;; selected take from powerline
|
;;; selected take from powerline
|
||||||
|
@ -1348,11 +1338,11 @@ FACE is the face that the major mode item should be rendered in."
|
||||||
"Recolor `mode-icons' in STRING.
|
"Recolor `mode-icons' in STRING.
|
||||||
ACTIVE tells if the current window is active.
|
ACTIVE tells if the current window is active.
|
||||||
FACE is the face to recolor the icon to."
|
FACE is the face to recolor the icon to."
|
||||||
(let* ((active (and (not face) (or active (mode-icons--selected-window-active)))))
|
(let* ((face (mode-icons-get-face face active)))
|
||||||
(mapconcat
|
(mapconcat
|
||||||
(lambda(str)
|
(lambda(str)
|
||||||
(if (get-text-property 0 'display str)
|
(if (get-text-property 0 'display str)
|
||||||
(mode-icons--recolor-minor-mode-image str active)
|
(mode-icons--recolor-minor-mode-image str active face)
|
||||||
str))
|
str))
|
||||||
(mode-icons--property-substrings string 'mode-icons-p)
|
(mode-icons--property-substrings string 'mode-icons-p)
|
||||||
"")))
|
"")))
|
||||||
|
@ -1361,40 +1351,26 @@ FACE is the face to recolor the icon to."
|
||||||
"Recolor MODE image based on if the window is ACTIVE.
|
"Recolor MODE image based on if the window is ACTIVE.
|
||||||
Use FACE when specified."
|
Use FACE when specified."
|
||||||
(let ((icon-spec (get-text-property 0 'mode-icons-p mode))
|
(let ((icon-spec (get-text-property 0 'mode-icons-p mode))
|
||||||
(display)
|
(face (mode-icons-get-face face active)))
|
||||||
(face (or face)))
|
|
||||||
(cond
|
(cond
|
||||||
((and icon-spec (memq (nth 2 icon-spec) '(xpm xpm-bw)))
|
((and icon-spec (memq (nth 2 icon-spec) '(xpm xpm-bw)))
|
||||||
(propertize mode 'display (mode-icons-get-icon-display
|
(propertize mode 'display (mode-icons-get-icon-display
|
||||||
(nth 1 icon-spec) (nth 2 icon-spec)
|
(nth 1 icon-spec) (nth 2 icon-spec) face active)
|
||||||
(or face
|
'face face
|
||||||
(and active 'mode-line)
|
|
||||||
'mode-line-inactive) active)
|
|
||||||
'face (or face
|
|
||||||
(and active 'mode-line)
|
|
||||||
'mode-line-inactive)
|
|
||||||
'mode-icons-p icon-spec))
|
'mode-icons-p icon-spec))
|
||||||
((and icon-spec (memq (nth 2 icon-spec) '(emoji))
|
((and icon-spec (memq (nth 2 icon-spec) '(emoji))
|
||||||
(file-exists-p (mode-icons--get-emoji-xpm-file icon-spec)))
|
(file-exists-p (mode-icons--get-emoji-xpm-file icon-spec)))
|
||||||
(propertize mode 'display (mode-icons-get-icon-display
|
(propertize mode 'display (mode-icons-get-icon-display
|
||||||
(mode-icons--get-emoji-xpm-file icon-spec t)
|
(mode-icons--get-emoji-xpm-file icon-spec t)
|
||||||
'xpm
|
'xpm face active) 'face face
|
||||||
(or face
|
|
||||||
(and active 'mode-line)
|
|
||||||
'mode-line-inactive) active)
|
|
||||||
'face (or face
|
|
||||||
(and active 'mode-line)
|
|
||||||
'mode-line-inactive)
|
|
||||||
'mode-icons-p icon-spec))
|
'mode-icons-p icon-spec))
|
||||||
(t (propertize mode
|
(t (propertize mode 'face face)))))
|
||||||
'face (or face
|
|
||||||
(and active 'mode-line)
|
|
||||||
'mode-line-inactive))))))
|
|
||||||
|
|
||||||
(defun mode-icons--generate-minor-mode-list (&optional face)
|
(defun mode-icons--generate-minor-mode-list (&optional face)
|
||||||
"Extracts all rich strings necessary for the minor mode list.
|
"Extracts all rich strings necessary for the minor mode list.
|
||||||
When FACE is non-nil, use FACE to render the `minor-mode-alist'."
|
When FACE is non-nil, use FACE to render the `minor-mode-alist'."
|
||||||
(let ((active (mode-icons--selected-window-active)))
|
(let* ((active (mode-icons--selected-window-active))
|
||||||
|
(face (mode-icons-get-face face active)))
|
||||||
(delete " " (delete "" (mapcar (lambda(mode)
|
(delete " " (delete "" (mapcar (lambda(mode)
|
||||||
(concat " " (eval `(propertize ,(mode-icons--recolor-minor-mode-image mode active face)
|
(concat " " (eval `(propertize ,(mode-icons--recolor-minor-mode-image mode active face)
|
||||||
,@mode-icons-minor-mode-base-text-properties))))
|
,@mode-icons-minor-mode-base-text-properties))))
|
||||||
|
@ -1403,7 +1379,8 @@ When FACE is non-nil, use FACE to render the `minor-mode-alist'."
|
||||||
(defun mode-icons--generate-narrow (&optional face)
|
(defun mode-icons--generate-narrow (&optional face)
|
||||||
"Extracts all rich strings necessary for narrow indicator.
|
"Extracts all rich strings necessary for narrow indicator.
|
||||||
When FACE is non-nil, use FACE to render the narrow indicator."
|
When FACE is non-nil, use FACE to render the narrow indicator."
|
||||||
(let ((active (mode-icons--selected-window-active))
|
(let* ((active (mode-icons--selected-window-active))
|
||||||
|
(face (mode-icons-get-face active face))
|
||||||
icon-spec)
|
icon-spec)
|
||||||
(delete " " (delete "" (mapcar (lambda(mode)
|
(delete " " (delete "" (mapcar (lambda(mode)
|
||||||
(concat " " (eval `(propertize
|
(concat " " (eval `(propertize
|
||||||
|
|
Loading…
Reference in a new issue