Minor fix.

This commit is contained in:
Vincent Zhang 2018-06-19 18:23:22 +08:00
parent 747f060cdf
commit 998cfe1bd4

View file

@ -104,7 +104,7 @@ then it detaches itself."
(defvar doom-modeline-fn-alist ()) (defvar doom-modeline-fn-alist ())
(defvar doom-modeline-var-alist ())) (defvar doom-modeline-var-alist ()))
(defmacro doom-modeline-def-segment! (name &rest body) (defmacro doom-modeline-def-segment (name &rest body)
"Defines a modeline segment and byte compiles it." "Defines a modeline segment and byte compiles it."
(declare (indent defun) (doc-string 2)) (declare (indent defun) (doc-string 2))
(let ((sym (intern (format "doom-modeline-segment--%s" name))) (let ((sym (intern (format "doom-modeline-segment--%s" name)))
@ -125,6 +125,7 @@ then it detaches itself."
(byte-compile #',sym)))))))) (byte-compile #',sym))))))))
(defsubst doom-modeline--prepare-segments (segments) (defsubst doom-modeline--prepare-segments (segments)
"Prepare mode-line `SEGMENTS'."
(let (forms it) (let (forms it)
(dolist (seg segments) (dolist (seg segments)
(cond ((stringp seg) (cond ((stringp seg)
@ -138,15 +139,16 @@ then it detaches itself."
((error "%s is not a valid segment" seg)))) ((error "%s is not a valid segment" seg))))
(nreverse forms))) (nreverse forms)))
(defmacro doom-modeline-def-modeline! (name lhs &optional rhs) (defmacro doom-modeline-def (name lhs &optional rhs)
"Defines a modeline format and byte-compiles it. NAME is a symbol to identify "Defines a modeline format and byte-compiles it.
it (used by `doom-modeline' for retrieval). LHS and RHS are lists of symbols of NAME is a symbol to identify it (used by `doom-modeline' for retrieval).
modeline segments defined with `doom-modeline-def-segment!'. LHS and RHS are lists of symbols of modeline segments defined with
`doom-modeline-def-segment'.
Example: Example:
(doom-modeline-def-modeline! minimal (doom-modeline-def minimal
(bar matches \" \" buffer-info) (bar matches \" \" buffer-info)
(media-info major-mode)) (media-info major-mode))
(doom-set-modeline 'minimal t)" (doom-modeline-set 'minimal t)"
(let ((sym (intern (format "doom-modeline-format--%s" name))) (let ((sym (intern (format "doom-modeline-format--%s" name)))
(lhs-forms (doom-modeline--prepare-segments lhs)) (lhs-forms (doom-modeline--prepare-segments lhs))
(rhs-forms (doom-modeline--prepare-segments rhs))) (rhs-forms (doom-modeline--prepare-segments rhs)))
@ -171,14 +173,16 @@ Example:
(byte-compile #',sym)))))) (byte-compile #',sym))))))
(defun doom-modeline (key) (defun doom-modeline (key)
"Return a mode-line configuration associated with KEY (a symbol). Throws an error if it doesn't exist." "Return a mode-line configuration associated with KEY (a symbol).
Throws an error if it doesn't exist."
(let ((fn (intern (format "doom-modeline-format--%s" key)))) (let ((fn (intern (format "doom-modeline-format--%s" key))))
(when (functionp fn) (when (functionp fn)
`(:eval (,fn))))) `(:eval (,fn)))))
(defun doom-modeline-set (key &optional default) (defun doom-modeline-set (key &optional default)
"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." "Set the modeline format. Does nothing if the modeline KEY doesn't exist.
(when-let ((modeline (doom-modeline key))) If DEFAULT is non-nil, set the default mode-line for all buffers."
(when-let (m (doom-modeline key))
(setf (if default (setf (if default
(default-value 'mode-line-format) (default-value 'mode-line-format)
(buffer-local-value 'mode-line-format (current-buffer))) (buffer-local-value 'mode-line-format (current-buffer)))
@ -516,53 +520,53 @@ Example:
;; buffer information ;; buffer information
;; ;;
(doom-modeline-def-segment! buffer-default-directory (doom-modeline-def-segment buffer-default-directory
"Displays `default-directory'. This is for special buffers like the scratch "Displays `default-directory'. This is for special buffers like the scratch
buffer where knowing the current project directory is important." buffer where knowing the current project directory is important."
(let ((face (if (doom-modeline--active) 'doom-modeline-buffer-path))) (let ((face (if (doom-modeline--active) 'doom-modeline-buffer-path)))
(concat (if (display-graphic-p) " ") (concat (if (display-graphic-p) " ")
(doom-modeline-maybe-icon-octicon (doom-modeline-maybe-icon-octicon
"file-directory" "file-directory"
:face face :face face
:v-adjust -0.05 :v-adjust -0.05
:height 1.25) :height 1.25)
(propertize (concat " " (abbreviate-file-name default-directory)) (propertize (concat " " (abbreviate-file-name default-directory))
'face face)))) 'face face))))
;; ;;
(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 (cond (buffer-read-only (concat (cond (buffer-read-only
(concat (doom-modeline-maybe-icon-octicon (concat (doom-modeline-maybe-icon-octicon
"lock" "lock"
:face 'doom-modeline-warning :face 'doom-modeline-warning
:v-adjust -0.05) :v-adjust -0.05)
" ")) " "))
((buffer-modified-p) ((buffer-modified-p)
(concat (doom-modeline-maybe-icon-faicon (concat (doom-modeline-maybe-icon-faicon
"floppy-o" "floppy-o"
:face 'doom-modeline-buffer-modified :face 'doom-modeline-buffer-modified
:v-adjust -0.0575) :v-adjust -0.0575)
" ")) " "))
((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-maybe-icon-octicon (concat (doom-modeline-maybe-icon-octicon
"circle-slash" "circle-slash"
:face 'doom-modeline-urgent :face 'doom-modeline-urgent
:v-adjust -0.05) :v-adjust -0.05)
" ")) " "))
((buffer-narrowed-p) ((buffer-narrowed-p)
(concat (doom-modeline-maybe-icon-octicon (concat (doom-modeline-maybe-icon-octicon
"fold" "fold"
:face 'doom-modeline-warning :face 'doom-modeline-warning
:v-adjust -0.05) :v-adjust -0.05)
" "))) " ")))
(if buffer-file-name (if buffer-file-name
(doom-modeline-buffer-file-name) (doom-modeline-buffer-file-name)
"%b"))) "%b")))
(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."
(propertize (propertize
"%b" "%b"
@ -571,7 +575,7 @@ directory, the file name, and its state (modified, read-only or non-existent)."
((doom-modeline--active) 'doom-modeline-buffer-file)))) ((doom-modeline--active) 'doom-modeline-buffer-file))))
;; ;;
(doom-modeline-def-segment! buffer-encoding (doom-modeline-def-segment buffer-encoding
"Displays the encoding and eol style of the buffer the same way Atom does." "Displays the encoding and eol style of the buffer the same way Atom does."
(concat (pcase (coding-system-eol-type buffer-file-coding-system) (concat (pcase (coding-system-eol-type buffer-file-coding-system)
(0 "LF ") (0 "LF ")
@ -587,7 +591,7 @@ directory, the file name, and its state (modified, read-only or non-existent)."
;; major-mode ;; major-mode
;; ;;
(doom-modeline-def-segment! major-mode (doom-modeline-def-segment major-mode
"The major mode, including process, environment and text-scale info." "The major mode, including process, environment and text-scale info."
(propertize (propertize
(concat (format-mode-line mode-name) (concat (format-mode-line mode-name)
@ -644,7 +648,7 @@ directory, the file name, and its state (modified, read-only or non-existent)."
(add-hook 'after-save-hook #'doom-modeline--update-vcs) (add-hook 'after-save-hook #'doom-modeline--update-vcs)
(add-hook 'find-file-hook #'doom-modeline--update-vcs t) (add-hook 'find-file-hook #'doom-modeline--update-vcs t)
(doom-modeline-def-segment! vcs (doom-modeline-def-segment vcs
"Displays the current branch, colored based on its state." "Displays the current branch, colored based on its state."
doom-modeline--vcs) doom-modeline--vcs)
@ -688,7 +692,7 @@ Uses `all-the-icons-material' to fetch the icon."
(`errored (doom-modeline-icon "sim_card_alert" "Error" 'doom-modeline-urgent)) (`errored (doom-modeline-icon "sim_card_alert" "Error" 'doom-modeline-urgent))
(`interrupted (doom-modeline-icon "pause" "Interrupted" 'font-lock-doc-face))))) (`interrupted (doom-modeline-icon "pause" "Interrupted" 'font-lock-doc-face)))))
(doom-modeline-def-segment! flycheck (doom-modeline-def-segment flycheck
"Displays color-coded flycheck error status in the current buffer with pretty "Displays color-coded flycheck error status in the current buffer with pretty
icons." icons."
doom-modeline--flycheck) doom-modeline--flycheck)
@ -706,7 +710,7 @@ icons."
"If non-nil, a word count will be added to the selection-info modeline "If non-nil, a word count will be added to the selection-info modeline
segment.") segment.")
(doom-modeline-def-segment! selection-info (doom-modeline-def-segment selection-info
"Information about the current selection, such as how many characters and "Information about the current selection, such as how many characters and
lines are selected, or the NxM dimensions of a block selection." lines are selected, or the NxM dimensions of a block selection."
(when (and mark-active (doom-modeline--active)) (when (and mark-active (doom-modeline--active))
@ -804,7 +808,7 @@ lines are selected, or the NxM dimensions of a block selection."
length)) length))
'face (if (doom-modeline--active) 'doom-modeline-panel)))) 'face (if (doom-modeline--active) 'doom-modeline-panel))))
(doom-modeline-def-segment! matches (doom-modeline-def-segment matches
"Displays: 1. the currently recording macro, 2. A current/total for the "Displays: 1. the currently recording macro, 2. A current/total for the
current search term (with anzu), 3. The number of substitutions being conducted current search term (with anzu), 3. The number of substitutions being conducted
with `evil-ex-substitute', and/or 4. The number of active `iedit' regions." with `evil-ex-substitute', and/or 4. The number of active `iedit' regions."
@ -819,7 +823,7 @@ with `evil-ex-substitute', and/or 4. The number of active `iedit' regions."
;; media-info ;; media-info
;; ;;
(doom-modeline-def-segment! media-info (doom-modeline-def-segment media-info
"Metadata regarding the current file, such as dimensions for images." "Metadata regarding the current file, such as dimensions for images."
;; TODO Include other information ;; TODO Include other information
(cond ((eq major-mode 'image-mode) (cond ((eq major-mode 'image-mode)
@ -833,7 +837,7 @@ with `evil-ex-substitute', and/or 4. The number of active `iedit' regions."
(defvar doom-modeline--bar-active nil) (defvar doom-modeline--bar-active nil)
(defvar doom-modeline--bar-inactive nil) (defvar doom-modeline--bar-inactive nil)
(doom-modeline-def-segment! bar (doom-modeline-def-segment bar
"The bar regulates the height of the mode-line in GUI Emacs. "The bar regulates the height of the mode-line in GUI Emacs.
Returns \"\" to not break --no-window-system." Returns \"\" to not break --no-window-system."
(if (display-graphic-p) (if (display-graphic-p)
@ -863,7 +867,7 @@ Returns \"\" to not break --no-window-system."
(advice-add #'window-numbering-install-mode-line :override #'ignore) (advice-add #'window-numbering-install-mode-line :override #'ignore)
(advice-add #'window-numbering-clear-mode-line :override #'ignore) (advice-add #'window-numbering-clear-mode-line :override #'ignore)
(doom-modeline-def-segment! window-number (doom-modeline-def-segment window-number
(if (bound-and-true-p window-numbering-mode) (if (bound-and-true-p window-numbering-mode)
(propertize (format " %s " (window-numbering-get-number-string)) (propertize (format " %s " (window-numbering-get-number-string))
'face (if (doom-modeline--active) 'face (if (doom-modeline--active)
@ -876,7 +880,7 @@ Returns \"\" to not break --no-window-system."
;; ;;
(declare-function eyebrowse--get 'eyebrowse) (declare-function eyebrowse--get 'eyebrowse)
(doom-modeline-def-segment! workspace-number (doom-modeline-def-segment workspace-number
"The current workspace name or number. Requires `eyebrowse-mode' to be "The current workspace name or number. Requires `eyebrowse-mode' to be
enabled." enabled."
(if (and (bound-and-true-p eyebrowse-mode) (if (and (bound-and-true-p eyebrowse-mode)
@ -893,25 +897,25 @@ enabled."
;; Mode lines ;; Mode lines
;; ;;
(doom-modeline-def-modeline! main (doom-modeline-def main
(workspace-number bar matches " " buffer-info " %l:%c %p " selection-info) (workspace-number bar matches " " buffer-info " %l:%c %p " selection-info)
(buffer-encoding major-mode vcs flycheck)) (buffer-encoding major-mode vcs flycheck))
(doom-modeline-def-modeline! minimal (doom-modeline-def minimal
(bar matches " " buffer-info) (bar matches " " buffer-info)
(media-info major-mode)) (media-info major-mode))
(doom-modeline-def-modeline! special (doom-modeline-def special
(bar matches " " buffer-info-simple " %l:%c %p " selection-info) (bar matches " " buffer-info-simple " %l:%c %p " selection-info)
(buffer-encoding major-mode flycheck)) (buffer-encoding major-mode flycheck))
(doom-modeline-def-modeline! project (doom-modeline-def project
(bar buffer-default-directory) (bar buffer-default-directory)
(major-mode)) (major-mode))
(doom-modeline-def-modeline! media (doom-modeline-def media
(bar " %b ") (bar " %b ")
(media-info major-mode)) (media-info major-mode))
;; ;;
;; Hooks ;; Hooks