mirror of
https://github.com/ryuslash/mode-icons.git
synced 2024-11-24 02:20:29 +01:00
Add emoji support. (Undo-Tree = 🌿)
Allow undo-tree to have the 🌿 emoji Addresses Issue #20
This commit is contained in:
parent
fd94d1a276
commit
7c1de479b3
2 changed files with 51 additions and 6 deletions
|
@ -42,6 +42,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
||||||
=smart-mode-line=.
|
=smart-mode-line=.
|
||||||
- Allow desaturating and matching the mode-line face colors for xpm
|
- Allow desaturating and matching the mode-line face colors for xpm
|
||||||
images.
|
images.
|
||||||
|
- Allow emojis to be used as mode-icons
|
||||||
|
|
||||||
### Removed
|
### Removed
|
||||||
|
|
||||||
|
|
|
@ -68,6 +68,7 @@
|
||||||
|
|
||||||
(require 'cl-lib)
|
(require 'cl-lib)
|
||||||
(require 'color)
|
(require 'color)
|
||||||
|
(require 'emojify nil t)
|
||||||
|
|
||||||
(defgroup mode-icons nil
|
(defgroup mode-icons nil
|
||||||
"Provide icons for major modes."
|
"Provide icons for major modes."
|
||||||
|
@ -235,9 +236,9 @@ This was stole/modified from `c-save-buffer-state'"
|
||||||
("\\`Conf" #xf1de FontAwesome)
|
("\\`Conf" #xf1de FontAwesome)
|
||||||
("\\`Fundamental\\'" #xf016 FontAwesome)
|
("\\`Fundamental\\'" #xf016 FontAwesome)
|
||||||
("\\`Javascript-IDE\\'" "js" xpm)
|
("\\`Javascript-IDE\\'" "js" xpm)
|
||||||
|
("\\` Undo-Tree\\'" ":herb:" emoji)
|
||||||
;; Diminished modes
|
;; Diminished modes
|
||||||
("\\` \\(?:ElDoc\\|Anzu\\|SP\\|Guide\\|PgLn\\|Undo-Tree\\|Ergo.*\\|,\\|Isearch\\|Ind\\)\\'" nil nil)
|
("\\` \\(?:ElDoc\\|Anzu\\|SP\\|Guide\\|PgLn\\|Undo-Tree\\|Ergo.*\\|,\\|Isearch\\|Ind\\)\\'" nil nil))
|
||||||
)
|
|
||||||
"Icons for major and minor modes.
|
"Icons for major and minor modes.
|
||||||
|
|
||||||
Each specificatioun is a list with the first element being the
|
Each specificatioun is a list with the first element being the
|
||||||
|
@ -254,7 +255,8 @@ without the extension. And the third being the type of icon."
|
||||||
(const :tag "Locked By Someone Else" steal)
|
(const :tag "Locked By Someone Else" steal)
|
||||||
(const :tag "Apple" apple)
|
(const :tag "Apple" apple)
|
||||||
(const :tag "Windows" win)
|
(const :tag "Windows" win)
|
||||||
(const :tag "Unix" unix))
|
(const :tag "Unix" unix)
|
||||||
|
(function :tag "Enriched minor mode"))
|
||||||
(choice
|
(choice
|
||||||
(string :tag "Icon Name")
|
(string :tag "Icon Name")
|
||||||
(integer :tag "Font Glyph Code")
|
(integer :tag "Font Glyph Code")
|
||||||
|
@ -271,7 +273,8 @@ without the extension. And the third being the type of icon."
|
||||||
(const :tag "jpg" jpg)
|
(const :tag "jpg" jpg)
|
||||||
(const :tag "xbm" xbm)
|
(const :tag "xbm" xbm)
|
||||||
(const :tag "xpm" xpm)
|
(const :tag "xpm" xpm)
|
||||||
(const :tag "Black and White xpm that changes color to match the mode-line face" xpm-bw))))
|
(const :tag "Black and White xpm that changes color to match the mode-line face" xpm-bw)
|
||||||
|
(const :tag "Emoji" emoji))))
|
||||||
:group 'mode-icons)
|
:group 'mode-icons)
|
||||||
|
|
||||||
(defvar mode-icons-get-xpm-string (make-hash-table :test 'equal))
|
(defvar mode-icons-get-xpm-string (make-hash-table :test 'equal))
|
||||||
|
@ -592,11 +595,17 @@ everywhere else."
|
||||||
"Determine if ICON-SPEC is suppored on your system."
|
"Determine if ICON-SPEC is suppored on your system."
|
||||||
(or
|
(or
|
||||||
(and (or (eq (nth 2 icon-spec) nil) (eq (nth 1 icon-spec) nil)) t)
|
(and (or (eq (nth 2 icon-spec) nil) (eq (nth 1 icon-spec) nil)) t)
|
||||||
|
(and (eq (nth 2 icon-spec) 'emoji) (image-type-available-p 'png)
|
||||||
|
(featurep 'emojify))
|
||||||
(mode-icons-supported-font-p (nth 1 icon-spec) (nth 2 icon-spec))
|
(mode-icons-supported-font-p (nth 1 icon-spec) (nth 2 icon-spec))
|
||||||
(and (eq (nth 2 icon-spec) 'jpg) (image-type-available-p 'jpeg))
|
(and (eq (nth 2 icon-spec) 'jpg) (image-type-available-p 'jpeg))
|
||||||
(and (eq (nth 2 icon-spec) 'xpm-bw) (image-type-available-p 'xpm))
|
(and (eq (nth 2 icon-spec) 'xpm-bw) (image-type-available-p 'xpm))
|
||||||
(and (image-type-available-p (nth 2 icon-spec)))))
|
(and (image-type-available-p (nth 2 icon-spec)))))
|
||||||
|
|
||||||
|
(defvar emojify-image-dir)
|
||||||
|
|
||||||
|
(defvar emojify-emojis)
|
||||||
|
|
||||||
(defun mode-icons-propertize-mode (mode icon-spec &optional face)
|
(defun mode-icons-propertize-mode (mode icon-spec &optional face)
|
||||||
"Propertize MODE with ICON-SPEC.
|
"Propertize MODE with ICON-SPEC.
|
||||||
|
|
||||||
|
@ -626,6 +635,30 @@ FACE is the face to match when a xpm-bw image is used."
|
||||||
(nth 1 icon-spec)))
|
(nth 1 icon-spec)))
|
||||||
(put-text-property (point-min) (point-max) 'mode-icons-p icon-spec)
|
(put-text-property (point-min) (point-max) 'mode-icons-p icon-spec)
|
||||||
(buffer-string)))
|
(buffer-string)))
|
||||||
|
((and (stringp (nth 1 icon-spec)) (eq (nth 2 icon-spec) 'emoji))
|
||||||
|
(unless emojify-emojis
|
||||||
|
(emojify-set-emoji-data))
|
||||||
|
(let* ((emoji (ht-get emojify-emojis (nth 1 icon-spec)))
|
||||||
|
(image-file (expand-file-name (ht-get emoji "image") emojify-image-dir))
|
||||||
|
(image-type (intern (upcase (file-name-extension image-file)))))
|
||||||
|
(if (file-exists-p image-file)
|
||||||
|
(propertize (format "%s" mode)
|
||||||
|
'display
|
||||||
|
(create-image image-file
|
||||||
|
;; use imagemagick if available and supports PNG images
|
||||||
|
;; (allows resizing images)
|
||||||
|
(when (and (fboundp 'imagemagick-types)
|
||||||
|
(memq image-type (imagemagick-types)))
|
||||||
|
'imagemagick)
|
||||||
|
nil
|
||||||
|
:ascent 'center
|
||||||
|
:heuristic-mask t
|
||||||
|
;; :background (emojify--get-image-background beg end)
|
||||||
|
;; no-op if imagemagick is not available
|
||||||
|
:height (emojify-default-font-height))
|
||||||
|
'mode-icons-p icon-spec)
|
||||||
|
(propertize (format "%s" mode)
|
||||||
|
'mode-icons-p icon-spec))))
|
||||||
(t (propertize (format "%s" mode) 'display
|
(t (propertize (format "%s" mode) 'display
|
||||||
(mode-icons-get-icon-display (nth 1 icon-spec) (nth 2 icon-spec)
|
(mode-icons-get-icon-display (nth 1 icon-spec) (nth 2 icon-spec)
|
||||||
(or face
|
(or face
|
||||||
|
@ -827,7 +860,9 @@ When DONT-UPDATE is non-nil, don't call `force-mode-line-update'"
|
||||||
out))
|
out))
|
||||||
|
|
||||||
(defun mode-icons--recolor-string (string &optional active face)
|
(defun mode-icons--recolor-string (string &optional active face)
|
||||||
"Recolor `mode-icons' in STRING."
|
"Recolor `mode-icons' in STRING.
|
||||||
|
ACTIVE tells if the current window is active.
|
||||||
|
FACE is the face to recolor the icon to."
|
||||||
(let* ((active (and (not face) (or active (mode-icons--selected-window-active)))))
|
(let* ((active (and (not face) (or active (mode-icons--selected-window-active)))))
|
||||||
(mapconcat
|
(mapconcat
|
||||||
(lambda(str)
|
(lambda(str)
|
||||||
|
@ -839,7 +874,7 @@ When DONT-UPDATE is non-nil, don't call `force-mode-line-update'"
|
||||||
|
|
||||||
(defun mode-icons--recolor-minor-mode-image (mode active &optional face)
|
(defun mode-icons--recolor-minor-mode-image (mode active &optional face)
|
||||||
"Recolor MODE image based on if the window is ACTIVE.
|
"Recolor MODE image based on if the window is ACTIVE.
|
||||||
Use FAEC 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)))
|
||||||
(cond
|
(cond
|
||||||
((and icon-spec (memq (nth 2 icon-spec) '(xpm xpm-bw)))
|
((and icon-spec (memq (nth 2 icon-spec) '(xpm xpm-bw)))
|
||||||
|
@ -1112,6 +1147,11 @@ When ENABLE is non-nil, enable the changes to the mode line."
|
||||||
(mode-icons-major-mode-icons-undo)
|
(mode-icons-major-mode-icons-undo)
|
||||||
(mode-icons-fix)))
|
(mode-icons-fix)))
|
||||||
|
|
||||||
|
(defun mode-icons-reset-hash ()
|
||||||
|
"Reset `mode-icons-get-icon-spec' and `mode-icons-get-icon-display'."
|
||||||
|
(setq mode-icons-get-icon-spec (make-hash-table :test 'equal)
|
||||||
|
mode-icons-get-icon-display (make-hash-table :test 'equal)))
|
||||||
|
|
||||||
(defun mode-icons-reset-now ()
|
(defun mode-icons-reset-now ()
|
||||||
"Reset mode-icons icons."
|
"Reset mode-icons icons."
|
||||||
(interactive)
|
(interactive)
|
||||||
|
@ -1144,6 +1184,10 @@ PAD is the padding around the minor modes."
|
||||||
(mode-icons--real-powerline-minor-modes face pad)))
|
(mode-icons--real-powerline-minor-modes face pad)))
|
||||||
(fset 'powerline-minor-modes (symbol-function #'mode-icons--powerline-minor-modes))))
|
(fset 'powerline-minor-modes (symbol-function #'mode-icons--powerline-minor-modes))))
|
||||||
|
|
||||||
|
(eval-after-load 'emojify
|
||||||
|
'(progn
|
||||||
|
(mode-icons-reset-hash)))
|
||||||
|
|
||||||
(provide 'mode-icons)
|
(provide 'mode-icons)
|
||||||
;;; mode-icons.el ends here
|
;;; mode-icons.el ends here
|
||||||
;; Local Variables:
|
;; Local Variables:
|
||||||
|
|
Loading…
Reference in a new issue