From 4f694f3f74d40e61abbf621a412aa613615da754 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Tue, 25 Dec 2018 00:00:02 +0800 Subject: [PATCH] [Feature] Display color icon for major mode. --- README.md | 5 ++- doom-modeline.el | 93 ++++++++++++++++++++++++++---------------------- 2 files changed, 54 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index 4140dbf..9aba07d 100644 --- a/README.md +++ b/README.md @@ -133,9 +133,12 @@ Strongly recommend to use ;; The icons may not be showed correctly on Windows. Disable to make it work. (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) +;; 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. (setq doom-modeline-minor-modes nil) diff --git a/doom-modeline.el b/doom-modeline.el index 0731946..3a1a06c 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -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.") (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 "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 _) "Update file icon in mode-line." (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) - (concat - (propertize icon - 'help-echo (format "Major-mode: `%s'" major-mode) - 'display '(raise -0.125) - 'face `(:height 1.1 :family ,(all-the-icons-icon-family-for-mode major-mode) :inherit)) - doom-modeline-vspc))))) + (propertize icon + 'help-echo (format "Major-mode: `%s'" major-mode) + 'display '(raise -0.125)))))) (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-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 icon :face (if (doom-modeline--active) face) - :height (or height (if (eq system-type 'darwin) 1.0 0.96)) - :v-adjust (or voffset (if (eq system-type 'darwin) -0.225 -0.205))))) + :height (or height 1.0) + :v-adjust (or voffset -0.215)))) (defvar-local doom-modeline--buffer-file-state-icon nil) (defun doom-modeline-update-buffer-file-state-icon (&rest _) "Update the buffer or file state in mode-line." (setq doom-modeline--buffer-file-state-icon (cond (buffer-read-only - (concat (doom-modeline-buffer-file-state-icon - "lock" - 'doom-modeline-warning) - doom-modeline-vspc)) + (doom-modeline-buffer-file-state-icon + "lock" + 'doom-modeline-warning)) ((buffer-modified-p) - (concat (doom-modeline-buffer-file-state-icon - "save" - 'doom-modeline-buffer-modified) - doom-modeline-vspc)) + (doom-modeline-buffer-file-state-icon + "save" + 'doom-modeline-buffer-modified)) ((and buffer-file-name (not (file-exists-p buffer-file-name))) - (concat (doom-modeline-buffer-file-state-icon - "do_not_disturb_alt" - 'doom-modeline-urgent) - doom-modeline-vspc)) + (doom-modeline-buffer-file-state-icon + "do_not_disturb_alt" + 'doom-modeline-urgent)) ((buffer-narrowed-p) - (concat (doom-modeline-buffer-file-state-icon - "unfold_less" - 'doom-modeline-warning - 1.1) - doom-modeline-vspc))))) + (doom-modeline-buffer-file-state-icon + "unfold_less" + 'doom-modeline-warning))))) (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-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 "Combined information about the current buffer, including the current working directory, the file name, and its state (modified, read-only or non-existent)." - (concat - ;; major mode icon - (if (and doom-modeline-icon doom-modeline-major-mode-icon) - (or doom-modeline--buffer-file-icon - (doom-modeline-update-buffer-file-icon))) + (let ((active (doom-modeline--active))) + (concat + ;; major mode icon + (when (and doom-modeline-icon doom-modeline-major-mode-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 - (if (doom-modeline--active) - (or doom-modeline--buffer-file-state-icon - (doom-modeline-update-buffer-file-state-icon))) + ;; state icon + (when doom-modeline-icon + (when-let ((icon (or doom-modeline--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 - (if (doom-modeline--active) - (or doom-modeline--buffer-file-name - (doom-modeline-update-buffer-file-name)) - (propertize - (or doom-modeline--buffer-file-name "%b") - 'face 'mode-line-inactive)))) + ;; buffer file name + (let ((name (or doom-modeline--buffer-file-name + (doom-modeline-update-buffer-file-name)))) + (if active + name + (propertize name 'face 'mode-line-inactive)))))) (doom-modeline-def-segment buffer-info-simple "Display only the current buffer's name, but with fontification."