mirror of
https://github.com/ryuslash/mode-icons.git
synced 2024-11-21 17:40:30 +01:00
Allow mode-icons fonts to work in windows
This commit is contained in:
parent
72736b5a92
commit
57acfed666
1 changed files with 54 additions and 21 deletions
|
@ -43,9 +43,15 @@ ICON should be a file name with extension. The result is the
|
||||||
absolute path to ICON."
|
absolute path to ICON."
|
||||||
(concat mode-icons--directory "/icons/" icon))
|
(concat mode-icons--directory "/icons/" icon))
|
||||||
|
|
||||||
(defvar mode-icons-octicons-font
|
(defmacro mode-icons-define-font (font)
|
||||||
(find-font (font-spec :name "github-octicons")))
|
"Define FONT for `mode-icons'."
|
||||||
|
`(progn
|
||||||
|
(defvar ,(intern (format "mode-icons-font-spec-%s" font))
|
||||||
|
(font-spec :name ,(format "%s" font)))
|
||||||
|
(defvar ,(intern (format "mode-icons-font-%s" font))
|
||||||
|
(find-font ,(intern (format "mode-icons-font-spec-%s" font))))))
|
||||||
|
|
||||||
|
(mode-icons-define-font "github-octicons")
|
||||||
|
|
||||||
(defcustom mode-icons
|
(defcustom mode-icons
|
||||||
`(("CSS" "css" xpm)
|
`(("CSS" "css" xpm)
|
||||||
|
@ -78,7 +84,7 @@ absolute path to ICON."
|
||||||
("YASnippet" "yas" xpm)
|
("YASnippet" "yas" xpm)
|
||||||
(" yas" "yas" xpm)
|
(" yas" "yas" xpm)
|
||||||
(" hs" "hs" xpm)
|
(" hs" "hs" xpm)
|
||||||
("Markdown" ,(make-string 1 #xf0c9) octicons)
|
("Markdown" ,(make-string 1 #xf0c9) github-octicons)
|
||||||
;; Diminished modes
|
;; Diminished modes
|
||||||
("\\(ElDoc\\|Anzu\\|SP\\|Guide\\|PgLn\\|Golden\\|Undo-Tree\\|Ergo.*\\|,\\|Isearch\\)" nil nil)
|
("\\(ElDoc\\|Anzu\\|SP\\|Guide\\|PgLn\\|Golden\\|Undo-Tree\\|Ergo.*\\|,\\|Isearch\\)" nil nil)
|
||||||
)
|
)
|
||||||
|
@ -94,7 +100,7 @@ without the extension. And the third being the type of icon."
|
||||||
(const :tag "Suppress" nil))
|
(const :tag "Suppress" nil))
|
||||||
(choice
|
(choice
|
||||||
(const :tag "text" nil)
|
(const :tag "text" nil)
|
||||||
(const :tag "Octicons" octicons)
|
(const :tag "Octicons" github-octicons)
|
||||||
(const :tag "png" png)
|
(const :tag "png" png)
|
||||||
(const :tag "gif" gif)
|
(const :tag "gif" gif)
|
||||||
(const :tag "jpeg" jpeg)
|
(const :tag "jpeg" jpeg)
|
||||||
|
@ -136,12 +142,37 @@ the icon."
|
||||||
(member 'sml/pos-id-separator mode-line-format)
|
(member 'sml/pos-id-separator mode-line-format)
|
||||||
(string-match-p "powerline" (prin1-to-string mode-line-format)))))
|
(string-match-p "powerline" (prin1-to-string mode-line-format)))))
|
||||||
|
|
||||||
|
(defvar mode-icons-font-register-alist nil
|
||||||
|
"Alist of characters supported.")
|
||||||
|
|
||||||
|
(defun mode-icons-supported-font-p (char font &optional dont-register)
|
||||||
|
"Determine if the CHAR is supported in FONT.
|
||||||
|
When DONT-REGISTER is non-nil, don't register the font.
|
||||||
|
Otherwise, under windows 32, emacs register the font for use in
|
||||||
|
the mode-line."
|
||||||
|
(when (and (or (integerp char)
|
||||||
|
(and (stringp char) (= 1 (length char))))
|
||||||
|
(boundp (intern (format "mode-icons-font-spec-%s" font)))
|
||||||
|
(symbol-value (intern (format "mode-icons-font-spec-%s" font))))
|
||||||
|
(if (not (eq system-type 'windows-nt)) 'direct-font
|
||||||
|
(let* ((char (or (and (integerp char) char)
|
||||||
|
(and (stringp char) (= 1 (length char))
|
||||||
|
(aref (vconcat char) 0))))
|
||||||
|
(found-char-p (assoc char mode-icons-font-register-alist))
|
||||||
|
(char-font-p (and found-char-p (eq (cdr found-char-p) font))))
|
||||||
|
(cond
|
||||||
|
(char-font-p t)
|
||||||
|
(found-char-p t)
|
||||||
|
(t ;; not yet registered.
|
||||||
|
(set-fontset-font t (cons char char) (symbol-value (intern (format "mode-icons-font-spec-%s" font))))
|
||||||
|
(push (cons char font) mode-icons-font-register-alist)
|
||||||
|
t))))))
|
||||||
|
|
||||||
(defun mode-icons-supported-p (icon-spec)
|
(defun mode-icons-supported-p (icon-spec)
|
||||||
"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) 'octicons) mode-icons-octicons-font (not (eq system-type 'windows-nt))
|
(mode-icons-supported-font-p (nth 1 icon-spec) (nth 2 icon-spec) t)
|
||||||
(stringp (nth 1 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 (image-type-available-p (nth 2 icon-spec)))))
|
(and (image-type-available-p (nth 2 icon-spec)))))
|
||||||
|
|
||||||
|
@ -150,21 +181,23 @@ the icon."
|
||||||
|
|
||||||
MODE should be a string, the name of the mode to propertize.
|
MODE should be a string, the name of the mode to propertize.
|
||||||
ICON-SPEC should be a specification from `mode-icons'."
|
ICON-SPEC should be a specification from `mode-icons'."
|
||||||
(cond
|
(let (tmp)
|
||||||
((get-text-property 0 'mode-icons-p mode)
|
(cond
|
||||||
mode)
|
((get-text-property 0 'mode-icons-p mode)
|
||||||
((not (nth 1 icon-spec))
|
mode)
|
||||||
"")
|
((not (nth 1 icon-spec))
|
||||||
((and mode-icons-octicons-font (not (eq system-type 'windows-nt))
|
"")
|
||||||
(stringp (nth 1 icon-spec)) (eq (nth 2 icon-spec) 'octicons))
|
((setq tmp (mode-icons-supported-font-p (nth 1 icon-spec) (nth 2 icon-spec)))
|
||||||
(propertize mode 'display (nth 1 icon-spec)
|
(if (eq 'direct-font tmp)
|
||||||
'font 'mode-icons-octicons-font
|
(propertize mode 'display (nth 1 icon-spec)
|
||||||
'mode-icons-p t))
|
'font (symbol-value (intern (format "mode-icons-font-%s" font)))
|
||||||
((and (stringp (nth 1 icon-spec)) (not (nth 2 icon-spec)))
|
'mode-icons-p t)
|
||||||
(propertize mode 'display (mode-icons-get-icon-display (nth 1 icon-spec) (nth 2 icon-spec))
|
(propertize mode 'display (nth 1 icon-spec) 'mode-icons-p t)))
|
||||||
'mode-icons-p t))
|
((and (stringp (nth 1 icon-spec)) (not (nth 2 icon-spec)))
|
||||||
(t (propertize mode 'display (mode-icons-get-icon-display (nth 1 icon-spec) (nth 2 icon-spec))
|
(propertize mode 'display (mode-icons-get-icon-display (nth 1 icon-spec) (nth 2 icon-spec))
|
||||||
'mode-icons-p t))))
|
'mode-icons-p t))
|
||||||
|
(t (propertize mode 'display (mode-icons-get-icon-display (nth 1 icon-spec) (nth 2 icon-spec))
|
||||||
|
'mode-icons-p t)))))
|
||||||
|
|
||||||
(defun mode-icons-get-icon-spec (mode)
|
(defun mode-icons-get-icon-spec (mode)
|
||||||
"Get icon spec for MODE based on regular expression."
|
"Get icon spec for MODE based on regular expression."
|
||||||
|
|
Loading…
Reference in a new issue