[Feature] Display color icon for major mode.

This commit is contained in:
Vincent Zhang 2018-12-25 00:00:02 +08:00
parent b5266e7093
commit 4f694f3f74
2 changed files with 54 additions and 44 deletions

View file

@ -133,9 +133,12 @@ Strongly recommend to use
;; The icons may not be showed correctly on Windows. Disable to make it work. ;; The icons may not be showed correctly on Windows. Disable to make it work.
(setq doom-modeline-icon t) (setq doom-modeline-icon t)
;; Whether show the icon for major mode. It should respect `doom-modeline-icon'. ;; Whether show the icon for major mode. It respects `doom-modeline-icon'.
(setq doom-modeline-major-mode-icon t) (setq doom-modeline-major-mode-icon t)
;; Display color icons for `major-mode'. It respects `all-the-icons-color-icons'.
(setq doom-modeline-major-mode-color-icon t)
;; Whether display minor modes or not. Non-nil to display in mode-line. ;; Whether display minor modes or not. Non-nil to display in mode-line.
(setq doom-modeline-minor-modes nil) (setq doom-modeline-minor-modes nil)

View file

@ -116,7 +116,10 @@ Non-nil to show the icons in mode-line.
The icons may not be showed correctly in terminal and on Windows.") The icons may not be showed correctly in terminal and on Windows.")
(defvar doom-modeline-major-mode-icon t (defvar doom-modeline-major-mode-icon t
"Whether show the icon for major mode. It should respect `doom-modeline-icon'.") "Whether show the icon for major mode. It respects `doom-modeline-icon'.")
(defvar doom-modeline-major-mode-color-icon t
"Display color icons for `major-mode'. It respects `all-the-icons-color-icons'.")
(defvar doom-modeline-minor-modes nil (defvar doom-modeline-minor-modes nil
"Whether display minor modes or not. Non-nil to display in mode-line.") "Whether display minor modes or not. Non-nil to display in mode-line.")
@ -741,14 +744,11 @@ buffer where knowing the current project directory is important."
(defun doom-modeline-update-buffer-file-icon (&rest _) (defun doom-modeline-update-buffer-file-icon (&rest _)
"Update file icon in mode-line." "Update file icon in mode-line."
(setq doom-modeline--buffer-file-icon (setq doom-modeline--buffer-file-icon
(let ((icon (doom-modeline-icon-for-mode major-mode))) (let ((icon (doom-modeline-icon-for-mode major-mode :height 0.92)))
(unless (symbolp icon) (unless (symbolp icon)
(concat (propertize icon
(propertize icon 'help-echo (format "Major-mode: `%s'" major-mode)
'help-echo (format "Major-mode: `%s'" major-mode) 'display '(raise -0.125))))))
'display '(raise -0.125)
'face `(:height 1.1 :family ,(all-the-icons-icon-family-for-mode major-mode) :inherit))
doom-modeline-vspc)))))
(add-hook 'find-file-hook 'doom-modeline-update-buffer-file-icon) (add-hook 'find-file-hook 'doom-modeline-update-buffer-file-icon)
(add-hook 'after-revert-hook 'doom-modeline-update-buffer-file-icon) (add-hook 'after-revert-hook 'doom-modeline-update-buffer-file-icon)
(add-hook 'after-change-major-mode-hook 'doom-modeline-update-buffer-file-icon) (add-hook 'after-change-major-mode-hook 'doom-modeline-update-buffer-file-icon)
@ -761,35 +761,30 @@ Uses `all-the-icons-material' to fetch the icon."
(doom-modeline-icon-material (doom-modeline-icon-material
icon icon
:face (if (doom-modeline--active) face) :face (if (doom-modeline--active) face)
:height (or height (if (eq system-type 'darwin) 1.0 0.96)) :height (or height 1.0)
:v-adjust (or voffset (if (eq system-type 'darwin) -0.225 -0.205))))) :v-adjust (or voffset -0.215))))
(defvar-local doom-modeline--buffer-file-state-icon nil) (defvar-local doom-modeline--buffer-file-state-icon nil)
(defun doom-modeline-update-buffer-file-state-icon (&rest _) (defun doom-modeline-update-buffer-file-state-icon (&rest _)
"Update the buffer or file state in mode-line." "Update the buffer or file state in mode-line."
(setq doom-modeline--buffer-file-state-icon (setq doom-modeline--buffer-file-state-icon
(cond (buffer-read-only (cond (buffer-read-only
(concat (doom-modeline-buffer-file-state-icon (doom-modeline-buffer-file-state-icon
"lock" "lock"
'doom-modeline-warning) 'doom-modeline-warning))
doom-modeline-vspc))
((buffer-modified-p) ((buffer-modified-p)
(concat (doom-modeline-buffer-file-state-icon (doom-modeline-buffer-file-state-icon
"save" "save"
'doom-modeline-buffer-modified) 'doom-modeline-buffer-modified))
doom-modeline-vspc))
((and buffer-file-name ((and buffer-file-name
(not (file-exists-p buffer-file-name))) (not (file-exists-p buffer-file-name)))
(concat (doom-modeline-buffer-file-state-icon (doom-modeline-buffer-file-state-icon
"do_not_disturb_alt" "do_not_disturb_alt"
'doom-modeline-urgent) 'doom-modeline-urgent))
doom-modeline-vspc))
((buffer-narrowed-p) ((buffer-narrowed-p)
(concat (doom-modeline-buffer-file-state-icon (doom-modeline-buffer-file-state-icon
"unfold_less" "unfold_less"
'doom-modeline-warning 'doom-modeline-warning)))))
1.1)
doom-modeline-vspc)))))
(add-hook 'find-file-hook 'doom-modeline-update-buffer-file-state-icon) (add-hook 'find-file-hook 'doom-modeline-update-buffer-file-state-icon)
(add-hook 'after-save-hook 'doom-modeline-update-buffer-file-state-icon) (add-hook 'after-save-hook 'doom-modeline-update-buffer-file-state-icon)
(add-hook 'after-revert-hook 'doom-modeline-update-buffer-file-state-icon) (add-hook 'after-revert-hook 'doom-modeline-update-buffer-file-state-icon)
@ -835,24 +830,36 @@ mouse-1: Previous buffer\nmouse-3: Next buffer"
(doom-modeline-def-segment buffer-info (doom-modeline-def-segment buffer-info
"Combined information about the current buffer, including the current working "Combined information about the current buffer, including the current working
directory, the file name, and its state (modified, read-only or non-existent)." directory, the file name, and its state (modified, read-only or non-existent)."
(concat (let ((active (doom-modeline--active)))
;; major mode icon (concat
(if (and doom-modeline-icon doom-modeline-major-mode-icon) ;; major mode icon
(or doom-modeline--buffer-file-icon (when (and doom-modeline-icon doom-modeline-major-mode-icon)
(doom-modeline-update-buffer-file-icon))) (when-let ((icon (or doom-modeline--buffer-file-icon
(doom-modeline-update-buffer-file-icon))))
(concat
(if (and active doom-modeline-major-mode-color-icon)
icon
(propertize icon
'face `(:height 1.1 :family ,(all-the-icons-icon-family icon) :inherit)))
doom-modeline-vspc)))
;; state icon ;; state icon
(if (doom-modeline--active) (when doom-modeline-icon
(or doom-modeline--buffer-file-state-icon (when-let ((icon (or doom-modeline--buffer-file-state-icon
(doom-modeline-update-buffer-file-state-icon))) (doom-modeline-update-buffer-file-state-icon))))
(concat
(if active
icon
(propertize icon
'face `(:height 1.2 :family ,(all-the-icons-icon-family icon) :inherit)))
doom-modeline-vspc)))
;; buffer file name ;; buffer file name
(if (doom-modeline--active) (let ((name (or doom-modeline--buffer-file-name
(or doom-modeline--buffer-file-name (doom-modeline-update-buffer-file-name))))
(doom-modeline-update-buffer-file-name)) (if active
(propertize name
(or doom-modeline--buffer-file-name "%b") (propertize name 'face 'mode-line-inactive))))))
'face 'mode-line-inactive))))
(doom-modeline-def-segment buffer-info-simple (doom-modeline-def-segment buffer-info-simple
"Display only the current buffer's name, but with fontification." "Display only the current buffer's name, but with fontification."