[Feature] Add options: doom-modeline-buffer-state-icon and doom-modeline-buffer-modification-icon.

Close #158.
This commit is contained in:
Vincent Zhang 2019-04-20 16:39:40 +08:00
parent b464b69d26
commit 108fd78261
3 changed files with 42 additions and 29 deletions

View file

@ -148,16 +148,24 @@ Strongly recommend to use
;; Please refer to https://github.com/bbatsov/projectile/issues/657. ;; Please refer to https://github.com/bbatsov/projectile/issues/657.
(setq doom-modeline-buffer-file-name-style 'truncate-upto-project) (setq doom-modeline-buffer-file-name-style 'truncate-upto-project)
;; Whether display icons or not (if nil nothing will be showed). ;; Whether display icons in mode-line or not.
(setq doom-modeline-icon t) (setq doom-modeline-icon t)
;; Whether display the icon for major mode. It respects `doom-modeline-icon'. ;; Whether display 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'. ;; Whether display color icons for `major-mode'. It respects
;; `doom-modeline-icon' and `all-the-icons-color-icons'.
(setq doom-modeline-major-mode-color-icon t) (setq doom-modeline-major-mode-color-icon t)
;; Whether display minor modes or not. Non-nil to display in mode-line. ;; Whether display icons for buffer states. It respects `doom-modeline-icon'.
(setq doom-modeline-buffer-state-icon t)
;; Whether display buffer modification icon. It respects `doom-modeline-icon'
;; and `doom-modeline-buffer-state-icon'.
(setq doom-modeline-buffer-modification-icon t)
;; Whether display minor modes in mode-line or not.
(setq doom-modeline-minor-modes nil) (setq doom-modeline-minor-modes nil)
;; If non-nil, a word count will be added to the selection-info modeline segment. ;; If non-nil, a word count will be added to the selection-info modeline segment.

View file

@ -117,19 +117,22 @@ Given ~/Projects/FOSS/emacs/lisp/comint.el
buffer-name => comint.el<2> (uniquify buffer name)") buffer-name => comint.el<2> (uniquify buffer name)")
(defvar doom-modeline-icon (display-graphic-p) (defvar doom-modeline-icon (display-graphic-p)
"Whether show `all-the-icons' or not. "Whether display icons in mode-line or not.")
Non-nil to show the icons in mode-line.
The icons may not be showed correctly in terminal.")
(defvar doom-modeline-major-mode-icon t (defvar doom-modeline-major-mode-icon t
"Whether show the icon for major mode. It respects `doom-modeline-icon'.") "Whether display the icon for major mode. It respects `doom-modeline-icon'.")
(defvar doom-modeline-major-mode-color-icon t (defvar doom-modeline-major-mode-color-icon t
"Display color icons for `major-mode'. It respects `all-the-icons-color-icons'.") "Whether display color icons for `major-mode'. It respects `doom-modeline-icon' and `all-the-icons-color-icons'.")
(defvar doom-modeline-buffer-state-icon t
"Whether display icons for buffer states. It respects `doom-modeline-icon'.")
(defvar doom-modeline-buffer-modification-icon t
"Whether display buffer modification icon. It respects `doom-modeline-icon' and `doom-modeline-buffer-state-icon'.")
(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 in mode-line or not.")
(defvar doom-modeline-enable-word-count nil (defvar doom-modeline-enable-word-count nil
"If non-nil, a word count will be added to the selection-info modeline segment.") "If non-nil, a word count will be added to the selection-info modeline segment.")
@ -320,11 +323,11 @@ The icons may not be showed correctly in terminal.")
(defun doom-modeline-def-modeline (name lhs &optional rhs) (defun doom-modeline-def-modeline (name lhs &optional rhs)
"Defines a modeline format and byte-compiles it. "Defines a modeline format and byte-compiles it.
NAME is a symbol to identify it (used by `doom-modeline' for retrieval). NAME is a symbol to identify it (used by `doom-modeline' for retrieval).
LHS and RHS are lists of symbols of modeline segments defined with LHS and RHS are lists of symbols of modeline segments defined with
`doom-modeline-def-segment'. `doom-modeline-def-segment'.
Example: Example:
(doom-modeline-def-modeline 'minimal (doom-modeline-def-modeline 'minimal
'(bar matches \" \" buffer-info) '(bar matches \" \" buffer-info)
'(media-info major-mode)) '(media-info major-mode))
@ -351,14 +354,14 @@ Example:
(defun doom-modeline (key) (defun doom-modeline (key)
"Return a mode-line configuration associated with KEY (a symbol). "Return a mode-line configuration associated with KEY (a symbol).
Throws an error if it doesn't exist." Throws an error if it doesn't exist."
(let ((fn (intern-soft (format "doom-modeline-format--%s" key)))) (let ((fn (intern-soft (format "doom-modeline-format--%s" key))))
(when (functionp fn) (when (functionp fn)
`(:eval (,fn))))) `(:eval (,fn)))))
(defun doom-modeline-set-modeline (key &optional default) (defun doom-modeline-set-modeline (key &optional default)
"Set the modeline format. Does nothing if the modeline KEY doesn't exist. "Set the modeline format. Does nothing if the modeline KEY doesn't exist.
If DEFAULT is non-nil, set the default mode-line for all buffers." If DEFAULT is non-nil, set the default mode-line for all buffers."
(when-let ((modeline (doom-modeline key))) (when-let ((modeline (doom-modeline key)))
(setf (if default (setf (if default
(default-value 'mode-line-format) (default-value 'mode-line-format)
@ -509,7 +512,7 @@ If DEFAULT is non-nil, set the default mode-line for all buffers."
(defvar-local doom-modeline-project-root nil) (defvar-local doom-modeline-project-root nil)
(defun doom-modeline-project-root () (defun doom-modeline-project-root ()
"Get the path to the root of your project. "Get the path to the root of your project.
Return `default-directory' if no project was found." Return `default-directory' if no project was found."
(or doom-modeline-project-root (or doom-modeline-project-root
(setq doom-modeline-project-root (setq doom-modeline-project-root
(file-local-name (file-local-name

View file

@ -231,13 +231,14 @@ buffer where knowing the current project directory is important."
"Displays an ICON with FACE, HEIGHT and VOFFSET. "Displays an ICON with FACE, HEIGHT and VOFFSET.
TEXT is the alternative if it is not applicable. TEXT is the alternative if it is not applicable.
Uses `all-the-icons-material' to fetch the icon." Uses `all-the-icons-material' to fetch the icon."
(if doom-modeline-icon (if (and doom-modeline-icon
(when icon doom-modeline-buffer-state-icon
icon)
(doom-modeline-icon-material (doom-modeline-icon-material
icon icon
:face face :face face
:height (or height 1.1) :height (or height 1.1)
:v-adjust (or voffset -0.225))) :v-adjust (or voffset -0.225))
(when text (when text
(propertize text 'face face)))) (propertize text 'face face))))
@ -250,7 +251,8 @@ Uses `all-the-icons-material' to fetch the icon."
"lock" "lock"
"%1*" "%1*"
'doom-modeline-warning)) 'doom-modeline-warning))
((and buffer-file-name (buffer-modified-p)) ((and buffer-file-name (buffer-modified-p)
doom-modeline-buffer-modification-icon)
(doom-modeline-buffer-file-state-icon (doom-modeline-buffer-file-state-icon
"save" "save"
"%1*" "%1*"