From da777a87c15f111aedf84fad724ae2c3b6a352a0 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Wed, 13 Jun 2018 21:34:31 +0800 Subject: [PATCH 01/28] Remove `memoize` dependency. --- doom-modeline.el | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/doom-modeline.el b/doom-modeline.el index bb16df9..c28e363 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -47,7 +47,6 @@ (require 'projectile) (require 'all-the-icons) (require 'dash) -(require 'memoize) (require 'shrink-path) (require 'eldoc-eval) @@ -410,7 +409,7 @@ active." (eq (selected-window) doom-modeline-current-window)) ;; Inspired from `powerline's `pl/make-xpm'. -(defmemoize doom-modeline--make-xpm (color height width) +(defun doom-modeline--make-xpm (color height width) "Create an XPM bitmap." (propertize " " 'display @@ -473,9 +472,6 @@ If TRUNCATE-TAIL is t also truncate the parent directory of the file." (propertize (file-name-nondirectory buffer-file-name) 'face (if file-faces `(:inherit ,file-faces))))))))) -(defmemoize doom-modeline-file-relative-name (filename directory) - (file-relative-name filename directory)) - (defun doom-modeline--buffer-file-name-relative (&optional include-project) "Propertized `buffer-file-name' showing directories relative to project's root only." (let ((root (doom-modeline-project-root)) @@ -492,14 +488,6 @@ If TRUNCATE-TAIL is t also truncate the parent directory of the file." (propertize (file-name-nondirectory buffer-file-truename) 'face (if file-faces `(:inherit ,file-faces)))))))) -(defmemoize doom-modeline-abbreviate-file-name (file-name) - (abbreviate-file-name file-name)) - -(defmemoize doom-modeline-shrink-path-file-mixed (project-root file-name) - (shrink-path-file-mixed project-root - (file-name-directory file-name) - file-name)) - (defun doom-modeline--buffer-file-name (truncate-project-root-parent) "Propertized `buffer-file-name'. If TRUNCATE-PROJECT-ROOT-PARENT is t space will be saved by truncating it down From 2b87b94af5704ee2e7620b64dd5fbd46d1457999 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Thu, 14 Jun 2018 18:00:13 +0800 Subject: [PATCH 02/28] Fix: quote -> backquote. --- doom-modeline.el | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/doom-modeline.el b/doom-modeline.el index c28e363..48f6219 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -439,12 +439,12 @@ active." "Propertized `buffer-file-name' based on `doom-modeline-buffer-file-name-style'." (propertize (pcase doom-modeline-buffer-file-name-style - ('truncate-upto-project (doom-modeline--buffer-file-name 'shrink)) - ('truncate-upto-root (doom-modeline--buffer-file-name-truncate)) - ('truncate-all (doom-modeline--buffer-file-name-truncate t)) - ('relative-to-project (doom-modeline--buffer-file-name-relative)) - ('relative-from-project (doom-modeline--buffer-file-name-relative 'include-project)) - ('file-name (propertize (file-name-nondirectory buffer-file-name) + (`truncate-upto-project (doom-modeline--buffer-file-name 'shrink)) + (`truncate-upto-root (doom-modeline--buffer-file-name-truncate)) + (`truncate-all (doom-modeline--buffer-file-name-truncate t)) + (`relative-to-project (doom-modeline--buffer-file-name-relative)) + (`relative-from-project (doom-modeline--buffer-file-name-relative 'include-project)) + (`file-name (propertize (file-name-nondirectory buffer-file-name) 'face (let ((face (or (and (buffer-modified-p) 'doom-modeline-buffer-modified) @@ -677,7 +677,7 @@ directory, the file name, and its state (modified, read-only or non-existent)." icons." (when (boundp 'flycheck-last-status-change) (pcase flycheck-last-status-change - ('finished (if flycheck-current-errors + (`finished (if flycheck-current-errors (let-alist (flycheck-count-errors flycheck-current-errors) (let ((sum (+ (or .error 0) (or .warning 0)))) (doom-modeline-icon "do_not_disturb_alt" @@ -685,10 +685,10 @@ icons." (if .error 'doom-modeline-urgent 'doom-modeline-warning) -0.25))) (doom-modeline-icon "check" nil 'doom-modeline-info))) - ('running (doom-modeline-icon "access_time" nil 'font-lock-doc-face -0.25)) - ('no-checker (doom-modeline-icon "sim_card_alert" "-" 'font-lock-doc-face)) - ('errored (doom-modeline-icon "sim_card_alert" "Error" 'doom-modeline-urgent)) - ('interrupted (doom-modeline-icon "pause" "Interrupted" 'font-lock-doc-face))))) + (`running (doom-modeline-icon "access_time" nil 'font-lock-doc-face -0.25)) + (`no-checker (doom-modeline-icon "sim_card_alert" "-" 'font-lock-doc-face)) + (`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 "x" "Interrupted" 'font-lock-doc-face))))) From 29e92d589cdc39c900a5d07743a48b760e3d5517 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Fri, 15 Jun 2018 02:13:56 +0800 Subject: [PATCH 03/28] Update comments. --- doom-modeline.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doom-modeline.el b/doom-modeline.el index 48f6219..da6e797 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -73,7 +73,7 @@ (defvar doom-modeline--transient-counter 0)) (defmacro doom-modeline-add-transient-hook! (hook &rest forms) - "Attaches transient forms to a HOOK. + "Attache transient FORMS to a HOOK. HOOK can be a quoted hook or a sharp-quoted function (which will be advised). These forms will be evaluated once when that function/hook is first invoked, then it detaches itself." From 7498b4879eaa35f1f5a50f84b1c7fadb94b4290f Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Fri, 15 Jun 2018 12:18:01 +0800 Subject: [PATCH 04/28] Fix warnings. --- doom-modeline.el | 516 ++++++++++++++++++++++++----------------------- 1 file changed, 259 insertions(+), 257 deletions(-) diff --git a/doom-modeline.el b/doom-modeline.el index da6e797..b865f23 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -141,7 +141,7 @@ Body forms can access the hook's arguments through the let-bound variable `(progn ,@(nreverse forms))))) (defmacro doom-modeline-def-segment! (name &rest forms) - "Defines a modeline segment and byte compiles it." + "Define a modeline segment and byte compiles it." (declare (indent defun) (doc-string 2)) (let ((sym (intern (format "doom-modeline-segment--%s" name)))) `(progn @@ -158,9 +158,10 @@ Body forms can access the hook's arguments through the let-bound variable collect (list (intern (format "doom-modeline-segment--%s" (symbol-name seg)))))) (defmacro doom-modeline-def-modeline! (name lhs &optional rhs) - "Defines a modeline format and byte-compiles it. 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 `doom-modeline-def-segment!'. + "Define a modeline format and byte-compiles it. +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 `doom-modeline-def-segment!'. Example: (doom-modeline-def-modeline! minimal (bar matches \" \" buffer-info) @@ -185,15 +186,15 @@ Example: (byte-compile #',sym)))))) (defun doom-modeline (key) - "Returns 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)))) (when (functionp fn) `(:eval (,fn))))) (defun doom-modeline-set-modeline (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. +If DEFAULT is non-nil, set the default mode-line for all buffers." (-when-let* ((modeline (doom-modeline key))) (setf (if default (default-value 'mode-line-format) @@ -207,76 +208,15 @@ If STRICT-P, return nil if no project was found, otherwise return (let (projectile-require-project-root) (projectile-project-root))) -;; -;; modeline configs -;; - -(defun doom-modeline-eldoc (text) - (concat (when (display-graphic-p) - (doom-modeline--make-xpm - (face-background 'doom-modeline-eldoc-bar nil t) - doom-modeline-height - doom-modeline-bar-width)) - text)) - -;; Show eldoc in the mode-line with `eval-expression' -(defun doom-modeline--show-eldoc (input) - "Display string STR in the mode-line next to minibuffer." - (with-current-buffer (eldoc-current-buffer) - (let* ((str (and (stringp input) input)) - (mode-line-format (or (and str (or (doom-modeline-eldoc str) str)) - mode-line-format)) - mode-line-in-non-selected-windows) - (force-mode-line-update) - (sit-for eldoc-show-in-mode-line-delay)))) -(setq eldoc-in-minibuffer-show-fn #'doom-modeline--show-eldoc) - -(eldoc-in-minibuffer-mode +1) - - -;; anzu and evil-anzu expose current/total state that can be displayed in the -;; mode-line. -(when (featurep 'evil-anzu) - (doom-modeline-add-transient-hook! #'evil-ex-start-search (require 'evil-anzu)) - - (setq anzu-cons-mode-line-p nil - anzu-minimum-input-length 1 - anzu-search-threshold 250) - - ;; Avoid anzu conflicts across buffers - (mapc #'make-variable-buffer-local - '(anzu--total-matched anzu--current-position anzu--state - anzu--cached-count anzu--cached-positions anzu--last-command - anzu--last-isearch-string anzu--overflow-p)) - - ;; Ensure anzu state is cleared when searches & iedit are done - (add-hook 'isearch-mode-end-hook #'anzu--reset-status t) - (add-hook '+evil-esc-hook #'anzu--reset-status t) - (add-hook 'iedit-mode-end-hook #'anzu--reset-status)) - - -;; Keep `doom-modeline-current-window' up-to-date -(defvar doom-modeline-current-window (frame-selected-window)) -(defun doom-modeline-set-selected-window (&rest _) - "Set `doom-modeline-current-window' appropriately." - (-when-let* ((win (frame-selected-window))) - (unless (minibuffer-window-active-p win) - (setq doom-modeline-current-window win)))) - -(add-hook 'window-configuration-change-hook #'doom-modeline-set-selected-window) -(add-hook 'focus-in-hook #'doom-modeline-set-selected-window) -(advice-add #'handle-switch-frame :after #'doom-modeline-set-selected-window) -(advice-add #'select-window :after #'doom-modeline-set-selected-window) - ;; ;; Variables ;; (defvar doom-modeline-height 29 - "How tall the mode-line should be (only respected in GUI emacs).") + "How tall the mode-line should be (only respected in GUI).") (defvar doom-modeline-bar-width 3 - "How wide the mode-line bar should be (only respected in GUI emacs).") + "How wide the mode-line bar should be (only respected in GUI).") (defvar doom-modeline-vspc (propertize " " 'face 'variable-pitch) @@ -379,6 +319,68 @@ active." "The face used for brackets around the project." :group 'doom-modeline) +;; +;; modeline configs +;; + +(defun doom-modeline-eldoc (text) + (concat (when (display-graphic-p) + (doom-modeline--make-xpm + (face-background 'doom-modeline-eldoc-bar nil t) + doom-modeline-height + doom-modeline-bar-width)) + text)) + +;; Show eldoc in the mode-line with `eval-expression' +(defun doom-modeline--show-eldoc (input) + "Display string STR in the mode-line next to minibuffer." + (with-current-buffer (eldoc-current-buffer) + (let* ((str (and (stringp input) input)) + (mode-line-format (or (and str (or (doom-modeline-eldoc str) str)) + mode-line-format)) + mode-line-in-non-selected-windows) + (force-mode-line-update) + (sit-for eldoc-show-in-mode-line-delay)))) +(setq eldoc-in-minibuffer-show-fn #'doom-modeline--show-eldoc) + +(eldoc-in-minibuffer-mode +1) + + +;; anzu and evil-anzu expose current/total state that can be displayed in the +;; mode-line. +(when (featurep 'evil-anzu) + (doom-modeline-add-transient-hook! #'evil-ex-start-search (require 'evil-anzu)) + + (setq anzu-cons-mode-line-p nil + anzu-minimum-input-length 1 + anzu-search-threshold 250) + + ;; Avoid anzu conflicts across buffers + (mapc #'make-variable-buffer-local + '(anzu--total-matched anzu--current-position anzu--state + anzu--cached-count anzu--cached-positions anzu--last-command + anzu--last-isearch-string anzu--overflow-p)) + + ;; Ensure anzu state is cleared when searches & iedit are done + (add-hook 'isearch-mode-end-hook #'anzu--reset-status t) + ;; (add-hook '+evil-esc-hook #'anzu--reset-status t) + (add-hook 'iedit-mode-end-hook #'anzu--reset-status)) + + +;; Keep `doom-modeline-current-window' up-to-date +(defvar doom-modeline-current-window (frame-selected-window)) +(defun doom-modeline-set-selected-window (&rest _) + "Set `doom-modeline-current-window' appropriately." + (-when-let* ((win (frame-selected-window))) + (unless (minibuffer-window-active-p win) + (setq doom-modeline-current-window win)))) + +(add-hook 'window-configuration-change-hook #'doom-modeline-set-selected-window) +(add-hook 'focus-in-hook #'doom-modeline-set-selected-window) +(advice-add #'handle-switch-frame :after #'doom-modeline-set-selected-window) +(advice-add #'select-window :after #'doom-modeline-set-selected-window) + + ;; ;; Bootstrap ;; @@ -526,88 +528,88 @@ Example: (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." - (let ((face (if (doom-modeline--active) 'doom-modeline-buffer-path))) - (concat (if (display-graphic-p) " ") - (doom-modeline-maybe-icon-octicon - "file-directory" - :face face - :v-adjust -0.05 - :height 1.25) - (propertize (concat " " (abbreviate-file-name default-directory)) - 'face face)))) + (let ((face (if (doom-modeline--active) 'doom-modeline-buffer-path))) + (concat (if (display-graphic-p) " ") + (doom-modeline-maybe-icon-octicon + "file-directory" + :face face + :v-adjust -0.05 + :height 1.25) + (propertize (concat " " (abbreviate-file-name default-directory)) + 'face face)))) ;; (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)." - (concat - (cond (buffer-read-only - (concat (doom-modeline-maybe-icon-octicon - "lock" - :face 'doom-modeline-warning - :v-adjust -0.05) - " ")) - ((buffer-modified-p) - (concat (doom-modeline-maybe-icon-faicon - "floppy-o" - :face 'doom-modeline-buffer-modified - :v-adjust -0.0575) - " ")) - ((and buffer-file-name - (not (file-exists-p buffer-file-name))) - (concat (doom-modeline-maybe-icon-octicon - "circle-slash" - :face 'doom-modeline-urgent - :v-adjust -0.05) - " ")) - ((buffer-narrowed-p) - (concat (doom-modeline-maybe-icon-octicon - "fold" - :face 'doom-modeline-warning - :v-adjust -0.05) - " "))) - (if buffer-file-name - (doom-modeline-buffer-file-name) - "%b"))) + (concat + (cond (buffer-read-only + (concat (doom-modeline-maybe-icon-octicon + "lock" + :face 'doom-modeline-warning + :v-adjust -0.05) + " ")) + ((buffer-modified-p) + (concat (doom-modeline-maybe-icon-faicon + "floppy-o" + :face 'doom-modeline-buffer-modified + :v-adjust -0.0575) + " ")) + ((and buffer-file-name + (not (file-exists-p buffer-file-name))) + (concat (doom-modeline-maybe-icon-octicon + "circle-slash" + :face 'doom-modeline-urgent + :v-adjust -0.05) + " ")) + ((buffer-narrowed-p) + (concat (doom-modeline-maybe-icon-octicon + "fold" + :face 'doom-modeline-warning + :v-adjust -0.05) + " "))) + (if buffer-file-name + (doom-modeline-buffer-file-name) + "%b"))) ;; (doom-modeline-def-segment! buffer-info-simple - "Display only the current buffer's name, but with fontification." - (propertize - "%b" - 'face (cond ((and buffer-file-name (buffer-modified-p)) - 'doom-modeline-buffer-modified) - ((doom-modeline--active) 'doom-modeline-buffer-file)))) + "Display only the current buffer's name, but with fontification." + (propertize + "%b" + 'face (cond ((and buffer-file-name (buffer-modified-p)) + 'doom-modeline-buffer-modified) + ((doom-modeline--active) 'doom-modeline-buffer-file)))) ;; (doom-modeline-def-segment! buffer-encoding - "Displays the encoding and eol style of the buffer the same way Atom does." - (concat (pcase (coding-system-eol-type buffer-file-coding-system) - (0 "LF ") - (1 "CRLF ") - (2 "CR ")) - (let ((sys (coding-system-plist buffer-file-coding-system))) - (cond ((memq (plist-get sys :category) '(coding-category-undecided coding-category-utf-8)) - "UTF-8") - (t (upcase (symbol-name (plist-get sys :name)))))) - " ")) + "Displays the encoding and eol style of the buffer the same way Atom does." + (concat (pcase (coding-system-eol-type buffer-file-coding-system) + (0 "LF ") + (1 "CRLF ") + (2 "CR ")) + (let ((sys (coding-system-plist buffer-file-coding-system))) + (cond ((memq (plist-get sys :category) '(coding-category-undecided coding-category-utf-8)) + "UTF-8") + (t (upcase (symbol-name (plist-get sys :name)))))) + " ")) ;; (doom-modeline-def-segment! major-mode - "The major mode, including process, environment and text-scale info." - (propertize - (concat (format-mode-line mode-name) - (when (stringp mode-line-process) - mode-line-process) - (when doom-modeline-env-version - (concat " " doom-modeline-env-version)) - (and (featurep 'face-remap) - (/= text-scale-mode-amount 0) - (format " (%+d)" text-scale-mode-amount))) - 'face (if (doom-modeline--active) 'doom-modeline-buffer-major-mode))) + "The major mode, including process, environment and text-scale info." + (propertize + (concat (format-mode-line mode-name) + (when (stringp mode-line-process) + mode-line-process) + (when doom-modeline-env-version + (concat " " doom-modeline-env-version)) + (and (featurep 'face-remap) + (/= text-scale-mode-amount 0) + (format " (%+d)" text-scale-mode-amount))) + 'face (if (doom-modeline--active) 'doom-modeline-buffer-major-mode))) (defun doom-modeline-maybe-icon-octicon (&rest args) @@ -624,39 +626,39 @@ directory, the file name, and its state (modified, read-only or non-existent)." ;; (doom-modeline-def-segment! vcs - "Displays the current branch, colored based on its state." - (when (and vc-mode buffer-file-name) - (let* ((backend (vc-backend buffer-file-name)) - (state (vc-state buffer-file-name backend))) - (let ((face 'mode-line-inactive) - (active (doom-modeline--active)) - (all-the-icons-default-adjust -0.1)) - (concat (if (display-graphic-p) " ") - (cond ((memq state '(edited added)) - (if active (setq face 'doom-modeline-info)) - (doom-modeline-maybe-icon-octicon - "git-compare" - :face face - :v-adjust -0.05)) - ((eq state 'needs-merge) - (if active (setq face 'doom-modeline-info)) - (doom-modeline-maybe-icon-octicon "git-merge" :face face)) - ((eq state 'needs-update) - (if active (setq face 'doom-modeline-warning)) - (doom-modeline-maybe-icon-octicon "arrow-down" :face face)) - ((memq state '(removed conflict unregistered)) - (if active (setq face 'doom-modeline-urgent)) - (doom-modeline-maybe-icon-octicon "alert" :face face)) - (t - (if active (setq face 'font-lock-doc-face)) - (doom-modeline-maybe-icon-octicon - "git-branch" - :face face - :v-adjust -0.05))) - " " - (propertize (substring vc-mode (+ (if (eq backend 'Hg) 2 3) 2)) - 'face (if active face)) - " "))))) + "Displays the current branch, colored based on its state." + (when (and vc-mode buffer-file-name) + (let* ((backend (vc-backend buffer-file-name)) + (state (vc-state buffer-file-name backend))) + (let ((face 'mode-line-inactive) + (active (doom-modeline--active)) + (all-the-icons-default-adjust -0.1)) + (concat (if (display-graphic-p) " ") + (cond ((memq state '(edited added)) + (if active (setq face 'doom-modeline-info)) + (doom-modeline-maybe-icon-octicon + "git-compare" + :face face + :v-adjust -0.05)) + ((eq state 'needs-merge) + (if active (setq face 'doom-modeline-info)) + (doom-modeline-maybe-icon-octicon "git-merge" :face face)) + ((eq state 'needs-update) + (if active (setq face 'doom-modeline-warning)) + (doom-modeline-maybe-icon-octicon "arrow-down" :face face)) + ((memq state '(removed conflict unregistered)) + (if active (setq face 'doom-modeline-urgent)) + (doom-modeline-maybe-icon-octicon "alert" :face face)) + (t + (if active (setq face 'font-lock-doc-face)) + (doom-modeline-maybe-icon-octicon + "git-branch" + :face face + :v-adjust -0.05))) + " " + (propertize (substring vc-mode (+ (if (eq backend 'Hg) 2 3) 2)) + 'face (if active face)) + " "))))) ;; @@ -673,22 +675,22 @@ directory, the file name, and its state (modified, read-only or non-existent)." (if vc-mode " " " "))) (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." - (when (boundp 'flycheck-last-status-change) - (pcase flycheck-last-status-change - (`finished (if flycheck-current-errors - (let-alist (flycheck-count-errors flycheck-current-errors) - (let ((sum (+ (or .error 0) (or .warning 0)))) - (doom-modeline-icon "do_not_disturb_alt" - (number-to-string sum) - (if .error 'doom-modeline-urgent 'doom-modeline-warning) - -0.25))) - (doom-modeline-icon "check" nil 'doom-modeline-info))) - (`running (doom-modeline-icon "access_time" nil 'font-lock-doc-face -0.25)) - (`no-checker (doom-modeline-icon "sim_card_alert" "-" 'font-lock-doc-face)) - (`errored (doom-modeline-icon "sim_card_alert" "Error" 'doom-modeline-urgent)) - (`interrupted (doom-modeline-icon "pause" "Interrupted" 'font-lock-doc-face))))) + (when (boundp 'flycheck-last-status-change) + (pcase flycheck-last-status-change + (`finished (if flycheck-current-errors + (let-alist (flycheck-count-errors flycheck-current-errors) + (let ((sum (+ (or .error 0) (or .warning 0)))) + (doom-modeline-icon "do_not_disturb_alt" + (number-to-string sum) + (if .error 'doom-modeline-urgent 'doom-modeline-warning) + -0.25))) + (doom-modeline-icon "check" nil 'doom-modeline-info))) + (`running (doom-modeline-icon "access_time" nil 'font-lock-doc-face -0.25)) + (`no-checker (doom-modeline-icon "sim_card_alert" "-" 'font-lock-doc-face)) + (`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 "x" "Interrupted" 'font-lock-doc-face))))) @@ -698,25 +700,25 @@ icons." (current-column))) (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." - (when (and (doom-modeline--active) (or mark-active (eq evil-state 'visual))) - (let ((reg-beg (region-beginning)) - (reg-end (region-end))) - (propertize - (let ((lines (count-lines reg-beg (min (1+ reg-end) (point-max))))) - (cond ((or (bound-and-true-p rectangle-mark-mode) - (eq 'block evil-visual-selection)) - (let ((cols (abs (- (doom-modeline-column reg-end) - (doom-modeline-column reg-beg))))) - (format "%dx%dB" lines cols))) - ((eq 'line evil-visual-selection) - (format "%dL" lines)) - ((> lines 1) - (format "%dC %dL" (- (1+ reg-end) reg-beg) lines)) - (t - (format "%dC" (- (1+ reg-end) reg-beg))))) - 'face 'doom-modeline-highlight)))) + (when (and (doom-modeline--active) (or mark-active (eq evil-state 'visual))) + (let ((reg-beg (region-beginning)) + (reg-end (region-end))) + (propertize + (let ((lines (count-lines reg-beg (min (1+ reg-end) (point-max))))) + (cond ((or (bound-and-true-p rectangle-mark-mode) + (eq 'block evil-visual-selection)) + (let ((cols (abs (- (doom-modeline-column reg-end) + (doom-modeline-column reg-beg))))) + (format "%dx%dB" lines cols))) + ((eq 'line evil-visual-selection) + (format "%dL" lines)) + ((> lines 1) + (format "%dC %dL" (- (1+ reg-end) reg-beg) lines)) + (t + (format "%dC" (- (1+ reg-end) reg-beg))))) + 'face 'doom-modeline-highlight)))) ;; @@ -792,36 +794,36 @@ lines are selected, or the NxM dimensions of a block selection." 'face (if (doom-modeline--active) 'doom-modeline-panel)))) (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 with `evil-ex-substitute', and/or 4. The number of active `iedit' regions." - (let ((meta (concat (doom-modeline--macro-recording) - (doom-modeline--anzu) - (doom-modeline--evil-substitute) - (doom-modeline--iedit)))) - (or (and (not (equal meta "")) meta) - (if buffer-file-name " %I ")))) + (let ((meta (concat (doom-modeline--macro-recording) + (doom-modeline--anzu) + (doom-modeline--evil-substitute) + (doom-modeline--iedit)))) + (or (and (not (equal meta "")) meta) + (if buffer-file-name " %I ")))) ;; TODO Include other information (doom-modeline-def-segment! media-info - "Metadata regarding the current file, such as dimensions for images." - (cond ((eq major-mode 'image-mode) - (cl-destructuring-bind (width . height) - (image-size (image-get-display-property) :pixels) - (format " %dx%d " width height))))) + "Metadata regarding the current file, such as dimensions for images." + (cond ((eq major-mode 'image-mode) + (cl-destructuring-bind (width . height) + (image-size (image-get-display-property) :pixels) + (format " %dx%d " width height))))) (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." - (if (display-graphic-p) - (doom-modeline--make-xpm - (face-background (if (doom-modeline--active) - 'doom-modeline-bar - 'doom-modeline-inactive-bar) - nil t) - doom-modeline-height - doom-modeline-bar-width) - "")) + (if (display-graphic-p) + (doom-modeline--make-xpm + (face-background (if (doom-modeline--active) + 'doom-modeline-bar + 'doom-modeline-inactive-bar) + nil t) + doom-modeline-height + doom-modeline-bar-width) + "")) (defun doom-modeline-eyebrowse-number () (when (and (bound-and-true-p eyebrowse-mode) @@ -841,47 +843,47 @@ Returns \"\" to not break --no-window-system." (cadr minibuffer-edges))))) (doom-modeline-def-segment! persp-number - "The persp number." - (when (featurep 'persp-mode) - (when (doom-modeline-window-bottom-left-p) - (-when-let* ((persp (get-current-persp))) - (propertize - (concat - (number-to-string - (+ 1 - (cl-position - (persp-name persp) - (persp-names-current-frame-fast-ordered)))) - "." - (or (doom-modeline-eyebrowse-number) "1") - " ") - 'face 'doom-modeline-persp))))) + "The persp number." + (when (featurep 'persp-mode) + (when (doom-modeline-window-bottom-left-p) + (-when-let* ((persp (get-current-persp))) + (propertize + (concat + (number-to-string + (+ 1 + (cl-position + (persp-name persp) + (persp-names-current-frame-fast-ordered)))) + "." + (or (doom-modeline-eyebrowse-number) "1") + " ") + 'face 'doom-modeline-persp))))) (advice-add #'window-numbering-install-mode-line :override #'ignore) (advice-add #'window-numbering-clear-mode-line :override #'ignore) (doom-modeline-def-segment! window-number - (if (bound-and-true-p window-numbering-mode) - (propertize (format " %s " (window-numbering-get-number-string)) - 'face (if (doom-modeline--active) - 'doom-modeline-bar - 'doom-modeline-inactive-bar)) - "")) + (if (bound-and-true-p window-numbering-mode) + (propertize (format " %s " (window-numbering-get-number-string)) + 'face (if (doom-modeline--active) + 'doom-modeline-bar + 'doom-modeline-inactive-bar)) + "")) (declare-function eyebrowse--get 'eyebrowse) (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." - (if (and (bound-and-true-p eyebrowse-mode) - (< 1 (length (eyebrowse--get 'window-configs)))) - (let* ((num (eyebrowse--get 'current-slot)) - (tag (when num (nth 2 (assoc num (eyebrowse--get 'window-configs))))) - (str (if (and tag (< 0 (length tag))) - tag - (when num (int-to-string num))))) - (propertize (format "%s " str) 'face 'doom-modeline-eyebrowse)) - "")) + (if (and (bound-and-true-p eyebrowse-mode) + (< 1 (length (eyebrowse--get 'window-configs)))) + (let* ((num (eyebrowse--get 'current-slot)) + (tag (when num (nth 2 (assoc num (eyebrowse--get 'window-configs))))) + (str (if (and tag (< 0 (length tag))) + tag + (when num (int-to-string num))))) + (propertize (format "%s " str) 'face 'doom-modeline-eyebrowse)) + "")) ;; ;; Mode lines From 872287147bc5b4e1828f963ad99bcddfb183ab69 Mon Sep 17 00:00:00 2001 From: Justin Smestad Date: Fri, 15 Jun 2018 09:18:51 -0600 Subject: [PATCH 05/28] Update use-package definition * Instead of overriding `:init` handler, use `:hook` instead. * Add `:requires` (can also be `:after` if you prefer that) * Adding `all-the-icons` to the handler causes the package to not load, not sure why. * Add example with use-package to install dependencies --- README.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 46c38e2..4321e46 100644 --- a/README.md +++ b/README.md @@ -33,12 +33,23 @@ In `init.el`, (use-package doom-modeline :ensure t :defer t - :init (add-hook 'after-init-hook #'doom-modeline-init)) + :requires (shrink-path eldoc-eval) + :hook (after-init . doom-modeline-init)) ``` + + This package requires the fonts included with `all-the-icons` to be installed. Run `M-x all-the-icons-install-fonts` to do so. +If you do not have them already installed, here are the dependencies: + +``` emacs-lisp +(use-package shrink-path) +(use-package all-the-icons) +(use-package eldoc-eval) +``` + ## Screenshots ![modeline](https://github.com/hlissner/doom-emacs/raw/screenshots/ml.png) From a7ada395b4eef805945464b8260c56d3f08ed4d5 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Sat, 16 Jun 2018 01:33:36 +0800 Subject: [PATCH 06/28] Fix lint errors. --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 4321e46..32fceae 100644 --- a/README.md +++ b/README.md @@ -37,8 +37,6 @@ In `init.el`, :hook (after-init . doom-modeline-init)) ``` - - This package requires the fonts included with `all-the-icons` to be installed. Run `M-x all-the-icons-install-fonts` to do so. From 03c00e84ab72a965657946fc12ab039240f19727 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Sun, 17 Jun 2018 22:49:51 +0800 Subject: [PATCH 07/28] Add GPL3 license. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 32fceae..412fc68 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # doom-modeline +[![License](http://img.shields.io/:license-gpl3-blue.svg)](http://www.gnu.org/licenses/gpl-3.0.html) + The modeline package extracted from [DOOM Emacs](https://github.com/hlissner/doom-emacs/tree/master/modules/ui/doom-modeline). It's also the part of [Centaur Emacs](https://github.com/seagle0128/.emacs.d). From 97f3e709fba2edeae33d68fe44ca37e7b8562412 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Mon, 18 Jun 2018 22:25:38 +0800 Subject: [PATCH 08/28] Format codes. --- doom-modeline.el | 372 +++++++++++++++++++++++------------------------ 1 file changed, 186 insertions(+), 186 deletions(-) diff --git a/doom-modeline.el b/doom-modeline.el index b865f23..04bb4cb 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -528,88 +528,88 @@ Example: (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." - (let ((face (if (doom-modeline--active) 'doom-modeline-buffer-path))) - (concat (if (display-graphic-p) " ") - (doom-modeline-maybe-icon-octicon - "file-directory" - :face face - :v-adjust -0.05 - :height 1.25) - (propertize (concat " " (abbreviate-file-name default-directory)) - 'face face)))) + (let ((face (if (doom-modeline--active) 'doom-modeline-buffer-path))) + (concat (if (display-graphic-p) " ") + (doom-modeline-maybe-icon-octicon + "file-directory" + :face face + :v-adjust -0.05 + :height 1.25) + (propertize (concat " " (abbreviate-file-name default-directory)) + 'face face)))) ;; (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)." - (concat - (cond (buffer-read-only - (concat (doom-modeline-maybe-icon-octicon - "lock" - :face 'doom-modeline-warning - :v-adjust -0.05) - " ")) - ((buffer-modified-p) - (concat (doom-modeline-maybe-icon-faicon - "floppy-o" - :face 'doom-modeline-buffer-modified - :v-adjust -0.0575) - " ")) - ((and buffer-file-name - (not (file-exists-p buffer-file-name))) - (concat (doom-modeline-maybe-icon-octicon - "circle-slash" - :face 'doom-modeline-urgent - :v-adjust -0.05) - " ")) - ((buffer-narrowed-p) - (concat (doom-modeline-maybe-icon-octicon - "fold" - :face 'doom-modeline-warning - :v-adjust -0.05) - " "))) - (if buffer-file-name - (doom-modeline-buffer-file-name) - "%b"))) + (concat + (cond (buffer-read-only + (concat (doom-modeline-maybe-icon-octicon + "lock" + :face 'doom-modeline-warning + :v-adjust -0.05) + " ")) + ((buffer-modified-p) + (concat (doom-modeline-maybe-icon-faicon + "floppy-o" + :face 'doom-modeline-buffer-modified + :v-adjust -0.0575) + " ")) + ((and buffer-file-name + (not (file-exists-p buffer-file-name))) + (concat (doom-modeline-maybe-icon-octicon + "circle-slash" + :face 'doom-modeline-urgent + :v-adjust -0.05) + " ")) + ((buffer-narrowed-p) + (concat (doom-modeline-maybe-icon-octicon + "fold" + :face 'doom-modeline-warning + :v-adjust -0.05) + " "))) + (if buffer-file-name + (doom-modeline-buffer-file-name) + "%b"))) ;; (doom-modeline-def-segment! buffer-info-simple - "Display only the current buffer's name, but with fontification." - (propertize - "%b" - 'face (cond ((and buffer-file-name (buffer-modified-p)) - 'doom-modeline-buffer-modified) - ((doom-modeline--active) 'doom-modeline-buffer-file)))) + "Display only the current buffer's name, but with fontification." + (propertize + "%b" + 'face (cond ((and buffer-file-name (buffer-modified-p)) + 'doom-modeline-buffer-modified) + ((doom-modeline--active) 'doom-modeline-buffer-file)))) ;; (doom-modeline-def-segment! buffer-encoding - "Displays the encoding and eol style of the buffer the same way Atom does." - (concat (pcase (coding-system-eol-type buffer-file-coding-system) - (0 "LF ") - (1 "CRLF ") - (2 "CR ")) - (let ((sys (coding-system-plist buffer-file-coding-system))) - (cond ((memq (plist-get sys :category) '(coding-category-undecided coding-category-utf-8)) - "UTF-8") - (t (upcase (symbol-name (plist-get sys :name)))))) - " ")) + "Displays the encoding and eol style of the buffer the same way Atom does." + (concat (pcase (coding-system-eol-type buffer-file-coding-system) + (0 "LF ") + (1 "CRLF ") + (2 "CR ")) + (let ((sys (coding-system-plist buffer-file-coding-system))) + (cond ((memq (plist-get sys :category) '(coding-category-undecided coding-category-utf-8)) + "UTF-8") + (t (upcase (symbol-name (plist-get sys :name)))))) + " ")) ;; (doom-modeline-def-segment! major-mode - "The major mode, including process, environment and text-scale info." - (propertize - (concat (format-mode-line mode-name) - (when (stringp mode-line-process) - mode-line-process) - (when doom-modeline-env-version - (concat " " doom-modeline-env-version)) - (and (featurep 'face-remap) - (/= text-scale-mode-amount 0) - (format " (%+d)" text-scale-mode-amount))) - 'face (if (doom-modeline--active) 'doom-modeline-buffer-major-mode))) + "The major mode, including process, environment and text-scale info." + (propertize + (concat (format-mode-line mode-name) + (when (stringp mode-line-process) + mode-line-process) + (when doom-modeline-env-version + (concat " " doom-modeline-env-version)) + (and (featurep 'face-remap) + (/= text-scale-mode-amount 0) + (format " (%+d)" text-scale-mode-amount))) + 'face (if (doom-modeline--active) 'doom-modeline-buffer-major-mode))) (defun doom-modeline-maybe-icon-octicon (&rest args) @@ -626,39 +626,39 @@ directory, the file name, and its state (modified, read-only or non-existent)." ;; (doom-modeline-def-segment! vcs - "Displays the current branch, colored based on its state." - (when (and vc-mode buffer-file-name) - (let* ((backend (vc-backend buffer-file-name)) - (state (vc-state buffer-file-name backend))) - (let ((face 'mode-line-inactive) - (active (doom-modeline--active)) - (all-the-icons-default-adjust -0.1)) - (concat (if (display-graphic-p) " ") - (cond ((memq state '(edited added)) - (if active (setq face 'doom-modeline-info)) - (doom-modeline-maybe-icon-octicon - "git-compare" - :face face - :v-adjust -0.05)) - ((eq state 'needs-merge) - (if active (setq face 'doom-modeline-info)) - (doom-modeline-maybe-icon-octicon "git-merge" :face face)) - ((eq state 'needs-update) - (if active (setq face 'doom-modeline-warning)) - (doom-modeline-maybe-icon-octicon "arrow-down" :face face)) - ((memq state '(removed conflict unregistered)) - (if active (setq face 'doom-modeline-urgent)) - (doom-modeline-maybe-icon-octicon "alert" :face face)) - (t - (if active (setq face 'font-lock-doc-face)) - (doom-modeline-maybe-icon-octicon - "git-branch" - :face face - :v-adjust -0.05))) - " " - (propertize (substring vc-mode (+ (if (eq backend 'Hg) 2 3) 2)) - 'face (if active face)) - " "))))) + "Displays the current branch, colored based on its state." + (when (and vc-mode buffer-file-name) + (let* ((backend (vc-backend buffer-file-name)) + (state (vc-state buffer-file-name backend))) + (let ((face 'mode-line-inactive) + (active (doom-modeline--active)) + (all-the-icons-default-adjust -0.1)) + (concat (if (display-graphic-p) " ") + (cond ((memq state '(edited added)) + (if active (setq face 'doom-modeline-info)) + (doom-modeline-maybe-icon-octicon + "git-compare" + :face face + :v-adjust -0.05)) + ((eq state 'needs-merge) + (if active (setq face 'doom-modeline-info)) + (doom-modeline-maybe-icon-octicon "git-merge" :face face)) + ((eq state 'needs-update) + (if active (setq face 'doom-modeline-warning)) + (doom-modeline-maybe-icon-octicon "arrow-down" :face face)) + ((memq state '(removed conflict unregistered)) + (if active (setq face 'doom-modeline-urgent)) + (doom-modeline-maybe-icon-octicon "alert" :face face)) + (t + (if active (setq face 'font-lock-doc-face)) + (doom-modeline-maybe-icon-octicon + "git-branch" + :face face + :v-adjust -0.05))) + " " + (propertize (substring vc-mode (+ (if (eq backend 'Hg) 2 3) 2)) + 'face (if active face)) + " "))))) ;; @@ -675,22 +675,22 @@ directory, the file name, and its state (modified, read-only or non-existent)." (if vc-mode " " " "))) (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." - (when (boundp 'flycheck-last-status-change) - (pcase flycheck-last-status-change - (`finished (if flycheck-current-errors - (let-alist (flycheck-count-errors flycheck-current-errors) - (let ((sum (+ (or .error 0) (or .warning 0)))) - (doom-modeline-icon "do_not_disturb_alt" - (number-to-string sum) - (if .error 'doom-modeline-urgent 'doom-modeline-warning) - -0.25))) - (doom-modeline-icon "check" nil 'doom-modeline-info))) - (`running (doom-modeline-icon "access_time" nil 'font-lock-doc-face -0.25)) - (`no-checker (doom-modeline-icon "sim_card_alert" "-" 'font-lock-doc-face)) - (`errored (doom-modeline-icon "sim_card_alert" "Error" 'doom-modeline-urgent)) - (`interrupted (doom-modeline-icon "pause" "Interrupted" 'font-lock-doc-face))))) + (when (boundp 'flycheck-last-status-change) + (pcase flycheck-last-status-change + (`finished (if flycheck-current-errors + (let-alist (flycheck-count-errors flycheck-current-errors) + (let ((sum (+ (or .error 0) (or .warning 0)))) + (doom-modeline-icon "do_not_disturb_alt" + (number-to-string sum) + (if .error 'doom-modeline-urgent 'doom-modeline-warning) + -0.25))) + (doom-modeline-icon "check" nil 'doom-modeline-info))) + (`running (doom-modeline-icon "access_time" nil 'font-lock-doc-face -0.25)) + (`no-checker (doom-modeline-icon "sim_card_alert" "-" 'font-lock-doc-face)) + (`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 "x" "Interrupted" 'font-lock-doc-face))))) @@ -700,25 +700,25 @@ icons." (current-column))) (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." - (when (and (doom-modeline--active) (or mark-active (eq evil-state 'visual))) - (let ((reg-beg (region-beginning)) - (reg-end (region-end))) - (propertize - (let ((lines (count-lines reg-beg (min (1+ reg-end) (point-max))))) - (cond ((or (bound-and-true-p rectangle-mark-mode) - (eq 'block evil-visual-selection)) - (let ((cols (abs (- (doom-modeline-column reg-end) - (doom-modeline-column reg-beg))))) - (format "%dx%dB" lines cols))) - ((eq 'line evil-visual-selection) - (format "%dL" lines)) - ((> lines 1) - (format "%dC %dL" (- (1+ reg-end) reg-beg) lines)) - (t - (format "%dC" (- (1+ reg-end) reg-beg))))) - 'face 'doom-modeline-highlight)))) + (when (and (doom-modeline--active) (or mark-active (eq evil-state 'visual))) + (let ((reg-beg (region-beginning)) + (reg-end (region-end))) + (propertize + (let ((lines (count-lines reg-beg (min (1+ reg-end) (point-max))))) + (cond ((or (bound-and-true-p rectangle-mark-mode) + (eq 'block evil-visual-selection)) + (let ((cols (abs (- (doom-modeline-column reg-end) + (doom-modeline-column reg-beg))))) + (format "%dx%dB" lines cols))) + ((eq 'line evil-visual-selection) + (format "%dL" lines)) + ((> lines 1) + (format "%dC %dL" (- (1+ reg-end) reg-beg) lines)) + (t + (format "%dC" (- (1+ reg-end) reg-beg))))) + 'face 'doom-modeline-highlight)))) ;; @@ -794,36 +794,36 @@ lines are selected, or the NxM dimensions of a block selection." 'face (if (doom-modeline--active) 'doom-modeline-panel)))) (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 with `evil-ex-substitute', and/or 4. The number of active `iedit' regions." - (let ((meta (concat (doom-modeline--macro-recording) - (doom-modeline--anzu) - (doom-modeline--evil-substitute) - (doom-modeline--iedit)))) - (or (and (not (equal meta "")) meta) - (if buffer-file-name " %I ")))) + (let ((meta (concat (doom-modeline--macro-recording) + (doom-modeline--anzu) + (doom-modeline--evil-substitute) + (doom-modeline--iedit)))) + (or (and (not (equal meta "")) meta) + (if buffer-file-name " %I ")))) ;; TODO Include other information (doom-modeline-def-segment! media-info - "Metadata regarding the current file, such as dimensions for images." - (cond ((eq major-mode 'image-mode) - (cl-destructuring-bind (width . height) - (image-size (image-get-display-property) :pixels) - (format " %dx%d " width height))))) + "Metadata regarding the current file, such as dimensions for images." + (cond ((eq major-mode 'image-mode) + (cl-destructuring-bind (width . height) + (image-size (image-get-display-property) :pixels) + (format " %dx%d " width height))))) (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." - (if (display-graphic-p) - (doom-modeline--make-xpm - (face-background (if (doom-modeline--active) - 'doom-modeline-bar - 'doom-modeline-inactive-bar) - nil t) - doom-modeline-height - doom-modeline-bar-width) - "")) + (if (display-graphic-p) + (doom-modeline--make-xpm + (face-background (if (doom-modeline--active) + 'doom-modeline-bar + 'doom-modeline-inactive-bar) + nil t) + doom-modeline-height + doom-modeline-bar-width) + "")) (defun doom-modeline-eyebrowse-number () (when (and (bound-and-true-p eyebrowse-mode) @@ -843,47 +843,47 @@ Returns \"\" to not break --no-window-system." (cadr minibuffer-edges))))) (doom-modeline-def-segment! persp-number - "The persp number." - (when (featurep 'persp-mode) - (when (doom-modeline-window-bottom-left-p) - (-when-let* ((persp (get-current-persp))) - (propertize - (concat - (number-to-string - (+ 1 - (cl-position - (persp-name persp) - (persp-names-current-frame-fast-ordered)))) - "." - (or (doom-modeline-eyebrowse-number) "1") - " ") - 'face 'doom-modeline-persp))))) + "The persp number." + (when (featurep 'persp-mode) + (when (doom-modeline-window-bottom-left-p) + (-when-let* ((persp (get-current-persp))) + (propertize + (concat + (number-to-string + (+ 1 + (cl-position + (persp-name persp) + (persp-names-current-frame-fast-ordered)))) + "." + (or (doom-modeline-eyebrowse-number) "1") + " ") + 'face 'doom-modeline-persp))))) (advice-add #'window-numbering-install-mode-line :override #'ignore) (advice-add #'window-numbering-clear-mode-line :override #'ignore) (doom-modeline-def-segment! window-number - (if (bound-and-true-p window-numbering-mode) - (propertize (format " %s " (window-numbering-get-number-string)) - 'face (if (doom-modeline--active) - 'doom-modeline-bar - 'doom-modeline-inactive-bar)) - "")) + (if (bound-and-true-p window-numbering-mode) + (propertize (format " %s " (window-numbering-get-number-string)) + 'face (if (doom-modeline--active) + 'doom-modeline-bar + 'doom-modeline-inactive-bar)) + "")) (declare-function eyebrowse--get 'eyebrowse) (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." - (if (and (bound-and-true-p eyebrowse-mode) - (< 1 (length (eyebrowse--get 'window-configs)))) - (let* ((num (eyebrowse--get 'current-slot)) - (tag (when num (nth 2 (assoc num (eyebrowse--get 'window-configs))))) - (str (if (and tag (< 0 (length tag))) - tag - (when num (int-to-string num))))) - (propertize (format "%s " str) 'face 'doom-modeline-eyebrowse)) - "")) + (if (and (bound-and-true-p eyebrowse-mode) + (< 1 (length (eyebrowse--get 'window-configs)))) + (let* ((num (eyebrowse--get 'current-slot)) + (tag (when num (nth 2 (assoc num (eyebrowse--get 'window-configs))))) + (str (if (and tag (< 0 (length tag))) + tag + (when num (int-to-string num))))) + (propertize (format "%s " str) 'face 'doom-modeline-eyebrowse)) + "")) ;; ;; Mode lines From c2ad2a27f38b56bac0a0b5b0603b621b3622e86b Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Tue, 19 Jun 2018 14:58:35 +0800 Subject: [PATCH 09/28] Fix warnings. --- doom-modeline.el | 51 +++++++++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/doom-modeline.el b/doom-modeline.el index 04bb4cb..737efaa 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -93,7 +93,8 @@ then it detaches itself." (add-hook ,hook #',fn ,append)))))) (defmacro doom-modeline-add-hook! (&rest args) - "A convenience macro for `add-hook'. Takes, in order: + "A convenience macro for `add-hook'. +Takes, in order: 1. Optional properties :local and/or :append, which will make the hook buffer-local or append to the list of hooks (respectively), 2. The hooks: either an unquoted major mode, an unquoted list of major-modes, @@ -110,7 +111,7 @@ Examples: (doom-modeline-add-hook! (one-mode second-mode) (setq v 5) (setq a 2)) (doom-modeline-add-hook! :append :local (one-mode second-mode) (setq v 5) (setq a 2)) Body forms can access the hook's arguments through the let-bound variable -`args'." +`ARGS'." (declare (indent defun) (debug t)) (let ((hook-fn 'add-hook) append-p local-p) @@ -141,7 +142,7 @@ Body forms can access the hook's arguments through the let-bound variable `(progn ,@(nreverse forms))))) (defmacro doom-modeline-def-segment! (name &rest forms) - "Define a modeline segment and byte compiles it." + "Define a modeline segment NAME by FORMS and byte compiles it." (declare (indent defun) (doc-string 2)) (let ((sym (intern (format "doom-modeline-segment--%s" name)))) `(progn @@ -150,7 +151,8 @@ Body forms can access the hook's arguments through the let-bound variable `(let (byte-compile-warnings) (byte-compile #',sym)))))) -(defsubst doom-modeline--prepare-modeline-segments (segments) +(defsubst doom-modeline--prepare-segments (segments) + "Prepare modeline segments `SEGMENTS'." (cl-loop for seg in segments if (stringp seg) collect seg @@ -168,8 +170,8 @@ Example: (media-info major-mode)) (doom-modeline-set-modeline 'minimal t)" (let ((sym (intern (format "doom-modeline-format--%s" name))) - (lhs-forms (doom-modeline--prepare-modeline-segments lhs)) - (rhs-forms (doom-modeline--prepare-modeline-segments rhs))) + (lhs-forms (doom-modeline--prepare-segments lhs)) + (rhs-forms (doom-modeline--prepare-segments rhs))) `(progn (defun ,sym () (let ((lhs (list ,@lhs-forms)) @@ -219,8 +221,8 @@ If STRICT-P, return nil if no project was found, otherwise return "How wide the mode-line bar should be (only respected in GUI).") (defvar doom-modeline-vspc - (propertize " " 'face 'variable-pitch) - "TODO") + "Text style with icons in mode-line." + (propertize " " 'face 'variable-pitch)) (defvar doom-modeline-buffer-file-name-style 'truncate-upto-project "Determines the style used by `doom-modeline-buffer-file-name'. @@ -324,6 +326,7 @@ active." ;; (defun doom-modeline-eldoc (text) + "Display string TEXT in the mode-line." (concat (when (display-graphic-p) (doom-modeline--make-xpm (face-background 'doom-modeline-eldoc-bar nil t) @@ -333,7 +336,7 @@ active." ;; Show eldoc in the mode-line with `eval-expression' (defun doom-modeline--show-eldoc (input) - "Display string STR in the mode-line next to minibuffer." + "Display string INPUT in the mode-line next to minibuffer." (with-current-buffer (eldoc-current-buffer) (let* ((str (and (stringp input) input)) (mode-line-format (or (and str (or (doom-modeline-eldoc str) str)) @@ -390,6 +393,7 @@ active." (defvar-local doom-modeline-env-command nil) (doom-modeline-add-hook! '(focus-in-hook find-file-hook) #'doom-modeline-update-env) (defun doom-modeline-update-env () + "Update environment for mode-line." (when doom-modeline-env-command (let* ((default-directory (doom-modeline-project-root)) (s (shell-command-to-string doom-modeline-env-command))) @@ -408,11 +412,12 @@ active." ;; (defsubst doom-modeline--active () + "If modeline is active." (eq (selected-window) doom-modeline-current-window)) ;; Inspired from `powerline's `pl/make-xpm'. (defun doom-modeline--make-xpm (color height width) - "Create an XPM bitmap." + "Create an XPM bitmap iva `COLOR', `HEIGHT' and `WIDTH'." (propertize " " 'display (let ((data (make-list height (make-list width 1))) @@ -438,7 +443,7 @@ active." 'xpm t :ascent 'center)))) (defun doom-modeline-buffer-file-name () - "Propertized `buffer-file-name' based on `doom-modeline-buffer-file-name-style'." + "Propertized variable `buffer-file-name' based on `doom-modeline-buffer-file-name-style'." (propertize (pcase doom-modeline-buffer-file-name-style (`truncate-upto-project (doom-modeline--buffer-file-name 'shrink)) @@ -456,7 +461,7 @@ active." 'help-echo buffer-file-truename)) (defun doom-modeline--buffer-file-name-truncate (&optional truncate-tail) - "Propertized `buffer-file-name' that truncates every dir along path. + "Propertized variable `buffer-file-name' that truncates every dir along path. If TRUNCATE-TAIL is t also truncate the parent directory of the file." (let ((dirs (shrink-path-prompt (file-name-directory buffer-file-truename))) (active (doom-modeline--active))) @@ -475,7 +480,7 @@ If TRUNCATE-TAIL is t also truncate the parent directory of the file." 'face (if file-faces `(:inherit ,file-faces))))))))) (defun doom-modeline--buffer-file-name-relative (&optional include-project) - "Propertized `buffer-file-name' showing directories relative to project's root only." + "Propertized variable `buffer-file-name' showing directories relative to project's root only." (let ((root (doom-modeline-project-root)) (active (doom-modeline--active))) (if (null root) @@ -491,7 +496,7 @@ If TRUNCATE-TAIL is t also truncate the parent directory of the file." 'face (if file-faces `(:inherit ,file-faces)))))))) (defun doom-modeline--buffer-file-name (truncate-project-root-parent) - "Propertized `buffer-file-name'. + "Propertized variable `buffer-file-name'. If TRUNCATE-PROJECT-ROOT-PARENT is t space will be saved by truncating it down fish-shell style. Example: @@ -613,14 +618,17 @@ directory, the file name, and its state (modified, read-only or non-existent)." (defun doom-modeline-maybe-icon-octicon (&rest args) + "Display octicon ARGS." (when (and (display-graphic-p) (not (eq system-type 'windows-nt))) (apply 'all-the-icons-octicon args))) (defun doom-modeline-maybe-icon-faicon (&rest args) + "Display fontawesome icon ARGS." (when (and (display-graphic-p) (not (eq system-type 'windows-nt))) (apply 'all-the-icons-faicon args))) (defun doom-modeline-maybe-icon-material (&rest args) + "Display material icon ARGS." (when (and (display-graphic-p) (not (eq system-type 'windows-nt))) (apply 'all-the-icons-material args))) @@ -663,8 +671,7 @@ directory, the file name, and its state (modified, read-only or non-existent)." ;; (defun doom-modeline-icon (icon &optional text face voffset) - "Displays an ICON with FACE, followed by TEXT. Uses -`all-the-icons-material' to fetch the icon." + "Display an ICON with FACE, followed by TEXT. Use `all-the-icons-material' to fetch the icon." (concat (if vc-mode " " " ") (when icon (concat @@ -696,6 +703,7 @@ icons." ;; (defsubst doom-modeline-column (pos) + "Get column of the position `POS'." (save-excursion (goto-char pos) (current-column))) @@ -734,12 +742,13 @@ lines are selected, or the NxM dimensions of a block selection." sep (doom-modeline-maybe-icon-octicon "triangle-right" :face 'doom-modeline-panel - :v-adjust -0.05)) - sep))) + :v-adjust -0.05) + sep)))) (defsubst doom-modeline--anzu () - "Show the match index and total number thereof. Requires `anzu', also -`evil-anzu' if using `evil-mode' for compatibility with `evil-search'." + "Show the match index and total number thereof. +Require `anzu', also `evil-anzu' if using `evil-mode' + for compatibility with `evil-search'." (setq anzu-cons-mode-line-p nil) (when (and anzu--state (not iedit-mode)) (propertize @@ -826,6 +835,7 @@ Returns \"\" to not break --no-window-system." "")) (defun doom-modeline-eyebrowse-number () + "The eyebrowse number." (when (and (bound-and-true-p eyebrowse-mode) (< 1 (length (eyebrowse--get 'window-configs)))) (let* ((num (eyebrowse--get 'current-slot)) @@ -836,6 +846,7 @@ Returns \"\" to not break --no-window-system." str))) (defun doom-modeline-window-bottom-left-p () + "If it's botom left of the window." (let* ((edges (window-edges)) (minibuffer-edges (window-edges (minibuffer-window)))) (and (eq 0 (car edges)) From 84e9a43bd1c507a09053a2cb5cff6e2db1580a31 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Tue, 19 Jun 2018 18:44:11 +0800 Subject: [PATCH 10/28] Merge from develop branch. --- doom-modeline.el | 297 ++++++++++++++++++----------------------------- 1 file changed, 115 insertions(+), 182 deletions(-) diff --git a/doom-modeline.el b/doom-modeline.el index 737efaa..43adee7 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -72,76 +72,7 @@ (defvar doom-modeline--transient-counter 0)) -(defmacro doom-modeline-add-transient-hook! (hook &rest forms) - "Attache transient FORMS to a HOOK. -HOOK can be a quoted hook or a sharp-quoted function (which will be advised). -These forms will be evaluated once when that function/hook is first invoked, -then it detaches itself." - (declare (indent 1)) - (let ((append (eq (car forms) :after)) - (fn (intern (format "doom-transient-hook-%s" (cl-incf doom-modeline--transient-counter))))) - `(when ,hook - (fset ',fn - (lambda (&rest _) - ,@forms - (cond ((functionp ,hook) (advice-remove ,hook #',fn)) - ((symbolp ,hook) (remove-hook ,hook #',fn))) - (unintern ',fn nil))) - (cond ((functionp ,hook) - (advice-add ,hook ,(if append :after :before) #',fn)) - ((symbolp ,hook) - (add-hook ,hook #',fn ,append)))))) - -(defmacro doom-modeline-add-hook! (&rest args) - "A convenience macro for `add-hook'. -Takes, in order: - 1. Optional properties :local and/or :append, which will make the hook - buffer-local or append to the list of hooks (respectively), - 2. The hooks: either an unquoted major mode, an unquoted list of major-modes, - a quoted hook variable or a quoted list of hook variables. If unquoted, the - hooks will be resolved by appending -hook to each symbol. - 3. A function, list of functions, or body forms to be wrapped in a lambda. -Examples: - (doom-modeline-add-hook! 'some-mode-hook 'enable-something) - (doom-modeline-add-hook! some-mode '(enable-something and-another)) - (doom-modeline-add-hook! '(one-mode-hook second-mode-hook) 'enable-something) - (doom-modeline-add-hook! (one-mode second-mode) 'enable-something) - (doom-modeline-add-hook! :append (one-mode second-mode) 'enable-something) - (doom-modeline-add-hook! :local (one-mode second-mode) 'enable-something) - (doom-modeline-add-hook! (one-mode second-mode) (setq v 5) (setq a 2)) - (doom-modeline-add-hook! :append :local (one-mode second-mode) (setq v 5) (setq a 2)) -Body forms can access the hook's arguments through the let-bound variable -`ARGS'." - (declare (indent defun) (debug t)) - (let ((hook-fn 'add-hook) - append-p local-p) - (while (keywordp (car args)) - (pcase (pop args) - (:append (setq append-p t)) - (:local (setq local-p t)) - (:remove (setq hook-fn 'remove-hook)))) - (let ((hooks (doom-modeline--resolve-hooks (pop args))) - (funcs - (let ((val (car args))) - (if (memq (car-safe val) '(quote function)) - (if (cdr-safe (cadr val)) - (cadr val) - (list (cadr val))) - (list args)))) - forms) - (dolist (fn funcs) - (setq fn (if (symbolp fn) - `(function ,fn) - `(lambda (&rest _) ,@args))) - (dolist (hook hooks) - (push (cond ((eq hook-fn 'remove-hook) - `(remove-hook ',hook ,fn ,local-p)) - (t - `(add-hook ',hook ,fn ,append-p ,local-p))) - forms))) - `(progn ,@(nreverse forms))))) - -(defmacro doom-modeline-def-segment! (name &rest forms) +(defmacro doom-modeline-def-segment (name &rest forms) "Define a modeline segment NAME by FORMS and byte compiles it." (declare (indent defun) (doc-string 2)) (let ((sym (intern (format "doom-modeline-segment--%s" name)))) @@ -159,16 +90,16 @@ Body forms can access the hook's arguments through the let-bound variable else collect (list (intern (format "doom-modeline-segment--%s" (symbol-name seg)))))) -(defmacro doom-modeline-def-modeline! (name lhs &optional rhs) +(defmacro doom-modeline-def (name lhs &optional rhs) "Define a modeline format and byte-compiles it. 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 `doom-modeline-def-segment!'. + with `doom-modeline-def-segment'. Example: - (doom-modeline-def-modeline! minimal + (doom-modeline-def minimal (bar matches \" \" buffer-info) (media-info major-mode)) - (doom-modeline-set-modeline 'minimal t)" + (doom-modeline-set 'minimal t)" (let ((sym (intern (format "doom-modeline-format--%s" name))) (lhs-forms (doom-modeline--prepare-segments lhs)) (rhs-forms (doom-modeline--prepare-segments rhs))) @@ -194,7 +125,7 @@ Throws an error if it doesn't exist." (when (functionp fn) `(:eval (,fn))))) -(defun doom-modeline-set-modeline (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." (-when-let* ((modeline (doom-modeline key))) @@ -221,8 +152,8 @@ If STRICT-P, return nil if no project was found, otherwise return "How wide the mode-line bar should be (only respected in GUI).") (defvar doom-modeline-vspc - "Text style with icons in mode-line." - (propertize " " 'face 'variable-pitch)) + (propertize " " 'face 'variable-pitch) + "Text style with icons in mode-line.") (defvar doom-modeline-buffer-file-name-style 'truncate-upto-project "Determines the style used by `doom-modeline-buffer-file-name'. @@ -351,23 +282,20 @@ active." ;; anzu and evil-anzu expose current/total state that can be displayed in the ;; mode-line. -(when (featurep 'evil-anzu) - (doom-modeline-add-transient-hook! #'evil-ex-start-search (require 'evil-anzu)) +(setq anzu-cons-mode-line-p nil + anzu-minimum-input-length 1 + anzu-search-threshold 250) - (setq anzu-cons-mode-line-p nil - anzu-minimum-input-length 1 - anzu-search-threshold 250) +;; Avoid anzu conflicts across buffers +(mapc #'make-variable-buffer-local + '(anzu--total-matched anzu--current-position anzu--state + anzu--cached-count anzu--cached-positions anzu--last-command + anzu--last-isearch-string anzu--overflow-p)) - ;; Avoid anzu conflicts across buffers - (mapc #'make-variable-buffer-local - '(anzu--total-matched anzu--current-position anzu--state - anzu--cached-count anzu--cached-positions anzu--last-command - anzu--last-isearch-string anzu--overflow-p)) - - ;; Ensure anzu state is cleared when searches & iedit are done - (add-hook 'isearch-mode-end-hook #'anzu--reset-status t) - ;; (add-hook '+evil-esc-hook #'anzu--reset-status t) - (add-hook 'iedit-mode-end-hook #'anzu--reset-status)) +;; Ensure anzu state is cleared when searches & iedit are done +(add-hook 'isearch-mode-end-hook #'anzu--reset-status t) +;; (add-hook '+evil-esc-hook #'anzu--reset-status t) +(add-hook 'iedit-mode-end-hook #'anzu--reset-status) ;; Keep `doom-modeline-current-window' up-to-date @@ -391,7 +319,8 @@ active." ;; Show version string for multi-version managers like rvm, rbenv, pyenv, etc. (defvar-local doom-modeline-env-version nil) (defvar-local doom-modeline-env-command nil) -(doom-modeline-add-hook! '(focus-in-hook find-file-hook) #'doom-modeline-update-env) +(add-hook 'focus-in-hook #'doom-modeline-update-env) +(add-hook 'find-file-hook #'doom-modeline-update-env) (defun doom-modeline-update-env () "Update environment for mode-line." (when doom-modeline-env-command @@ -404,8 +333,12 @@ active." ;; Only support python and ruby for now ;; TODO torgeir -(doom-modeline-add-hook! 'python-mode-hook (setq doom-modeline-env-command "python --version 2>&1 | cut -d' ' -f2")) -(doom-modeline-add-hook! 'ruby-mode-hook (setq doom-modeline-env-command "ruby --version 2>&1 | cut -d' ' -f2")) +(add-hook 'python-mode-hook + (lambda () + (setq doom-modeline-env-command "python --version 2>&1 | cut -d' ' -f2"))) +(add-hook 'ruby-mode-hook + (lambda () + (setq doom-modeline-env-command "ruby --version 2>&1 | cut -d' ' -f2"))) ;; ;; Modeline helpers @@ -532,7 +465,7 @@ Example: ;; -(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 buffer where knowing the current project directory is important." (let ((face (if (doom-modeline--active) 'doom-modeline-buffer-path))) @@ -547,7 +480,7 @@ buffer where knowing the current project directory is important." ;; -(doom-modeline-def-segment! buffer-info +(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 @@ -581,16 +514,16 @@ directory, the file name, and its state (modified, read-only or non-existent)." "%b"))) ;; -(doom-modeline-def-segment! buffer-info-simple - "Display only the current buffer's name, but with fontification." - (propertize - "%b" - 'face (cond ((and buffer-file-name (buffer-modified-p)) - 'doom-modeline-buffer-modified) - ((doom-modeline--active) 'doom-modeline-buffer-file)))) +(doom-modeline-def-segment buffer-info-simple + "Display only the current buffer's name, but with fontification." + (propertize + "%b" + 'face (cond ((and buffer-file-name (buffer-modified-p)) + 'doom-modeline-buffer-modified) + ((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." (concat (pcase (coding-system-eol-type buffer-file-coding-system) (0 "LF ") @@ -603,7 +536,7 @@ directory, the file name, and its state (modified, read-only or non-existent)." " ")) ;; -(doom-modeline-def-segment! major-mode +(doom-modeline-def-segment major-mode "The major mode, including process, environment and text-scale info." (propertize (concat (format-mode-line mode-name) @@ -633,7 +566,7 @@ directory, the file name, and its state (modified, read-only or non-existent)." (apply 'all-the-icons-material args))) ;; -(doom-modeline-def-segment! vcs +(doom-modeline-def-segment vcs "Displays the current branch, colored based on its state." (when (and vc-mode buffer-file-name) (let* ((backend (vc-backend buffer-file-name)) @@ -681,23 +614,23 @@ directory, the file name, and its state (modified, read-only or non-existent)." (propertize text 'face face)) (if vc-mode " " " "))) -(doom-modeline-def-segment! flycheck - "Displays color-coded flycheck error status in the current buffer with pretty +(doom-modeline-def-segment flycheck + "Displays color-coded flycheck error status in the current buffer with pretty icons." - (when (boundp 'flycheck-last-status-change) - (pcase flycheck-last-status-change - (`finished (if flycheck-current-errors - (let-alist (flycheck-count-errors flycheck-current-errors) - (let ((sum (+ (or .error 0) (or .warning 0)))) - (doom-modeline-icon "do_not_disturb_alt" - (number-to-string sum) - (if .error 'doom-modeline-urgent 'doom-modeline-warning) - -0.25))) - (doom-modeline-icon "check" nil 'doom-modeline-info))) - (`running (doom-modeline-icon "access_time" nil 'font-lock-doc-face -0.25)) - (`no-checker (doom-modeline-icon "sim_card_alert" "-" 'font-lock-doc-face)) - (`errored (doom-modeline-icon "sim_card_alert" "Error" 'doom-modeline-urgent)) - (`interrupted (doom-modeline-icon "pause" "Interrupted" 'font-lock-doc-face))))) + (when (boundp 'flycheck-last-status-change) + (pcase flycheck-last-status-change + (`finished (if flycheck-current-errors + (let-alist (flycheck-count-errors flycheck-current-errors) + (let ((sum (+ (or .error 0) (or .warning 0)))) + (doom-modeline-icon "do_not_disturb_alt" + (number-to-string sum) + (if .error 'doom-modeline-urgent 'doom-modeline-warning) + -0.25))) + (doom-modeline-icon "check" nil 'doom-modeline-info))) + (`running (doom-modeline-icon "access_time" nil 'font-lock-doc-face -0.25)) + (`no-checker (doom-modeline-icon "sim_card_alert" "-" 'font-lock-doc-face)) + (`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 "x" "Interrupted" 'font-lock-doc-face))))) @@ -707,7 +640,7 @@ icons." (save-excursion (goto-char pos) (current-column))) -(doom-modeline-def-segment! selection-info +(doom-modeline-def-segment selection-info "Information about the current selection, such as how many characters and lines are selected, or the NxM dimensions of a block selection." (when (and (doom-modeline--active) (or mark-active (eq evil-state 'visual))) @@ -802,37 +735,37 @@ Require `anzu', also `evil-anzu' if using `evil-mode' length)) 'face (if (doom-modeline--active) 'doom-modeline-panel)))) -(doom-modeline-def-segment! matches - "Displays: 1. the currently recording macro, 2. A current/total for the +(doom-modeline-def-segment matches + "Displays: 1. the currently recording macro, 2. A current/total for the 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." - (let ((meta (concat (doom-modeline--macro-recording) - (doom-modeline--anzu) - (doom-modeline--evil-substitute) - (doom-modeline--iedit)))) - (or (and (not (equal meta "")) meta) - (if buffer-file-name " %I ")))) + (let ((meta (concat (doom-modeline--macro-recording) + (doom-modeline--anzu) + (doom-modeline--evil-substitute) + (doom-modeline--iedit)))) + (or (and (not (equal meta "")) meta) + (if buffer-file-name " %I ")))) ;; TODO Include other information -(doom-modeline-def-segment! media-info - "Metadata regarding the current file, such as dimensions for images." - (cond ((eq major-mode 'image-mode) - (cl-destructuring-bind (width . height) - (image-size (image-get-display-property) :pixels) - (format " %dx%d " width height))))) +(doom-modeline-def-segment media-info + "Metadata regarding the current file, such as dimensions for images." + (cond ((eq major-mode 'image-mode) + (cl-destructuring-bind (width . height) + (image-size (image-get-display-property) :pixels) + (format " %dx%d " width height))))) -(doom-modeline-def-segment! bar - "The bar regulates the height of the mode-line in GUI Emacs. +(doom-modeline-def-segment bar + "The bar regulates the height of the mode-line in GUI Emacs. Returns \"\" to not break --no-window-system." - (if (display-graphic-p) - (doom-modeline--make-xpm - (face-background (if (doom-modeline--active) - 'doom-modeline-bar - 'doom-modeline-inactive-bar) - nil t) - doom-modeline-height - doom-modeline-bar-width) - "")) + (if (display-graphic-p) + (doom-modeline--make-xpm + (face-background (if (doom-modeline--active) + 'doom-modeline-bar + 'doom-modeline-inactive-bar) + nil t) + doom-modeline-height + doom-modeline-bar-width) + "")) (defun doom-modeline-eyebrowse-number () "The eyebrowse number." @@ -853,7 +786,7 @@ Returns \"\" to not break --no-window-system." (eq (nth 3 edges) (cadr minibuffer-edges))))) -(doom-modeline-def-segment! persp-number +(doom-modeline-def-segment persp-number "The persp number." (when (featurep 'persp-mode) (when (doom-modeline-window-bottom-left-p) @@ -874,7 +807,7 @@ Returns \"\" to not break --no-window-system." (advice-add #'window-numbering-install-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) (propertize (format " %s " (window-numbering-get-number-string)) 'face (if (doom-modeline--active) @@ -883,42 +816,42 @@ Returns \"\" to not break --no-window-system." "")) (declare-function eyebrowse--get 'eyebrowse) -(doom-modeline-def-segment! workspace-number - "The current workspace name or number. Requires `eyebrowse-mode' to be +(doom-modeline-def-segment workspace-number + "The current workspace name or number. Requires `eyebrowse-mode' to be enabled." - (if (and (bound-and-true-p eyebrowse-mode) - (< 1 (length (eyebrowse--get 'window-configs)))) - (let* ((num (eyebrowse--get 'current-slot)) - (tag (when num (nth 2 (assoc num (eyebrowse--get 'window-configs))))) - (str (if (and tag (< 0 (length tag))) - tag - (when num (int-to-string num))))) - (propertize (format "%s " str) 'face 'doom-modeline-eyebrowse)) - "")) + (if (and (bound-and-true-p eyebrowse-mode) + (< 1 (length (eyebrowse--get 'window-configs)))) + (let* ((num (eyebrowse--get 'current-slot)) + (tag (when num (nth 2 (assoc num (eyebrowse--get 'window-configs))))) + (str (if (and tag (< 0 (length tag))) + tag + (when num (int-to-string num))))) + (propertize (format "%s " str) 'face 'doom-modeline-eyebrowse)) + "")) ;; ;; Mode lines ;; -(doom-modeline-def-modeline! main - (workspace-number bar matches " " buffer-info " %l:%c %p " selection-info) - (buffer-encoding major-mode vcs flycheck)) +(doom-modeline-def main + (workspace-number bar matches " " buffer-info " %l:%c %p " selection-info) + (buffer-encoding major-mode vcs flycheck)) -(doom-modeline-def-modeline! minimal - (bar matches " " buffer-info) - (media-info major-mode)) +(doom-modeline-def minimal + (bar matches " " buffer-info) + (media-info major-mode)) -(doom-modeline-def-modeline! special - (bar matches " " buffer-info-simple " %l:%c %p " selection-info) - (buffer-encoding major-mode flycheck)) +(doom-modeline-def special + (bar matches " " buffer-info-simple " %l:%c %p " selection-info) + (buffer-encoding major-mode flycheck)) -(doom-modeline-def-modeline! project - (bar buffer-default-directory) - (major-mode)) +(doom-modeline-def project + (bar buffer-default-directory) + (major-mode)) -(doom-modeline-def-modeline! media - (bar " %b ") - (media-info major-mode)) +(doom-modeline-def media + (bar " %b ") + (media-info major-mode)) ;; ;; Bootstrap @@ -927,22 +860,22 @@ enabled." ;;;###autoload (defun doom-modeline-init () "Set the default modeline." - (doom-modeline-set-modeline 'main t) + (doom-modeline-set 'main t) ;; This scratch and messages buffer is already created and doesn't get a ;; modeline. (with-current-buffer "*Messages*" - (doom-modeline-set-modeline 'main)) + (doom-modeline-set 'main)) (with-current-buffer "*scratch*" - (doom-modeline-set-modeline 'main))) + (doom-modeline-set 'main))) (defun doom-modeline-set-special-modeline () "Set the special modeline." - (doom-modeline-set-modeline 'special)) + (doom-modeline-set 'special)) (defun doom-modeline-set-media-modeline () "Set the media modeline." - (doom-modeline-set-modeline 'media)) + (doom-modeline-set 'media)) (add-hook 'image-mode-hook #'doom-modeline-set-media-modeline) (add-hook 'org-src-mode-hook #'doom-modeline-set-special-modeline) From 63c5cde9a30908fe876bd167d8d80d9e6e91a651 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Tue, 19 Jun 2018 18:58:29 +0800 Subject: [PATCH 11/28] Fix for `evil-anzu`. --- doom-modeline.el | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/doom-modeline.el b/doom-modeline.el index 43adee7..119fc8d 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -282,20 +282,21 @@ active." ;; anzu and evil-anzu expose current/total state that can be displayed in the ;; mode-line. -(setq anzu-cons-mode-line-p nil - anzu-minimum-input-length 1 - anzu-search-threshold 250) +(when (featurep 'evil-anzu) + (setq anzu-cons-mode-line-p nil + anzu-minimum-input-length 1 + anzu-search-threshold 250) -;; Avoid anzu conflicts across buffers -(mapc #'make-variable-buffer-local - '(anzu--total-matched anzu--current-position anzu--state - anzu--cached-count anzu--cached-positions anzu--last-command - anzu--last-isearch-string anzu--overflow-p)) + ;; Avoid anzu conflicts across buffers + (mapc #'make-variable-buffer-local + '(anzu--total-matched anzu--current-position anzu--state + anzu--cached-count anzu--cached-positions anzu--last-command + anzu--last-isearch-string anzu--overflow-p)) -;; Ensure anzu state is cleared when searches & iedit are done -(add-hook 'isearch-mode-end-hook #'anzu--reset-status t) -;; (add-hook '+evil-esc-hook #'anzu--reset-status t) -(add-hook 'iedit-mode-end-hook #'anzu--reset-status) + ;; Ensure anzu state is cleared when searches & iedit are done + (add-hook 'isearch-mode-end-hook #'anzu--reset-status t) + ;; (add-hook '+evil-esc-hook #'anzu--reset-status t) + (add-hook 'iedit-mode-end-hook #'anzu--reset-status)) ;; Keep `doom-modeline-current-window' up-to-date From d3a2928efa11d1e84f96bc4cd6fea07f8a68c90e Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Tue, 19 Jun 2018 19:06:49 +0800 Subject: [PATCH 12/28] Refactor. --- doom-modeline.el | 186 +++++++++++++++++++++++------------------------ 1 file changed, 91 insertions(+), 95 deletions(-) diff --git a/doom-modeline.el b/doom-modeline.el index 119fc8d..d792162 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -90,16 +90,16 @@ else collect (list (intern (format "doom-modeline-segment--%s" (symbol-name seg)))))) -(defmacro doom-modeline-def (name lhs &optional rhs) +(defmacro doom-modeline-def-modeline (name lhs &optional rhs) "Define a modeline format and byte-compiles it. 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 `doom-modeline-def-segment'. Example: - (doom-modeline-def minimal + (doom-modeline-def-modeline minimal (bar matches \" \" buffer-info) (media-info major-mode)) - (doom-modeline-set 'minimal t)" + (doom-modeline-set-modeline 'minimal t)" (let ((sym (intern (format "doom-modeline-format--%s" name))) (lhs-forms (doom-modeline--prepare-segments lhs)) (rhs-forms (doom-modeline--prepare-segments rhs))) @@ -125,7 +125,7 @@ Throws an error if it doesn't exist." (when (functionp fn) `(:eval (,fn))))) -(defun doom-modeline-set (key &optional default) +(defun doom-modeline-set-modeline (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." (-when-let* ((modeline (doom-modeline key))) @@ -313,24 +313,6 @@ active." (advice-add #'select-window :after #'doom-modeline-set-selected-window) -;; -;; Bootstrap -;; - -;; Show version string for multi-version managers like rvm, rbenv, pyenv, etc. -(defvar-local doom-modeline-env-version nil) -(defvar-local doom-modeline-env-command nil) -(add-hook 'focus-in-hook #'doom-modeline-update-env) -(add-hook 'find-file-hook #'doom-modeline-update-env) -(defun doom-modeline-update-env () - "Update environment for mode-line." - (when doom-modeline-env-command - (let* ((default-directory (doom-modeline-project-root)) - (s (shell-command-to-string doom-modeline-env-command))) - (setq doom-modeline-env-version (if (string-match "[ \t\n\r]+\\'" s) - (replace-match "" t t s) - s))))) - ;; Only support python and ruby for now ;; TODO torgeir @@ -516,12 +498,12 @@ directory, the file name, and its state (modified, read-only or non-existent)." ;; (doom-modeline-def-segment buffer-info-simple - "Display only the current buffer's name, but with fontification." - (propertize - "%b" - 'face (cond ((and buffer-file-name (buffer-modified-p)) - 'doom-modeline-buffer-modified) - ((doom-modeline--active) 'doom-modeline-buffer-file)))) + "Display only the current buffer's name, but with fontification." + (propertize + "%b" + 'face (cond ((and buffer-file-name (buffer-modified-p)) + 'doom-modeline-buffer-modified) + ((doom-modeline--active) 'doom-modeline-buffer-file)))) ;; (doom-modeline-def-segment buffer-encoding @@ -616,22 +598,22 @@ directory, the file name, and its state (modified, read-only or non-existent)." (if vc-mode " " " "))) (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." - (when (boundp 'flycheck-last-status-change) - (pcase flycheck-last-status-change - (`finished (if flycheck-current-errors - (let-alist (flycheck-count-errors flycheck-current-errors) - (let ((sum (+ (or .error 0) (or .warning 0)))) - (doom-modeline-icon "do_not_disturb_alt" - (number-to-string sum) - (if .error 'doom-modeline-urgent 'doom-modeline-warning) - -0.25))) - (doom-modeline-icon "check" nil 'doom-modeline-info))) - (`running (doom-modeline-icon "access_time" nil 'font-lock-doc-face -0.25)) - (`no-checker (doom-modeline-icon "sim_card_alert" "-" 'font-lock-doc-face)) - (`errored (doom-modeline-icon "sim_card_alert" "Error" 'doom-modeline-urgent)) - (`interrupted (doom-modeline-icon "pause" "Interrupted" 'font-lock-doc-face))))) + (when (boundp 'flycheck-last-status-change) + (pcase flycheck-last-status-change + (`finished (if flycheck-current-errors + (let-alist (flycheck-count-errors flycheck-current-errors) + (let ((sum (+ (or .error 0) (or .warning 0)))) + (doom-modeline-icon "do_not_disturb_alt" + (number-to-string sum) + (if .error 'doom-modeline-urgent 'doom-modeline-warning) + -0.25))) + (doom-modeline-icon "check" nil 'doom-modeline-info))) + (`running (doom-modeline-icon "access_time" nil 'font-lock-doc-face -0.25)) + (`no-checker (doom-modeline-icon "sim_card_alert" "-" 'font-lock-doc-face)) + (`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 "x" "Interrupted" 'font-lock-doc-face))))) @@ -737,36 +719,36 @@ Require `anzu', also `evil-anzu' if using `evil-mode' 'face (if (doom-modeline--active) 'doom-modeline-panel)))) (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 with `evil-ex-substitute', and/or 4. The number of active `iedit' regions." - (let ((meta (concat (doom-modeline--macro-recording) - (doom-modeline--anzu) - (doom-modeline--evil-substitute) - (doom-modeline--iedit)))) - (or (and (not (equal meta "")) meta) - (if buffer-file-name " %I ")))) + (let ((meta (concat (doom-modeline--macro-recording) + (doom-modeline--anzu) + (doom-modeline--evil-substitute) + (doom-modeline--iedit)))) + (or (and (not (equal meta "")) meta) + (if buffer-file-name " %I ")))) ;; TODO Include other information (doom-modeline-def-segment media-info - "Metadata regarding the current file, such as dimensions for images." - (cond ((eq major-mode 'image-mode) - (cl-destructuring-bind (width . height) - (image-size (image-get-display-property) :pixels) - (format " %dx%d " width height))))) + "Metadata regarding the current file, such as dimensions for images." + (cond ((eq major-mode 'image-mode) + (cl-destructuring-bind (width . height) + (image-size (image-get-display-property) :pixels) + (format " %dx%d " width height))))) (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." - (if (display-graphic-p) - (doom-modeline--make-xpm - (face-background (if (doom-modeline--active) - 'doom-modeline-bar - 'doom-modeline-inactive-bar) - nil t) - doom-modeline-height - doom-modeline-bar-width) - "")) + (if (display-graphic-p) + (doom-modeline--make-xpm + (face-background (if (doom-modeline--active) + 'doom-modeline-bar + 'doom-modeline-inactive-bar) + nil t) + doom-modeline-height + doom-modeline-bar-width) + "")) (defun doom-modeline-eyebrowse-number () "The eyebrowse number." @@ -818,41 +800,41 @@ Returns \"\" to not break --no-window-system." (declare-function eyebrowse--get 'eyebrowse) (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." - (if (and (bound-and-true-p eyebrowse-mode) - (< 1 (length (eyebrowse--get 'window-configs)))) - (let* ((num (eyebrowse--get 'current-slot)) - (tag (when num (nth 2 (assoc num (eyebrowse--get 'window-configs))))) - (str (if (and tag (< 0 (length tag))) - tag - (when num (int-to-string num))))) - (propertize (format "%s " str) 'face 'doom-modeline-eyebrowse)) - "")) + (if (and (bound-and-true-p eyebrowse-mode) + (< 1 (length (eyebrowse--get 'window-configs)))) + (let* ((num (eyebrowse--get 'current-slot)) + (tag (when num (nth 2 (assoc num (eyebrowse--get 'window-configs))))) + (str (if (and tag (< 0 (length tag))) + tag + (when num (int-to-string num))))) + (propertize (format "%s " str) 'face 'doom-modeline-eyebrowse)) + "")) ;; ;; Mode lines ;; -(doom-modeline-def main - (workspace-number bar matches " " buffer-info " %l:%c %p " selection-info) - (buffer-encoding major-mode vcs flycheck)) +(doom-modeline-def-modeline main + (workspace-number bar matches " " buffer-info " %l:%c %p " selection-info) + (buffer-encoding major-mode vcs flycheck)) -(doom-modeline-def minimal - (bar matches " " buffer-info) - (media-info major-mode)) +(doom-modeline-def-modeline minimal + (bar matches " " buffer-info) + (media-info major-mode)) -(doom-modeline-def special - (bar matches " " buffer-info-simple " %l:%c %p " selection-info) - (buffer-encoding major-mode flycheck)) +(doom-modeline-def-modeline special + (bar matches " " buffer-info-simple " %l:%c %p " selection-info) + (buffer-encoding major-mode flycheck)) -(doom-modeline-def project - (bar buffer-default-directory) - (major-mode)) +(doom-modeline-def-modeline project + (bar buffer-default-directory) + (major-mode)) -(doom-modeline-def media - (bar " %b ") - (media-info major-mode)) +(doom-modeline-def-modeline media + (bar " %b ") + (media-info major-mode)) ;; ;; Bootstrap @@ -861,27 +843,41 @@ enabled." ;;;###autoload (defun doom-modeline-init () "Set the default modeline." - (doom-modeline-set 'main t) + (doom-modeline-set-modeline 'main t) ;; This scratch and messages buffer is already created and doesn't get a ;; modeline. (with-current-buffer "*Messages*" - (doom-modeline-set 'main)) + (doom-modeline-set-modeline 'main)) (with-current-buffer "*scratch*" - (doom-modeline-set 'main))) + (doom-modeline-set-modeline 'main))) (defun doom-modeline-set-special-modeline () "Set the special modeline." - (doom-modeline-set 'special)) + (doom-modeline-set-modeline 'special)) (defun doom-modeline-set-media-modeline () "Set the media modeline." - (doom-modeline-set 'media)) + (doom-modeline-set-modeline 'media)) (add-hook 'image-mode-hook #'doom-modeline-set-media-modeline) (add-hook 'org-src-mode-hook #'doom-modeline-set-special-modeline) (add-hook 'circe-mode-hook #'doom-modeline-set-special-modeline) +;; Show version string for multi-version managers like rvm, rbenv, pyenv, etc. +(defvar-local doom-modeline-env-version nil) +(defvar-local doom-modeline-env-command nil) +(add-hook 'focus-in-hook #'doom-modeline-update-env) +(add-hook 'find-file-hook #'doom-modeline-update-env) +(defun doom-modeline-update-env () + "Update environment for mode-line." + (when doom-modeline-env-command + (let* ((default-directory (doom-modeline-project-root)) + (s (shell-command-to-string doom-modeline-env-command))) + (setq doom-modeline-env-version (if (string-match "[ \t\n\r]+\\'" s) + (replace-match "" t t s) + s))))) + (provide 'doom-modeline) ;;; doom-modeline.el ends here From 8725a8276bbb74a265fcd5b3ec0c469287d79a93 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Thu, 21 Jun 2018 00:26:49 +0800 Subject: [PATCH 13/28] Silence compiler warnings. --- doom-modeline.el | 382 +++++++++++++++++++++++------------------------ 1 file changed, 191 insertions(+), 191 deletions(-) diff --git a/doom-modeline.el b/doom-modeline.el index d792162..398c879 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -166,11 +166,11 @@ relative-to-project => lisp/comint.el file-name => comint.el") ;; externs -(setq anzu--state nil) -(setq evil-mode nil) -(setq evil-state nil) -(setq evil-visual-selection nil) -(setq iedit-mode nil) +(defvar anzu--state nil) +(defvar evil-mode nil) +(defvar evil-state nil) +(defvar evil-visual-selection nil) +(defvar iedit-mode nil) ;; ;; Custom faces @@ -449,88 +449,88 @@ Example: (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." - (let ((face (if (doom-modeline--active) 'doom-modeline-buffer-path))) - (concat (if (display-graphic-p) " ") - (doom-modeline-maybe-icon-octicon - "file-directory" - :face face - :v-adjust -0.05 - :height 1.25) - (propertize (concat " " (abbreviate-file-name default-directory)) - 'face face)))) + (let ((face (if (doom-modeline--active) 'doom-modeline-buffer-path))) + (concat (if (display-graphic-p) " ") + (doom-modeline-maybe-icon-octicon + "file-directory" + :face face + :v-adjust -0.05 + :height 1.25) + (propertize (concat " " (abbreviate-file-name default-directory)) + 'face face)))) ;; (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)." - (concat - (cond (buffer-read-only - (concat (doom-modeline-maybe-icon-octicon - "lock" - :face 'doom-modeline-warning - :v-adjust -0.05) - " ")) - ((buffer-modified-p) - (concat (doom-modeline-maybe-icon-faicon - "floppy-o" - :face 'doom-modeline-buffer-modified - :v-adjust -0.0575) - " ")) - ((and buffer-file-name - (not (file-exists-p buffer-file-name))) - (concat (doom-modeline-maybe-icon-octicon - "circle-slash" - :face 'doom-modeline-urgent - :v-adjust -0.05) - " ")) - ((buffer-narrowed-p) - (concat (doom-modeline-maybe-icon-octicon - "fold" - :face 'doom-modeline-warning - :v-adjust -0.05) - " "))) - (if buffer-file-name - (doom-modeline-buffer-file-name) - "%b"))) + (concat + (cond (buffer-read-only + (concat (doom-modeline-maybe-icon-octicon + "lock" + :face 'doom-modeline-warning + :v-adjust -0.05) + " ")) + ((buffer-modified-p) + (concat (doom-modeline-maybe-icon-faicon + "floppy-o" + :face 'doom-modeline-buffer-modified + :v-adjust -0.0575) + " ")) + ((and buffer-file-name + (not (file-exists-p buffer-file-name))) + (concat (doom-modeline-maybe-icon-octicon + "circle-slash" + :face 'doom-modeline-urgent + :v-adjust -0.05) + " ")) + ((buffer-narrowed-p) + (concat (doom-modeline-maybe-icon-octicon + "fold" + :face 'doom-modeline-warning + :v-adjust -0.05) + " "))) + (if buffer-file-name + (doom-modeline-buffer-file-name) + "%b"))) ;; (doom-modeline-def-segment buffer-info-simple - "Display only the current buffer's name, but with fontification." - (propertize - "%b" - 'face (cond ((and buffer-file-name (buffer-modified-p)) - 'doom-modeline-buffer-modified) - ((doom-modeline--active) 'doom-modeline-buffer-file)))) + "Display only the current buffer's name, but with fontification." + (propertize + "%b" + 'face (cond ((and buffer-file-name (buffer-modified-p)) + 'doom-modeline-buffer-modified) + ((doom-modeline--active) 'doom-modeline-buffer-file)))) ;; (doom-modeline-def-segment buffer-encoding - "Displays the encoding and eol style of the buffer the same way Atom does." - (concat (pcase (coding-system-eol-type buffer-file-coding-system) - (0 "LF ") - (1 "CRLF ") - (2 "CR ")) - (let ((sys (coding-system-plist buffer-file-coding-system))) - (cond ((memq (plist-get sys :category) '(coding-category-undecided coding-category-utf-8)) - "UTF-8") - (t (upcase (symbol-name (plist-get sys :name)))))) - " ")) + "Displays the encoding and eol style of the buffer the same way Atom does." + (concat (pcase (coding-system-eol-type buffer-file-coding-system) + (0 "LF ") + (1 "CRLF ") + (2 "CR ")) + (let ((sys (coding-system-plist buffer-file-coding-system))) + (cond ((memq (plist-get sys :category) '(coding-category-undecided coding-category-utf-8)) + "UTF-8") + (t (upcase (symbol-name (plist-get sys :name)))))) + " ")) ;; (doom-modeline-def-segment major-mode - "The major mode, including process, environment and text-scale info." - (propertize - (concat (format-mode-line mode-name) - (when (stringp mode-line-process) - mode-line-process) - (when doom-modeline-env-version - (concat " " doom-modeline-env-version)) - (and (featurep 'face-remap) - (/= text-scale-mode-amount 0) - (format " (%+d)" text-scale-mode-amount))) - 'face (if (doom-modeline--active) 'doom-modeline-buffer-major-mode))) + "The major mode, including process, environment and text-scale info." + (propertize + (concat (format-mode-line mode-name) + (when (stringp mode-line-process) + mode-line-process) + (when doom-modeline-env-version + (concat " " doom-modeline-env-version)) + (and (featurep 'face-remap) + (/= text-scale-mode-amount 0) + (format " (%+d)" text-scale-mode-amount))) + 'face (if (doom-modeline--active) 'doom-modeline-buffer-major-mode))) (defun doom-modeline-maybe-icon-octicon (&rest args) @@ -550,39 +550,39 @@ directory, the file name, and its state (modified, read-only or non-existent)." ;; (doom-modeline-def-segment vcs - "Displays the current branch, colored based on its state." - (when (and vc-mode buffer-file-name) - (let* ((backend (vc-backend buffer-file-name)) - (state (vc-state buffer-file-name backend))) - (let ((face 'mode-line-inactive) - (active (doom-modeline--active)) - (all-the-icons-default-adjust -0.1)) - (concat (if (display-graphic-p) " ") - (cond ((memq state '(edited added)) - (if active (setq face 'doom-modeline-info)) - (doom-modeline-maybe-icon-octicon - "git-compare" - :face face - :v-adjust -0.05)) - ((eq state 'needs-merge) - (if active (setq face 'doom-modeline-info)) - (doom-modeline-maybe-icon-octicon "git-merge" :face face)) - ((eq state 'needs-update) - (if active (setq face 'doom-modeline-warning)) - (doom-modeline-maybe-icon-octicon "arrow-down" :face face)) - ((memq state '(removed conflict unregistered)) - (if active (setq face 'doom-modeline-urgent)) - (doom-modeline-maybe-icon-octicon "alert" :face face)) - (t - (if active (setq face 'font-lock-doc-face)) - (doom-modeline-maybe-icon-octicon - "git-branch" - :face face - :v-adjust -0.05))) - " " - (propertize (substring vc-mode (+ (if (eq backend 'Hg) 2 3) 2)) - 'face (if active face)) - " "))))) + "Displays the current branch, colored based on its state." + (when (and vc-mode buffer-file-name) + (let* ((backend (vc-backend buffer-file-name)) + (state (vc-state buffer-file-name backend))) + (let ((face 'mode-line-inactive) + (active (doom-modeline--active)) + (all-the-icons-default-adjust -0.1)) + (concat (if (display-graphic-p) " ") + (cond ((memq state '(edited added)) + (if active (setq face 'doom-modeline-info)) + (doom-modeline-maybe-icon-octicon + "git-compare" + :face face + :v-adjust -0.05)) + ((eq state 'needs-merge) + (if active (setq face 'doom-modeline-info)) + (doom-modeline-maybe-icon-octicon "git-merge" :face face)) + ((eq state 'needs-update) + (if active (setq face 'doom-modeline-warning)) + (doom-modeline-maybe-icon-octicon "arrow-down" :face face)) + ((memq state '(removed conflict unregistered)) + (if active (setq face 'doom-modeline-urgent)) + (doom-modeline-maybe-icon-octicon "alert" :face face)) + (t + (if active (setq face 'font-lock-doc-face)) + (doom-modeline-maybe-icon-octicon + "git-branch" + :face face + :v-adjust -0.05))) + " " + (propertize (substring vc-mode (+ (if (eq backend 'Hg) 2 3) 2)) + 'face (if active face)) + " "))))) ;; @@ -598,22 +598,22 @@ directory, the file name, and its state (modified, read-only or non-existent)." (if vc-mode " " " "))) (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." - (when (boundp 'flycheck-last-status-change) - (pcase flycheck-last-status-change - (`finished (if flycheck-current-errors - (let-alist (flycheck-count-errors flycheck-current-errors) - (let ((sum (+ (or .error 0) (or .warning 0)))) - (doom-modeline-icon "do_not_disturb_alt" - (number-to-string sum) - (if .error 'doom-modeline-urgent 'doom-modeline-warning) - -0.25))) - (doom-modeline-icon "check" nil 'doom-modeline-info))) - (`running (doom-modeline-icon "access_time" nil 'font-lock-doc-face -0.25)) - (`no-checker (doom-modeline-icon "sim_card_alert" "-" 'font-lock-doc-face)) - (`errored (doom-modeline-icon "sim_card_alert" "Error" 'doom-modeline-urgent)) - (`interrupted (doom-modeline-icon "pause" "Interrupted" 'font-lock-doc-face))))) + (when (boundp 'flycheck-last-status-change) + (pcase flycheck-last-status-change + (`finished (if flycheck-current-errors + (let-alist (flycheck-count-errors flycheck-current-errors) + (let ((sum (+ (or .error 0) (or .warning 0)))) + (doom-modeline-icon "do_not_disturb_alt" + (number-to-string sum) + (if .error 'doom-modeline-urgent 'doom-modeline-warning) + -0.25))) + (doom-modeline-icon "check" nil 'doom-modeline-info))) + (`running (doom-modeline-icon "access_time" nil 'font-lock-doc-face -0.25)) + (`no-checker (doom-modeline-icon "sim_card_alert" "-" 'font-lock-doc-face)) + (`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 "x" "Interrupted" 'font-lock-doc-face))))) @@ -624,25 +624,25 @@ icons." (current-column))) (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." - (when (and (doom-modeline--active) (or mark-active (eq evil-state 'visual))) - (let ((reg-beg (region-beginning)) - (reg-end (region-end))) - (propertize - (let ((lines (count-lines reg-beg (min (1+ reg-end) (point-max))))) - (cond ((or (bound-and-true-p rectangle-mark-mode) - (eq 'block evil-visual-selection)) - (let ((cols (abs (- (doom-modeline-column reg-end) - (doom-modeline-column reg-beg))))) - (format "%dx%dB" lines cols))) - ((eq 'line evil-visual-selection) - (format "%dL" lines)) - ((> lines 1) - (format "%dC %dL" (- (1+ reg-end) reg-beg) lines)) - (t - (format "%dC" (- (1+ reg-end) reg-beg))))) - 'face 'doom-modeline-highlight)))) + (when (and (doom-modeline--active) (or mark-active (eq evil-state 'visual))) + (let ((reg-beg (region-beginning)) + (reg-end (region-end))) + (propertize + (let ((lines (count-lines reg-beg (min (1+ reg-end) (point-max))))) + (cond ((or (bound-and-true-p rectangle-mark-mode) + (eq 'block evil-visual-selection)) + (let ((cols (abs (- (doom-modeline-column reg-end) + (doom-modeline-column reg-beg))))) + (format "%dx%dB" lines cols))) + ((eq 'line evil-visual-selection) + (format "%dL" lines)) + ((> lines 1) + (format "%dC %dL" (- (1+ reg-end) reg-beg) lines)) + (t + (format "%dC" (- (1+ reg-end) reg-beg))))) + 'face 'doom-modeline-highlight)))) ;; @@ -719,36 +719,36 @@ Require `anzu', also `evil-anzu' if using `evil-mode' 'face (if (doom-modeline--active) 'doom-modeline-panel)))) (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 with `evil-ex-substitute', and/or 4. The number of active `iedit' regions." - (let ((meta (concat (doom-modeline--macro-recording) - (doom-modeline--anzu) - (doom-modeline--evil-substitute) - (doom-modeline--iedit)))) - (or (and (not (equal meta "")) meta) - (if buffer-file-name " %I ")))) + (let ((meta (concat (doom-modeline--macro-recording) + (doom-modeline--anzu) + (doom-modeline--evil-substitute) + (doom-modeline--iedit)))) + (or (and (not (equal meta "")) meta) + (if buffer-file-name " %I ")))) ;; TODO Include other information (doom-modeline-def-segment media-info - "Metadata regarding the current file, such as dimensions for images." - (cond ((eq major-mode 'image-mode) - (cl-destructuring-bind (width . height) - (image-size (image-get-display-property) :pixels) - (format " %dx%d " width height))))) + "Metadata regarding the current file, such as dimensions for images." + (cond ((eq major-mode 'image-mode) + (cl-destructuring-bind (width . height) + (image-size (image-get-display-property) :pixels) + (format " %dx%d " width height))))) (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." - (if (display-graphic-p) - (doom-modeline--make-xpm - (face-background (if (doom-modeline--active) - 'doom-modeline-bar - 'doom-modeline-inactive-bar) - nil t) - doom-modeline-height - doom-modeline-bar-width) - "")) + (if (display-graphic-p) + (doom-modeline--make-xpm + (face-background (if (doom-modeline--active) + 'doom-modeline-bar + 'doom-modeline-inactive-bar) + nil t) + doom-modeline-height + doom-modeline-bar-width) + "")) (defun doom-modeline-eyebrowse-number () "The eyebrowse number." @@ -770,47 +770,47 @@ Returns \"\" to not break --no-window-system." (cadr minibuffer-edges))))) (doom-modeline-def-segment persp-number - "The persp number." - (when (featurep 'persp-mode) - (when (doom-modeline-window-bottom-left-p) - (-when-let* ((persp (get-current-persp))) - (propertize - (concat - (number-to-string - (+ 1 - (cl-position - (persp-name persp) - (persp-names-current-frame-fast-ordered)))) - "." - (or (doom-modeline-eyebrowse-number) "1") - " ") - 'face 'doom-modeline-persp))))) + "The persp number." + (when (featurep 'persp-mode) + (when (doom-modeline-window-bottom-left-p) + (-when-let* ((persp (get-current-persp))) + (propertize + (concat + (number-to-string + (+ 1 + (cl-position + (persp-name persp) + (persp-names-current-frame-fast-ordered)))) + "." + (or (doom-modeline-eyebrowse-number) "1") + " ") + 'face 'doom-modeline-persp))))) (advice-add #'window-numbering-install-mode-line :override #'ignore) (advice-add #'window-numbering-clear-mode-line :override #'ignore) (doom-modeline-def-segment window-number - (if (bound-and-true-p window-numbering-mode) - (propertize (format " %s " (window-numbering-get-number-string)) - 'face (if (doom-modeline--active) - 'doom-modeline-bar - 'doom-modeline-inactive-bar)) - "")) + (if (bound-and-true-p window-numbering-mode) + (propertize (format " %s " (window-numbering-get-number-string)) + 'face (if (doom-modeline--active) + 'doom-modeline-bar + 'doom-modeline-inactive-bar)) + "")) (declare-function eyebrowse--get 'eyebrowse) (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." - (if (and (bound-and-true-p eyebrowse-mode) - (< 1 (length (eyebrowse--get 'window-configs)))) - (let* ((num (eyebrowse--get 'current-slot)) - (tag (when num (nth 2 (assoc num (eyebrowse--get 'window-configs))))) - (str (if (and tag (< 0 (length tag))) - tag - (when num (int-to-string num))))) - (propertize (format "%s " str) 'face 'doom-modeline-eyebrowse)) - "")) + (if (and (bound-and-true-p eyebrowse-mode) + (< 1 (length (eyebrowse--get 'window-configs)))) + (let* ((num (eyebrowse--get 'current-slot)) + (tag (when num (nth 2 (assoc num (eyebrowse--get 'window-configs))))) + (str (if (and tag (< 0 (length tag))) + tag + (when num (int-to-string num))))) + (propertize (format "%s " str) 'face 'doom-modeline-eyebrowse)) + "")) ;; ;; Mode lines From 8caecb23b8de287011eb52bdeabad64a3fce7b80 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Thu, 21 Jun 2018 22:27:16 +0800 Subject: [PATCH 14/28] Support version, including Python, Ruby and Golang. --- doom-modeline.el | 418 +++++++++++++++++++++++------------------------ 1 file changed, 209 insertions(+), 209 deletions(-) diff --git a/doom-modeline.el b/doom-modeline.el index 398c879..5fb89ae 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -312,16 +312,19 @@ active." (advice-add #'handle-switch-frame :after #'doom-modeline-set-selected-window) (advice-add #'select-window :after #'doom-modeline-set-selected-window) - -;; Only support python and ruby for now - -;; TODO torgeir -(add-hook 'python-mode-hook - (lambda () - (setq doom-modeline-env-command "python --version 2>&1 | cut -d' ' -f2"))) -(add-hook 'ruby-mode-hook - (lambda () - (setq doom-modeline-env-command "ruby --version 2>&1 | cut -d' ' -f2"))) +;; Show version string for multi-version managers like rvm, rbenv, pyenv, etc. +(defvar-local doom-modeline-env-version nil) +(defvar-local doom-modeline-env-command nil) +(add-hook 'focus-in-hook #'doom-modeline-update-env) +(add-hook 'find-file-hook #'doom-modeline-update-env) +(defun doom-modeline-update-env () + "Update environment for mode-line." + (when doom-modeline-env-command + (let* ((default-directory (doom-modeline-project-root)) + (s (shell-command-to-string doom-modeline-env-command))) + (setq doom-modeline-env-version (if (string-match "[ \t\n\r]+\\'" s) + (replace-match "" t t s) + s))))) ;; ;; Modeline helpers @@ -449,88 +452,88 @@ Example: (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." - (let ((face (if (doom-modeline--active) 'doom-modeline-buffer-path))) - (concat (if (display-graphic-p) " ") - (doom-modeline-maybe-icon-octicon - "file-directory" - :face face - :v-adjust -0.05 - :height 1.25) - (propertize (concat " " (abbreviate-file-name default-directory)) - 'face face)))) + (let ((face (if (doom-modeline--active) 'doom-modeline-buffer-path))) + (concat (if (display-graphic-p) " ") + (doom-modeline-maybe-icon-octicon + "file-directory" + :face face + :v-adjust -0.05 + :height 1.25) + (propertize (concat " " (abbreviate-file-name default-directory)) + 'face face)))) ;; (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)." - (concat - (cond (buffer-read-only - (concat (doom-modeline-maybe-icon-octicon - "lock" - :face 'doom-modeline-warning - :v-adjust -0.05) - " ")) - ((buffer-modified-p) - (concat (doom-modeline-maybe-icon-faicon - "floppy-o" - :face 'doom-modeline-buffer-modified - :v-adjust -0.0575) - " ")) - ((and buffer-file-name - (not (file-exists-p buffer-file-name))) - (concat (doom-modeline-maybe-icon-octicon - "circle-slash" - :face 'doom-modeline-urgent - :v-adjust -0.05) - " ")) - ((buffer-narrowed-p) - (concat (doom-modeline-maybe-icon-octicon - "fold" - :face 'doom-modeline-warning - :v-adjust -0.05) - " "))) - (if buffer-file-name - (doom-modeline-buffer-file-name) - "%b"))) + (concat + (cond (buffer-read-only + (concat (doom-modeline-maybe-icon-octicon + "lock" + :face 'doom-modeline-warning + :v-adjust -0.05) + " ")) + ((buffer-modified-p) + (concat (doom-modeline-maybe-icon-faicon + "floppy-o" + :face 'doom-modeline-buffer-modified + :v-adjust -0.0575) + " ")) + ((and buffer-file-name + (not (file-exists-p buffer-file-name))) + (concat (doom-modeline-maybe-icon-octicon + "circle-slash" + :face 'doom-modeline-urgent + :v-adjust -0.05) + " ")) + ((buffer-narrowed-p) + (concat (doom-modeline-maybe-icon-octicon + "fold" + :face 'doom-modeline-warning + :v-adjust -0.05) + " "))) + (if buffer-file-name + (doom-modeline-buffer-file-name) + "%b"))) ;; (doom-modeline-def-segment buffer-info-simple - "Display only the current buffer's name, but with fontification." - (propertize - "%b" - 'face (cond ((and buffer-file-name (buffer-modified-p)) - 'doom-modeline-buffer-modified) - ((doom-modeline--active) 'doom-modeline-buffer-file)))) + "Display only the current buffer's name, but with fontification." + (propertize + "%b" + 'face (cond ((and buffer-file-name (buffer-modified-p)) + 'doom-modeline-buffer-modified) + ((doom-modeline--active) 'doom-modeline-buffer-file)))) ;; (doom-modeline-def-segment buffer-encoding - "Displays the encoding and eol style of the buffer the same way Atom does." - (concat (pcase (coding-system-eol-type buffer-file-coding-system) - (0 "LF ") - (1 "CRLF ") - (2 "CR ")) - (let ((sys (coding-system-plist buffer-file-coding-system))) - (cond ((memq (plist-get sys :category) '(coding-category-undecided coding-category-utf-8)) - "UTF-8") - (t (upcase (symbol-name (plist-get sys :name)))))) - " ")) + "Displays the encoding and eol style of the buffer the same way Atom does." + (concat (pcase (coding-system-eol-type buffer-file-coding-system) + (0 "LF ") + (1 "CRLF ") + (2 "CR ")) + (let ((sys (coding-system-plist buffer-file-coding-system))) + (cond ((memq (plist-get sys :category) '(coding-category-undecided coding-category-utf-8)) + "UTF-8") + (t (upcase (symbol-name (plist-get sys :name)))))) + " ")) ;; (doom-modeline-def-segment major-mode - "The major mode, including process, environment and text-scale info." - (propertize - (concat (format-mode-line mode-name) - (when (stringp mode-line-process) - mode-line-process) - (when doom-modeline-env-version - (concat " " doom-modeline-env-version)) - (and (featurep 'face-remap) - (/= text-scale-mode-amount 0) - (format " (%+d)" text-scale-mode-amount))) - 'face (if (doom-modeline--active) 'doom-modeline-buffer-major-mode))) + "The major mode, including process, environment and text-scale info." + (propertize + (concat (format-mode-line mode-name) + (when (stringp mode-line-process) + mode-line-process) + (when doom-modeline-env-version + (concat " " doom-modeline-env-version)) + (and (featurep 'face-remap) + (/= text-scale-mode-amount 0) + (format " (%+d)" text-scale-mode-amount))) + 'face (if (doom-modeline--active) 'doom-modeline-buffer-major-mode))) (defun doom-modeline-maybe-icon-octicon (&rest args) @@ -550,39 +553,39 @@ directory, the file name, and its state (modified, read-only or non-existent)." ;; (doom-modeline-def-segment vcs - "Displays the current branch, colored based on its state." - (when (and vc-mode buffer-file-name) - (let* ((backend (vc-backend buffer-file-name)) - (state (vc-state buffer-file-name backend))) - (let ((face 'mode-line-inactive) - (active (doom-modeline--active)) - (all-the-icons-default-adjust -0.1)) - (concat (if (display-graphic-p) " ") - (cond ((memq state '(edited added)) - (if active (setq face 'doom-modeline-info)) - (doom-modeline-maybe-icon-octicon - "git-compare" - :face face - :v-adjust -0.05)) - ((eq state 'needs-merge) - (if active (setq face 'doom-modeline-info)) - (doom-modeline-maybe-icon-octicon "git-merge" :face face)) - ((eq state 'needs-update) - (if active (setq face 'doom-modeline-warning)) - (doom-modeline-maybe-icon-octicon "arrow-down" :face face)) - ((memq state '(removed conflict unregistered)) - (if active (setq face 'doom-modeline-urgent)) - (doom-modeline-maybe-icon-octicon "alert" :face face)) - (t - (if active (setq face 'font-lock-doc-face)) - (doom-modeline-maybe-icon-octicon - "git-branch" - :face face - :v-adjust -0.05))) - " " - (propertize (substring vc-mode (+ (if (eq backend 'Hg) 2 3) 2)) - 'face (if active face)) - " "))))) + "Displays the current branch, colored based on its state." + (when (and vc-mode buffer-file-name) + (let* ((backend (vc-backend buffer-file-name)) + (state (vc-state buffer-file-name backend))) + (let ((face 'mode-line-inactive) + (active (doom-modeline--active)) + (all-the-icons-default-adjust -0.1)) + (concat (if (display-graphic-p) " ") + (cond ((memq state '(edited added)) + (if active (setq face 'doom-modeline-info)) + (doom-modeline-maybe-icon-octicon + "git-compare" + :face face + :v-adjust -0.05)) + ((eq state 'needs-merge) + (if active (setq face 'doom-modeline-info)) + (doom-modeline-maybe-icon-octicon "git-merge" :face face)) + ((eq state 'needs-update) + (if active (setq face 'doom-modeline-warning)) + (doom-modeline-maybe-icon-octicon "arrow-down" :face face)) + ((memq state '(removed conflict unregistered)) + (if active (setq face 'doom-modeline-urgent)) + (doom-modeline-maybe-icon-octicon "alert" :face face)) + (t + (if active (setq face 'font-lock-doc-face)) + (doom-modeline-maybe-icon-octicon + "git-branch" + :face face + :v-adjust -0.05))) + " " + (propertize (substring vc-mode (+ (if (eq backend 'Hg) 2 3) 2)) + 'face (if active face)) + " "))))) ;; @@ -598,22 +601,22 @@ directory, the file name, and its state (modified, read-only or non-existent)." (if vc-mode " " " "))) (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." - (when (boundp 'flycheck-last-status-change) - (pcase flycheck-last-status-change - (`finished (if flycheck-current-errors - (let-alist (flycheck-count-errors flycheck-current-errors) - (let ((sum (+ (or .error 0) (or .warning 0)))) - (doom-modeline-icon "do_not_disturb_alt" - (number-to-string sum) - (if .error 'doom-modeline-urgent 'doom-modeline-warning) - -0.25))) - (doom-modeline-icon "check" nil 'doom-modeline-info))) - (`running (doom-modeline-icon "access_time" nil 'font-lock-doc-face -0.25)) - (`no-checker (doom-modeline-icon "sim_card_alert" "-" 'font-lock-doc-face)) - (`errored (doom-modeline-icon "sim_card_alert" "Error" 'doom-modeline-urgent)) - (`interrupted (doom-modeline-icon "pause" "Interrupted" 'font-lock-doc-face))))) + (when (boundp 'flycheck-last-status-change) + (pcase flycheck-last-status-change + (`finished (if flycheck-current-errors + (let-alist (flycheck-count-errors flycheck-current-errors) + (let ((sum (+ (or .error 0) (or .warning 0)))) + (doom-modeline-icon "do_not_disturb_alt" + (number-to-string sum) + (if .error 'doom-modeline-urgent 'doom-modeline-warning) + -0.25))) + (doom-modeline-icon "check" nil 'doom-modeline-info))) + (`running (doom-modeline-icon "access_time" nil 'font-lock-doc-face -0.25)) + (`no-checker (doom-modeline-icon "sim_card_alert" "-" 'font-lock-doc-face)) + (`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 "x" "Interrupted" 'font-lock-doc-face))))) @@ -624,25 +627,25 @@ icons." (current-column))) (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." - (when (and (doom-modeline--active) (or mark-active (eq evil-state 'visual))) - (let ((reg-beg (region-beginning)) - (reg-end (region-end))) - (propertize - (let ((lines (count-lines reg-beg (min (1+ reg-end) (point-max))))) - (cond ((or (bound-and-true-p rectangle-mark-mode) - (eq 'block evil-visual-selection)) - (let ((cols (abs (- (doom-modeline-column reg-end) - (doom-modeline-column reg-beg))))) - (format "%dx%dB" lines cols))) - ((eq 'line evil-visual-selection) - (format "%dL" lines)) - ((> lines 1) - (format "%dC %dL" (- (1+ reg-end) reg-beg) lines)) - (t - (format "%dC" (- (1+ reg-end) reg-beg))))) - 'face 'doom-modeline-highlight)))) + (when (and (doom-modeline--active) (or mark-active (eq evil-state 'visual))) + (let ((reg-beg (region-beginning)) + (reg-end (region-end))) + (propertize + (let ((lines (count-lines reg-beg (min (1+ reg-end) (point-max))))) + (cond ((or (bound-and-true-p rectangle-mark-mode) + (eq 'block evil-visual-selection)) + (let ((cols (abs (- (doom-modeline-column reg-end) + (doom-modeline-column reg-beg))))) + (format "%dx%dB" lines cols))) + ((eq 'line evil-visual-selection) + (format "%dL" lines)) + ((> lines 1) + (format "%dC %dL" (- (1+ reg-end) reg-beg) lines)) + (t + (format "%dC" (- (1+ reg-end) reg-beg))))) + 'face 'doom-modeline-highlight)))) ;; @@ -719,36 +722,36 @@ Require `anzu', also `evil-anzu' if using `evil-mode' 'face (if (doom-modeline--active) 'doom-modeline-panel)))) (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 with `evil-ex-substitute', and/or 4. The number of active `iedit' regions." - (let ((meta (concat (doom-modeline--macro-recording) - (doom-modeline--anzu) - (doom-modeline--evil-substitute) - (doom-modeline--iedit)))) - (or (and (not (equal meta "")) meta) - (if buffer-file-name " %I ")))) + (let ((meta (concat (doom-modeline--macro-recording) + (doom-modeline--anzu) + (doom-modeline--evil-substitute) + (doom-modeline--iedit)))) + (or (and (not (equal meta "")) meta) + (if buffer-file-name " %I ")))) ;; TODO Include other information (doom-modeline-def-segment media-info - "Metadata regarding the current file, such as dimensions for images." - (cond ((eq major-mode 'image-mode) - (cl-destructuring-bind (width . height) - (image-size (image-get-display-property) :pixels) - (format " %dx%d " width height))))) + "Metadata regarding the current file, such as dimensions for images." + (cond ((eq major-mode 'image-mode) + (cl-destructuring-bind (width . height) + (image-size (image-get-display-property) :pixels) + (format " %dx%d " width height))))) (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." - (if (display-graphic-p) - (doom-modeline--make-xpm - (face-background (if (doom-modeline--active) - 'doom-modeline-bar - 'doom-modeline-inactive-bar) - nil t) - doom-modeline-height - doom-modeline-bar-width) - "")) + (if (display-graphic-p) + (doom-modeline--make-xpm + (face-background (if (doom-modeline--active) + 'doom-modeline-bar + 'doom-modeline-inactive-bar) + nil t) + doom-modeline-height + doom-modeline-bar-width) + "")) (defun doom-modeline-eyebrowse-number () "The eyebrowse number." @@ -770,47 +773,47 @@ Returns \"\" to not break --no-window-system." (cadr minibuffer-edges))))) (doom-modeline-def-segment persp-number - "The persp number." - (when (featurep 'persp-mode) - (when (doom-modeline-window-bottom-left-p) - (-when-let* ((persp (get-current-persp))) - (propertize - (concat - (number-to-string - (+ 1 - (cl-position - (persp-name persp) - (persp-names-current-frame-fast-ordered)))) - "." - (or (doom-modeline-eyebrowse-number) "1") - " ") - 'face 'doom-modeline-persp))))) + "The persp number." + (when (featurep 'persp-mode) + (when (doom-modeline-window-bottom-left-p) + (-when-let* ((persp (get-current-persp))) + (propertize + (concat + (number-to-string + (+ 1 + (cl-position + (persp-name persp) + (persp-names-current-frame-fast-ordered)))) + "." + (or (doom-modeline-eyebrowse-number) "1") + " ") + 'face 'doom-modeline-persp))))) (advice-add #'window-numbering-install-mode-line :override #'ignore) (advice-add #'window-numbering-clear-mode-line :override #'ignore) (doom-modeline-def-segment window-number - (if (bound-and-true-p window-numbering-mode) - (propertize (format " %s " (window-numbering-get-number-string)) - 'face (if (doom-modeline--active) - 'doom-modeline-bar - 'doom-modeline-inactive-bar)) - "")) + (if (bound-and-true-p window-numbering-mode) + (propertize (format " %s " (window-numbering-get-number-string)) + 'face (if (doom-modeline--active) + 'doom-modeline-bar + 'doom-modeline-inactive-bar)) + "")) (declare-function eyebrowse--get 'eyebrowse) (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." - (if (and (bound-and-true-p eyebrowse-mode) - (< 1 (length (eyebrowse--get 'window-configs)))) - (let* ((num (eyebrowse--get 'current-slot)) - (tag (when num (nth 2 (assoc num (eyebrowse--get 'window-configs))))) - (str (if (and tag (< 0 (length tag))) - tag - (when num (int-to-string num))))) - (propertize (format "%s " str) 'face 'doom-modeline-eyebrowse)) - "")) + (if (and (bound-and-true-p eyebrowse-mode) + (< 1 (length (eyebrowse--get 'window-configs)))) + (let* ((num (eyebrowse--get 'current-slot)) + (tag (when num (nth 2 (assoc num (eyebrowse--get 'window-configs))))) + (str (if (and tag (< 0 (length tag))) + tag + (when num (int-to-string num))))) + (propertize (format "%s " str) 'face 'doom-modeline-eyebrowse)) + "")) ;; ;; Mode lines @@ -864,19 +867,16 @@ enabled." (add-hook 'org-src-mode-hook #'doom-modeline-set-special-modeline) (add-hook 'circe-mode-hook #'doom-modeline-set-special-modeline) -;; Show version string for multi-version managers like rvm, rbenv, pyenv, etc. -(defvar-local doom-modeline-env-version nil) -(defvar-local doom-modeline-env-command nil) -(add-hook 'focus-in-hook #'doom-modeline-update-env) -(add-hook 'find-file-hook #'doom-modeline-update-env) -(defun doom-modeline-update-env () - "Update environment for mode-line." - (when doom-modeline-env-command - (let* ((default-directory (doom-modeline-project-root)) - (s (shell-command-to-string doom-modeline-env-command))) - (setq doom-modeline-env-version (if (string-match "[ \t\n\r]+\\'" s) - (replace-match "" t t s) - s))))) +;; Versions, support Python, Ruby and Golang +(add-hook 'python-mode-hook + (lambda () + (setq doom-modeline-env-command "python --version 2>&1 | cut -d' ' -f2"))) +(add-hook 'ruby-mode-hook + (lambda () + (setq doom-modeline-env-command "ruby --version 2>&1 | cut -d' ' -f2"))) +(add-hook 'go-mode-hook + (lambda () + (setq doom-modeline-env-command "go version 2>&1 | cut -d' ' -f3 | tr -d 'go'"))) (provide 'doom-modeline) From b096fa284f57eea978d724c5e3287917f08a8bc6 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Fri, 22 Jun 2018 11:13:41 +0800 Subject: [PATCH 15/28] Format codes. --- doom-modeline.el | 378 +++++++++++++++++++++++------------------------ 1 file changed, 189 insertions(+), 189 deletions(-) diff --git a/doom-modeline.el b/doom-modeline.el index 398c879..e55a270 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -449,140 +449,140 @@ Example: (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." - (let ((face (if (doom-modeline--active) 'doom-modeline-buffer-path))) - (concat (if (display-graphic-p) " ") - (doom-modeline-maybe-icon-octicon - "file-directory" - :face face - :v-adjust -0.05 - :height 1.25) - (propertize (concat " " (abbreviate-file-name default-directory)) - 'face face)))) + (let ((face (if (doom-modeline--active) 'doom-modeline-buffer-path))) + (concat (if (display-graphic-p) " ") + (doom-modeline-maybe-icon-octicon + "file-directory" + :face face + :v-adjust -0.05 + :height 1.25) + (propertize (concat " " (abbreviate-file-name default-directory)) + 'face face)))) ;; (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)." - (concat - (cond (buffer-read-only - (concat (doom-modeline-maybe-icon-octicon - "lock" - :face 'doom-modeline-warning - :v-adjust -0.05) - " ")) - ((buffer-modified-p) - (concat (doom-modeline-maybe-icon-faicon - "floppy-o" - :face 'doom-modeline-buffer-modified - :v-adjust -0.0575) - " ")) - ((and buffer-file-name - (not (file-exists-p buffer-file-name))) - (concat (doom-modeline-maybe-icon-octicon - "circle-slash" - :face 'doom-modeline-urgent - :v-adjust -0.05) - " ")) - ((buffer-narrowed-p) - (concat (doom-modeline-maybe-icon-octicon - "fold" - :face 'doom-modeline-warning - :v-adjust -0.05) - " "))) - (if buffer-file-name - (doom-modeline-buffer-file-name) - "%b"))) + (concat + (cond (buffer-read-only + (concat (doom-modeline-maybe-icon-octicon + "lock" + :face 'doom-modeline-warning + :v-adjust -0.05) + " ")) + ((buffer-modified-p) + (concat (doom-modeline-maybe-icon-faicon + "floppy-o" + :face 'doom-modeline-buffer-modified + :v-adjust -0.0575) + " ")) + ((and buffer-file-name + (not (file-exists-p buffer-file-name))) + (concat (doom-modeline-maybe-icon-octicon + "circle-slash" + :face 'doom-modeline-urgent + :v-adjust -0.05) + " ")) + ((buffer-narrowed-p) + (concat (doom-modeline-maybe-icon-octicon + "fold" + :face 'doom-modeline-warning + :v-adjust -0.05) + " "))) + (if buffer-file-name + (doom-modeline-buffer-file-name) + "%b"))) ;; (doom-modeline-def-segment buffer-info-simple - "Display only the current buffer's name, but with fontification." - (propertize - "%b" - 'face (cond ((and buffer-file-name (buffer-modified-p)) - 'doom-modeline-buffer-modified) - ((doom-modeline--active) 'doom-modeline-buffer-file)))) + "Display only the current buffer's name, but with fontification." + (propertize + "%b" + 'face (cond ((and buffer-file-name (buffer-modified-p)) + 'doom-modeline-buffer-modified) + ((doom-modeline--active) 'doom-modeline-buffer-file)))) ;; (doom-modeline-def-segment buffer-encoding - "Displays the encoding and eol style of the buffer the same way Atom does." - (concat (pcase (coding-system-eol-type buffer-file-coding-system) - (0 "LF ") - (1 "CRLF ") - (2 "CR ")) - (let ((sys (coding-system-plist buffer-file-coding-system))) - (cond ((memq (plist-get sys :category) '(coding-category-undecided coding-category-utf-8)) - "UTF-8") - (t (upcase (symbol-name (plist-get sys :name)))))) - " ")) + "Displays the encoding and eol style of the buffer the same way Atom does." + (concat (pcase (coding-system-eol-type buffer-file-coding-system) + (0 "LF ") + (1 "CRLF ") + (2 "CR ")) + (let ((sys (coding-system-plist buffer-file-coding-system))) + (cond ((memq (plist-get sys :category) '(coding-category-undecided coding-category-utf-8)) + "UTF-8") + (t (upcase (symbol-name (plist-get sys :name)))))) + " ")) ;; (doom-modeline-def-segment major-mode - "The major mode, including process, environment and text-scale info." - (propertize - (concat (format-mode-line mode-name) - (when (stringp mode-line-process) - mode-line-process) - (when doom-modeline-env-version - (concat " " doom-modeline-env-version)) - (and (featurep 'face-remap) - (/= text-scale-mode-amount 0) - (format " (%+d)" text-scale-mode-amount))) - 'face (if (doom-modeline--active) 'doom-modeline-buffer-major-mode))) + "The major mode, including process, environment and text-scale info." + (propertize + (concat (format-mode-line mode-name) + (when (stringp mode-line-process) + mode-line-process) + (when doom-modeline-env-version + (concat " " doom-modeline-env-version)) + (and (featurep 'face-remap) + (/= text-scale-mode-amount 0) + (format " (%+d)" text-scale-mode-amount))) + 'face (if (doom-modeline--active) 'doom-modeline-buffer-major-mode))) (defun doom-modeline-maybe-icon-octicon (&rest args) "Display octicon ARGS." - (when (and (display-graphic-p) (not (eq system-type 'windows-nt))) + (when (display-graphic-p) (apply 'all-the-icons-octicon args))) (defun doom-modeline-maybe-icon-faicon (&rest args) "Display fontawesome icon ARGS." - (when (and (display-graphic-p) (not (eq system-type 'windows-nt))) + (when (display-graphic-p) (apply 'all-the-icons-faicon args))) (defun doom-modeline-maybe-icon-material (&rest args) "Display material icon ARGS." - (when (and (display-graphic-p) (not (eq system-type 'windows-nt))) + (when (display-graphic-p) (apply 'all-the-icons-material args))) ;; (doom-modeline-def-segment vcs - "Displays the current branch, colored based on its state." - (when (and vc-mode buffer-file-name) - (let* ((backend (vc-backend buffer-file-name)) - (state (vc-state buffer-file-name backend))) - (let ((face 'mode-line-inactive) - (active (doom-modeline--active)) - (all-the-icons-default-adjust -0.1)) - (concat (if (display-graphic-p) " ") - (cond ((memq state '(edited added)) - (if active (setq face 'doom-modeline-info)) - (doom-modeline-maybe-icon-octicon - "git-compare" - :face face - :v-adjust -0.05)) - ((eq state 'needs-merge) - (if active (setq face 'doom-modeline-info)) - (doom-modeline-maybe-icon-octicon "git-merge" :face face)) - ((eq state 'needs-update) - (if active (setq face 'doom-modeline-warning)) - (doom-modeline-maybe-icon-octicon "arrow-down" :face face)) - ((memq state '(removed conflict unregistered)) - (if active (setq face 'doom-modeline-urgent)) - (doom-modeline-maybe-icon-octicon "alert" :face face)) - (t - (if active (setq face 'font-lock-doc-face)) - (doom-modeline-maybe-icon-octicon - "git-branch" - :face face - :v-adjust -0.05))) - " " - (propertize (substring vc-mode (+ (if (eq backend 'Hg) 2 3) 2)) - 'face (if active face)) - " "))))) + "Displays the current branch, colored based on its state." + (when (and vc-mode buffer-file-name) + (let* ((backend (vc-backend buffer-file-name)) + (state (vc-state buffer-file-name backend))) + (let ((face 'mode-line-inactive) + (active (doom-modeline--active)) + (all-the-icons-default-adjust -0.1)) + (concat (if (display-graphic-p) " ") + (cond ((memq state '(edited added)) + (if active (setq face 'doom-modeline-info)) + (doom-modeline-maybe-icon-octicon + "git-compare" + :face face + :v-adjust -0.05)) + ((eq state 'needs-merge) + (if active (setq face 'doom-modeline-info)) + (doom-modeline-maybe-icon-octicon "git-merge" :face face)) + ((eq state 'needs-update) + (if active (setq face 'doom-modeline-warning)) + (doom-modeline-maybe-icon-octicon "arrow-down" :face face)) + ((memq state '(removed conflict unregistered)) + (if active (setq face 'doom-modeline-urgent)) + (doom-modeline-maybe-icon-octicon "alert" :face face)) + (t + (if active (setq face 'font-lock-doc-face)) + (doom-modeline-maybe-icon-octicon + "git-branch" + :face face + :v-adjust -0.05))) + " " + (propertize (substring vc-mode (+ (if (eq backend 'Hg) 2 3) 2)) + 'face (if active face)) + " "))))) ;; @@ -598,22 +598,22 @@ directory, the file name, and its state (modified, read-only or non-existent)." (if vc-mode " " " "))) (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." - (when (boundp 'flycheck-last-status-change) - (pcase flycheck-last-status-change - (`finished (if flycheck-current-errors - (let-alist (flycheck-count-errors flycheck-current-errors) - (let ((sum (+ (or .error 0) (or .warning 0)))) - (doom-modeline-icon "do_not_disturb_alt" - (number-to-string sum) - (if .error 'doom-modeline-urgent 'doom-modeline-warning) - -0.25))) - (doom-modeline-icon "check" nil 'doom-modeline-info))) - (`running (doom-modeline-icon "access_time" nil 'font-lock-doc-face -0.25)) - (`no-checker (doom-modeline-icon "sim_card_alert" "-" 'font-lock-doc-face)) - (`errored (doom-modeline-icon "sim_card_alert" "Error" 'doom-modeline-urgent)) - (`interrupted (doom-modeline-icon "pause" "Interrupted" 'font-lock-doc-face))))) + (when (boundp 'flycheck-last-status-change) + (pcase flycheck-last-status-change + (`finished (if flycheck-current-errors + (let-alist (flycheck-count-errors flycheck-current-errors) + (let ((sum (+ (or .error 0) (or .warning 0)))) + (doom-modeline-icon "do_not_disturb_alt" + (number-to-string sum) + (if .error 'doom-modeline-urgent 'doom-modeline-warning) + -0.25))) + (doom-modeline-icon "check" nil 'doom-modeline-info))) + (`running (doom-modeline-icon "access_time" nil 'font-lock-doc-face -0.25)) + (`no-checker (doom-modeline-icon "sim_card_alert" "-" 'font-lock-doc-face)) + (`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 "x" "Interrupted" 'font-lock-doc-face))))) @@ -624,25 +624,25 @@ icons." (current-column))) (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." - (when (and (doom-modeline--active) (or mark-active (eq evil-state 'visual))) - (let ((reg-beg (region-beginning)) - (reg-end (region-end))) - (propertize - (let ((lines (count-lines reg-beg (min (1+ reg-end) (point-max))))) - (cond ((or (bound-and-true-p rectangle-mark-mode) - (eq 'block evil-visual-selection)) - (let ((cols (abs (- (doom-modeline-column reg-end) - (doom-modeline-column reg-beg))))) - (format "%dx%dB" lines cols))) - ((eq 'line evil-visual-selection) - (format "%dL" lines)) - ((> lines 1) - (format "%dC %dL" (- (1+ reg-end) reg-beg) lines)) - (t - (format "%dC" (- (1+ reg-end) reg-beg))))) - 'face 'doom-modeline-highlight)))) + (when (and (doom-modeline--active) (or mark-active (eq evil-state 'visual))) + (let ((reg-beg (region-beginning)) + (reg-end (region-end))) + (propertize + (let ((lines (count-lines reg-beg (min (1+ reg-end) (point-max))))) + (cond ((or (bound-and-true-p rectangle-mark-mode) + (eq 'block evil-visual-selection)) + (let ((cols (abs (- (doom-modeline-column reg-end) + (doom-modeline-column reg-beg))))) + (format "%dx%dB" lines cols))) + ((eq 'line evil-visual-selection) + (format "%dL" lines)) + ((> lines 1) + (format "%dC %dL" (- (1+ reg-end) reg-beg) lines)) + (t + (format "%dC" (- (1+ reg-end) reg-beg))))) + 'face 'doom-modeline-highlight)))) ;; @@ -719,36 +719,36 @@ Require `anzu', also `evil-anzu' if using `evil-mode' 'face (if (doom-modeline--active) 'doom-modeline-panel)))) (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 with `evil-ex-substitute', and/or 4. The number of active `iedit' regions." - (let ((meta (concat (doom-modeline--macro-recording) - (doom-modeline--anzu) - (doom-modeline--evil-substitute) - (doom-modeline--iedit)))) - (or (and (not (equal meta "")) meta) - (if buffer-file-name " %I ")))) + (let ((meta (concat (doom-modeline--macro-recording) + (doom-modeline--anzu) + (doom-modeline--evil-substitute) + (doom-modeline--iedit)))) + (or (and (not (equal meta "")) meta) + (if buffer-file-name " %I ")))) ;; TODO Include other information (doom-modeline-def-segment media-info - "Metadata regarding the current file, such as dimensions for images." - (cond ((eq major-mode 'image-mode) - (cl-destructuring-bind (width . height) - (image-size (image-get-display-property) :pixels) - (format " %dx%d " width height))))) + "Metadata regarding the current file, such as dimensions for images." + (cond ((eq major-mode 'image-mode) + (cl-destructuring-bind (width . height) + (image-size (image-get-display-property) :pixels) + (format " %dx%d " width height))))) (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." - (if (display-graphic-p) - (doom-modeline--make-xpm - (face-background (if (doom-modeline--active) - 'doom-modeline-bar - 'doom-modeline-inactive-bar) - nil t) - doom-modeline-height - doom-modeline-bar-width) - "")) + (if (display-graphic-p) + (doom-modeline--make-xpm + (face-background (if (doom-modeline--active) + 'doom-modeline-bar + 'doom-modeline-inactive-bar) + nil t) + doom-modeline-height + doom-modeline-bar-width) + "")) (defun doom-modeline-eyebrowse-number () "The eyebrowse number." @@ -770,47 +770,47 @@ Returns \"\" to not break --no-window-system." (cadr minibuffer-edges))))) (doom-modeline-def-segment persp-number - "The persp number." - (when (featurep 'persp-mode) - (when (doom-modeline-window-bottom-left-p) - (-when-let* ((persp (get-current-persp))) - (propertize - (concat - (number-to-string - (+ 1 - (cl-position - (persp-name persp) - (persp-names-current-frame-fast-ordered)))) - "." - (or (doom-modeline-eyebrowse-number) "1") - " ") - 'face 'doom-modeline-persp))))) + "The persp number." + (when (featurep 'persp-mode) + (when (doom-modeline-window-bottom-left-p) + (-when-let* ((persp (get-current-persp))) + (propertize + (concat + (number-to-string + (+ 1 + (cl-position + (persp-name persp) + (persp-names-current-frame-fast-ordered)))) + "." + (or (doom-modeline-eyebrowse-number) "1") + " ") + 'face 'doom-modeline-persp))))) (advice-add #'window-numbering-install-mode-line :override #'ignore) (advice-add #'window-numbering-clear-mode-line :override #'ignore) (doom-modeline-def-segment window-number - (if (bound-and-true-p window-numbering-mode) - (propertize (format " %s " (window-numbering-get-number-string)) - 'face (if (doom-modeline--active) - 'doom-modeline-bar - 'doom-modeline-inactive-bar)) - "")) + (if (bound-and-true-p window-numbering-mode) + (propertize (format " %s " (window-numbering-get-number-string)) + 'face (if (doom-modeline--active) + 'doom-modeline-bar + 'doom-modeline-inactive-bar)) + "")) (declare-function eyebrowse--get 'eyebrowse) (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." - (if (and (bound-and-true-p eyebrowse-mode) - (< 1 (length (eyebrowse--get 'window-configs)))) - (let* ((num (eyebrowse--get 'current-slot)) - (tag (when num (nth 2 (assoc num (eyebrowse--get 'window-configs))))) - (str (if (and tag (< 0 (length tag))) - tag - (when num (int-to-string num))))) - (propertize (format "%s " str) 'face 'doom-modeline-eyebrowse)) - "")) + (if (and (bound-and-true-p eyebrowse-mode) + (< 1 (length (eyebrowse--get 'window-configs)))) + (let* ((num (eyebrowse--get 'current-slot)) + (tag (when num (nth 2 (assoc num (eyebrowse--get 'window-configs))))) + (str (if (and tag (< 0 (length tag))) + tag + (when num (int-to-string num))))) + (propertize (format "%s " str) 'face 'doom-modeline-eyebrowse)) + "")) ;; ;; Mode lines From ed2791caf8ebdb515f5124ca4c47cffb8bc9112f Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Fri, 22 Jun 2018 12:17:17 +0800 Subject: [PATCH 16/28] Add window number in main. --- doom-modeline.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doom-modeline.el b/doom-modeline.el index 96fa047..ffc0ead 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -820,7 +820,7 @@ enabled." ;; (doom-modeline-def-modeline main - (workspace-number bar matches " " buffer-info " %l:%c %p " selection-info) + (workspace-number window-number bar matches " " buffer-info " %l:%c %p " selection-info) (buffer-encoding major-mode vcs flycheck)) (doom-modeline-def-modeline minimal From 70cea8a5fb02431e592c1f0cd63f22165bbca564 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Fri, 22 Jun 2018 15:19:52 +0800 Subject: [PATCH 17/28] Update README. --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 412fc68..37a47ce 100644 --- a/README.md +++ b/README.md @@ -10,11 +10,13 @@ It's also the part of [Centaur Emacs](https://github.com/seagle0128/.emacs.d). The DOOM modeline was designed for minimalism, and offers: -- A match count panel (for evil-search, iedit and evil-substitute) +- A match count panel (for anzue, iedit, evil-search and evil-substitute) - An indicator for recording a macro -- Local python/ruby version in the major-mode -- A customizable mode-line height (see +doom-modeline-height) +- Local python/ruby/go version in the major-mode +- A customizable mode-line height (see doom-modeline-height) - An error/warning count segment for flycheck +- A workspace number segment for eyebrowse +- A window number segment for window-numbering ## Install From 3c031d5c47403dc5e432516baf6f1d83c8688ed1 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Mon, 25 Jun 2018 23:57:57 +0800 Subject: [PATCH 18/28] Update README. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 37a47ce..a7e33dd 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,7 @@ If you do not have them already installed, here are the dependencies: (use-package shrink-path) (use-package all-the-icons) (use-package eldoc-eval) +(use-package projectile) ``` ## Screenshots From 58e33625421228a1f45b55dcc971c4ae0a7b4152 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Wed, 27 Jun 2018 02:43:39 +0800 Subject: [PATCH 19/28] Remove dash. --- doom-modeline.el | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doom-modeline.el b/doom-modeline.el index ffc0ead..cd25ff5 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -5,7 +5,7 @@ ;; Author: Vincent Zhang ;; URL: https://github.com/seagle0128/doom-modeline ;; Version: 0.1.1 -;; Package-Requires: ((emacs "24.4") (dash "2.11.0") (all-the-icons "1.0.0") (projectile "0.10.0") (shrink-path "0.2.0") (eldoc-eval "0.1")) +;; Package-Requires: ((emacs "24.4") (all-the-icons "1.0.0") (projectile "0.10.0") (shrink-path "0.2.0") (eldoc-eval "0.1")) ;; Keywords: modeline mode-line doom ;; This file is not part of GNU Emacs. @@ -128,7 +128,7 @@ Throws an error if it doesn't exist." (defun doom-modeline-set-modeline (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." - (-when-let* ((modeline (doom-modeline key))) + (let ((modeline (doom-modeline key))) (setf (if default (default-value 'mode-line-format) (buffer-local-value 'mode-line-format (current-buffer))) @@ -303,7 +303,7 @@ active." (defvar doom-modeline-current-window (frame-selected-window)) (defun doom-modeline-set-selected-window (&rest _) "Set `doom-modeline-current-window' appropriately." - (-when-let* ((win (frame-selected-window))) + (let ((win (frame-selected-window))) (unless (minibuffer-window-active-p win) (setq doom-modeline-current-window win)))) @@ -776,7 +776,7 @@ Returns \"\" to not break --no-window-system." "The persp number." (when (featurep 'persp-mode) (when (doom-modeline-window-bottom-left-p) - (-when-let* ((persp (get-current-persp))) + (let ((persp (get-current-persp))) (propertize (concat (number-to-string From 703d928c93d2722500d582ceb17a50fd2f6bb2fc Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Wed, 27 Jun 2018 02:43:54 +0800 Subject: [PATCH 20/28] Fix exception: /0. --- doom-modeline.el | 1 + 1 file changed, 1 insertion(+) diff --git a/doom-modeline.el b/doom-modeline.el index cd25ff5..24bfba7 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -531,6 +531,7 @@ directory, the file name, and its state (modified, read-only or non-existent)." (when doom-modeline-env-version (concat " " doom-modeline-env-version)) (and (featurep 'face-remap) + (> text-scale-mode-amount 0) (/= text-scale-mode-amount 0) (format " (%+d)" text-scale-mode-amount))) 'face (if (doom-modeline--active) 'doom-modeline-buffer-major-mode))) From 6628495b6d1603de409cc1f673f3df04d78cbc09 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Wed, 27 Jun 2018 05:26:17 +0800 Subject: [PATCH 21/28] Refactor. --- doom-modeline.el | 232 +++++++++++++++++++++++++---------------------- 1 file changed, 122 insertions(+), 110 deletions(-) diff --git a/doom-modeline.el b/doom-modeline.el index 24bfba7..500a6fa 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -50,6 +50,128 @@ (require 'shrink-path) (require 'eldoc-eval) +;; +;; Variables +;; + +(defvar doom-modeline-height 29 + "How tall the mode-line should be (only respected in GUI).") + +(defvar doom-modeline-bar-width 3 + "How wide the mode-line bar should be (only respected in GUI).") + +(defvar doom-modeline-vspc + (propertize " " 'face 'variable-pitch) + "Text style with icons in mode-line.") + +(defvar doom-modeline-buffer-file-name-style 'truncate-upto-project + "Determines the style used by `doom-modeline-buffer-file-name'. +Given ~/Projects/FOSS/emacs/lisp/comint.el +truncate-upto-project => ~/P/F/emacs/lisp/comint.el +truncate-upto-root => ~/P/F/e/lisp/comint.el +truncate-all => ~/P/F/e/l/comint.el +relative-from-project => emacs/lisp/comint.el +relative-to-project => lisp/comint.el +file-name => comint.el") + +;; externs +(defvar anzu--current-position 0) +(defvar anzu--overflow-p nil) +(defvar anzu--state nil) +(defvar anzu--total-matched 0) +(defvar evil-ex-active-highlights-alist nil) +(defvar evil-ex-argument nil) +(defvar evil-ex-range nil) +(defvar evil-mode nil) +(defvar evil-state nil) +(defvar evil-visual-beginning nil) +(defvar evil-visual-end nil) +(defvar evil-visual-selection nil) +(defvar iedit-mode nil) +(defvar iedit-occurrences-overlays nil) +(defvar text-scale-mode-amount) +(defvar-local flycheck-current-errors nil) + +;; +;; Custom faces +;; + +(defgroup doom-modeline nil + "" + :group 'doom) + +(defface doom-modeline-buffer-path + '((t (:inherit mode-line-emphasis :bold t))) + "Face used for the dirname part of the buffer path." + :group 'doom-modeline) + +(defface doom-modeline-buffer-file + '((t (:inherit mode-line-buffer-id))) + "Face used for the filename part of the mode-line buffer path." + :group 'doom-modeline) + +(defface doom-modeline-buffer-modified + '((t (:inherit error :background nil :bold t))) + "Face used for the 'unsaved' symbol in the mode-line." + :group 'doom-modeline) + +(defface doom-modeline-buffer-major-mode + '((t (:inherit mode-line-emphasis :bold t))) + "Face used for the major-mode segment in the mode-line." + :group 'doom-modeline) + +(defface doom-modeline-highlight + '((t (:inherit mode-line-emphasis))) + "Face for bright segments of the mode-line." + :group 'doom-modeline) + +(defface doom-modeline-panel + '((t (:inherit mode-line-highlight))) + "Face for 'X out of Y' segments, such as `doom-modeline--anzu', `doom-modeline--evil-substitute' and +`iedit'" + :group 'doom-modeline) + +(defface doom-modeline-info + `((t (:inherit success :bold t))) + "Face for info-level messages in the modeline. Used by `*vc'." + :group 'doom-modeline) + +(defface doom-modeline-warning + `((t (:inherit warning :bold t))) + "Face for warnings in the modeline. Used by `*flycheck'" + :group 'doom-modeline) + +(defface doom-modeline-urgent + `((t (:inherit error :bold t))) + "Face for errors in the modeline. Used by `*flycheck'" + :group 'doom-modeline) + +;; Bar +(defface doom-modeline-bar '((t (:inherit highlight))) + "The face used for the left-most bar on the mode-line of an active window." + :group 'doom-modeline) + +(defface doom-modeline-eldoc-bar '((t (:inherit shadow))) + "The face used for the left-most bar on the mode-line when eldoc-eval is +active." + :group 'doom-modeline) + +(defface doom-modeline-inactive-bar '((t (:inherit warning :inverse-video t))) + "The face used for the left-most bar on the mode-line of an inactive window." + :group 'doom-modeline) + +(defface doom-modeline-persp '((t ())) + "The face used for persp number." + :group 'doom-modeline) + +(defface doom-modeline-eyebrowse '((t ())) + "The face used for eyebrowse." + :group 'doom-modeline) + +(defface doom-modeline-bracket '((t (:inherit shadow))) + "The face used for brackets around the project." + :group 'doom-modeline) + (eval-and-compile (defun doom-modeline--resolve-hooks (hooks) (cl-loop with quoted-p = (eq (car-safe hooks) 'quote) @@ -141,116 +263,6 @@ If STRICT-P, return nil if no project was found, otherwise return (let (projectile-require-project-root) (projectile-project-root))) -;; -;; Variables -;; - -(defvar doom-modeline-height 29 - "How tall the mode-line should be (only respected in GUI).") - -(defvar doom-modeline-bar-width 3 - "How wide the mode-line bar should be (only respected in GUI).") - -(defvar doom-modeline-vspc - (propertize " " 'face 'variable-pitch) - "Text style with icons in mode-line.") - -(defvar doom-modeline-buffer-file-name-style 'truncate-upto-project - "Determines the style used by `doom-modeline-buffer-file-name'. -Given ~/Projects/FOSS/emacs/lisp/comint.el -truncate-upto-project => ~/P/F/emacs/lisp/comint.el -truncate-upto-root => ~/P/F/e/lisp/comint.el -truncate-all => ~/P/F/e/l/comint.el -relative-from-project => emacs/lisp/comint.el -relative-to-project => lisp/comint.el -file-name => comint.el") - -;; externs -(defvar anzu--state nil) -(defvar evil-mode nil) -(defvar evil-state nil) -(defvar evil-visual-selection nil) -(defvar iedit-mode nil) - -;; -;; Custom faces -;; - -(defgroup doom-modeline nil - "" - :group 'doom) - -(defface doom-modeline-buffer-path - '((t (:inherit mode-line-emphasis :bold t))) - "Face used for the dirname part of the buffer path." - :group 'doom-modeline) - -(defface doom-modeline-buffer-file - '((t (:inherit mode-line-buffer-id))) - "Face used for the filename part of the mode-line buffer path." - :group 'doom-modeline) - -(defface doom-modeline-buffer-modified - '((t (:inherit error :background nil :bold t))) - "Face used for the 'unsaved' symbol in the mode-line." - :group 'doom-modeline) - -(defface doom-modeline-buffer-major-mode - '((t (:inherit mode-line-emphasis :bold t))) - "Face used for the major-mode segment in the mode-line." - :group 'doom-modeline) - -(defface doom-modeline-highlight - '((t (:inherit mode-line-emphasis))) - "Face for bright segments of the mode-line." - :group 'doom-modeline) - -(defface doom-modeline-panel - '((t (:inherit mode-line-highlight))) - "Face for 'X out of Y' segments, such as `doom-modeline--anzu', `doom-modeline--evil-substitute' and -`iedit'" - :group 'doom-modeline) - -(defface doom-modeline-info - `((t (:inherit success :bold t))) - "Face for info-level messages in the modeline. Used by `*vc'." - :group 'doom-modeline) - -(defface doom-modeline-warning - `((t (:inherit warning :bold t))) - "Face for warnings in the modeline. Used by `*flycheck'" - :group 'doom-modeline) - -(defface doom-modeline-urgent - `((t (:inherit error :bold t))) - "Face for errors in the modeline. Used by `*flycheck'" - :group 'doom-modeline) - -;; Bar -(defface doom-modeline-bar '((t (:inherit highlight))) - "The face used for the left-most bar on the mode-line of an active window." - :group 'doom-modeline) - -(defface doom-modeline-eldoc-bar '((t (:inherit shadow))) - "The face used for the left-most bar on the mode-line when eldoc-eval is -active." - :group 'doom-modeline) - -(defface doom-modeline-inactive-bar '((t (:inherit warning :inverse-video t))) - "The face used for the left-most bar on the mode-line of an inactive window." - :group 'doom-modeline) - -(defface doom-modeline-persp '((t ())) - "The face used for persp number." - :group 'doom-modeline) - -(defface doom-modeline-eyebrowse '((t ())) - "The face used for eyebrowse." - :group 'doom-modeline) - -(defface doom-modeline-bracket '((t (:inherit shadow))) - "The face used for brackets around the project." - :group 'doom-modeline) ;; ;; modeline configs From b2c187ea66e1da6f2da985f5a8ff6d1c684b0f11 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Sun, 1 Jul 2018 01:21:58 +0800 Subject: [PATCH 22/28] Fix issues according to the feedback from melpa. --- doom-modeline.el | 138 ++++++++++++++++++++++------------------------- 1 file changed, 65 insertions(+), 73 deletions(-) diff --git a/doom-modeline.el b/doom-modeline.el index 500a6fa..d9277af 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -1,12 +1,12 @@ -;;; doom-modeline.el --- A minimal modeline from DOOM Emacs. -*- lexical-binding: t; -*- +;;; doom-modeline.el --- A minimal modeline from DOOM. -*- lexical-binding: t; -*- ;; Copyright (C) 2018 Vincent Zhang ;; Author: Vincent Zhang ;; URL: https://github.com/seagle0128/doom-modeline ;; Version: 0.1.1 -;; Package-Requires: ((emacs "24.4") (all-the-icons "1.0.0") (projectile "0.10.0") (shrink-path "0.2.0") (eldoc-eval "0.1")) -;; Keywords: modeline mode-line doom +;; Package-Requires: ((emacs "24.4") (all-the-icons "1.0.0") (projectile "0.10.0") (shrink-path "0.2.0") (eldoc-eval "0.1") (dash "2.11.0")) +;; Keywords: faces ;; This file is not part of GNU Emacs. @@ -66,111 +66,100 @@ (defvar doom-modeline-buffer-file-name-style 'truncate-upto-project "Determines the style used by `doom-modeline-buffer-file-name'. -Given ~/Projects/FOSS/emacs/lisp/comint.el -truncate-upto-project => ~/P/F/emacs/lisp/comint.el -truncate-upto-root => ~/P/F/e/lisp/comint.el -truncate-all => ~/P/F/e/l/comint.el -relative-from-project => emacs/lisp/comint.el -relative-to-project => lisp/comint.el -file-name => comint.el") + + Given ~/Projects/FOSS/emacs/lisp/comint.el + truncate-upto-project => ~/P/F/emacs/lisp/comint.el + truncate-upto-root => ~/P/F/e/lisp/comint.el + truncate-all => ~/P/F/e/l/comint.el + relative-from-project => emacs/lisp/comint.el + relative-to-project => lisp/comint.el + file-name => comint.el") ;; externs -(defvar anzu--current-position 0) -(defvar anzu--overflow-p nil) -(defvar anzu--state nil) -(defvar anzu--total-matched 0) -(defvar evil-ex-active-highlights-alist nil) -(defvar evil-ex-argument nil) -(defvar evil-ex-range nil) -(defvar evil-mode nil) -(defvar evil-state nil) -(defvar evil-visual-beginning nil) -(defvar evil-visual-end nil) -(defvar evil-visual-selection nil) -(defvar iedit-mode nil) -(defvar iedit-occurrences-overlays nil) +(defvar anzu--current-position) +(defvar anzu--overflow-p) +(defvar anzu--state) +(defvar anzu--total-matched) +(defvar anzu-cons-mode-line-p) +(defvar anzu-minimum-input-length) +(defvar anzu-search-threshold) +(defvar evil-ex-active-highlights-alist) +(defvar evil-ex-argument) +(defvar evil-ex-range) +(defvar evil-mode) +(defvar evil-state) +(defvar evil-visual-beginning) +(defvar evil-visual-end) +(defvar evil-visual-selection) +(defvar flycheck-current-errors) +(defvar iedit-mode) +(defvar iedit-occurrences-overlays) (defvar text-scale-mode-amount) -(defvar-local flycheck-current-errors nil) ;; ;; Custom faces ;; (defgroup doom-modeline nil - "" - :group 'doom) + "Doom mode-line faces." + :group 'faces) (defface doom-modeline-buffer-path '((t (:inherit mode-line-emphasis :bold t))) - "Face used for the dirname part of the buffer path." - :group 'doom-modeline) + "Face used for the dirname part of the buffer path.") (defface doom-modeline-buffer-file '((t (:inherit mode-line-buffer-id))) - "Face used for the filename part of the mode-line buffer path." - :group 'doom-modeline) + "Face used for the filename part of the mode-line buffer path.") (defface doom-modeline-buffer-modified '((t (:inherit error :background nil :bold t))) - "Face used for the 'unsaved' symbol in the mode-line." - :group 'doom-modeline) + "Face used for the 'unsaved' symbol in the mode-line.") (defface doom-modeline-buffer-major-mode '((t (:inherit mode-line-emphasis :bold t))) - "Face used for the major-mode segment in the mode-line." - :group 'doom-modeline) + "Face used for the major-mode segment in the mode-line.") (defface doom-modeline-highlight '((t (:inherit mode-line-emphasis))) - "Face for bright segments of the mode-line." - :group 'doom-modeline) + "Face for bright segments of the mode-line.") (defface doom-modeline-panel '((t (:inherit mode-line-highlight))) "Face for 'X out of Y' segments, such as `doom-modeline--anzu', `doom-modeline--evil-substitute' and -`iedit'" - :group 'doom-modeline) +`iedit'") (defface doom-modeline-info `((t (:inherit success :bold t))) - "Face for info-level messages in the modeline. Used by `*vc'." - :group 'doom-modeline) + "Face for info-level messages in the modeline. Used by `*vc'.") (defface doom-modeline-warning `((t (:inherit warning :bold t))) - "Face for warnings in the modeline. Used by `*flycheck'" - :group 'doom-modeline) + "Face for warnings in the modeline. Used by `*flycheck'") (defface doom-modeline-urgent `((t (:inherit error :bold t))) - "Face for errors in the modeline. Used by `*flycheck'" - :group 'doom-modeline) + "Face for errors in the modeline. Used by `*flycheck'") ;; Bar (defface doom-modeline-bar '((t (:inherit highlight))) - "The face used for the left-most bar on the mode-line of an active window." - :group 'doom-modeline) + "The face used for the left-most bar on the mode-line of an active window.") (defface doom-modeline-eldoc-bar '((t (:inherit shadow))) "The face used for the left-most bar on the mode-line when eldoc-eval is -active." - :group 'doom-modeline) +active.") (defface doom-modeline-inactive-bar '((t (:inherit warning :inverse-video t))) - "The face used for the left-most bar on the mode-line of an inactive window." - :group 'doom-modeline) + "The face used for the left-most bar on the mode-line of an inactive window.") (defface doom-modeline-persp '((t ())) - "The face used for persp number." - :group 'doom-modeline) + "The face used for persp number.") (defface doom-modeline-eyebrowse '((t ())) - "The face used for eyebrowse." - :group 'doom-modeline) + "The face used for eyebrowse.") (defface doom-modeline-bracket '((t (:inherit shadow))) - "The face used for brackets around the project." - :group 'doom-modeline) + "The face used for brackets around the project.") (eval-and-compile (defun doom-modeline--resolve-hooks (hooks) @@ -214,10 +203,11 @@ active." (defmacro doom-modeline-def-modeline (name lhs &optional rhs) "Define a modeline format and byte-compiles it. -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 `doom-modeline-def-segment'. -Example: + + 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 `doom-modeline-def-segment'. + Example: (doom-modeline-def-modeline minimal (bar matches \" \" buffer-info) (media-info major-mode)) @@ -241,15 +231,15 @@ Example: (byte-compile #',sym)))))) (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)))) (when (functionp fn) `(:eval (,fn))))) (defun doom-modeline-set-modeline (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." + + If DEFAULT is non-nil, set the default mode-line for all buffers." (let ((modeline (doom-modeline key))) (setf (if default (default-value 'mode-line-format) @@ -258,7 +248,8 @@ If DEFAULT is non-nil, set the default mode-line for all buffers." (defun doom-modeline-project-root () "Get the path to the root of your project. -If STRICT-P, return nil if no project was found, otherwise return + + If STRICT-P, return nil if no project was found, otherwise return `default-directory'." (let (projectile-require-project-root) (projectile-project-root))) @@ -393,7 +384,8 @@ If STRICT-P, return nil if no project was found, otherwise return (defun doom-modeline--buffer-file-name-truncate (&optional truncate-tail) "Propertized variable `buffer-file-name' that truncates every dir along path. -If TRUNCATE-TAIL is t also truncate the parent directory of the file." + + If TRUNCATE-TAIL is t also truncate the parent directory of the file." (let ((dirs (shrink-path-prompt (file-name-directory buffer-file-truename))) (active (doom-modeline--active))) (if (null dirs) @@ -411,7 +403,7 @@ If TRUNCATE-TAIL is t also truncate the parent directory of the file." 'face (if file-faces `(:inherit ,file-faces))))))))) (defun doom-modeline--buffer-file-name-relative (&optional include-project) - "Propertized variable `buffer-file-name' showing directories relative to project's root only." + "Propertized variable `buffer-file-name' showing directories relative to `INCLUDE-PROJECT' root only." (let ((root (doom-modeline-project-root)) (active (doom-modeline--active))) (if (null root) @@ -428,10 +420,11 @@ If TRUNCATE-TAIL is t also truncate the parent directory of the file." (defun doom-modeline--buffer-file-name (truncate-project-root-parent) "Propertized variable `buffer-file-name'. -If TRUNCATE-PROJECT-ROOT-PARENT is t space will be saved by truncating it down + + If TRUNCATE-PROJECT-ROOT-PARENT is t space will be saved by truncating it down fish-shell style. -Example: -~/Projects/FOSS/emacs/lisp/comint.el => ~/P/F/emacs/lisp/comint.el" + Example: + ~/Projects/FOSS/emacs/lisp/comint.el => ~/P/F/emacs/lisp/comint.el" (let* ((project-root (doom-modeline-project-root)) (file-name-split (shrink-path-file-mixed project-root (file-name-directory buffer-file-truename) @@ -755,7 +748,7 @@ with `evil-ex-substitute', and/or 4. The number of active `iedit' regions." (doom-modeline-def-segment bar "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) (doom-modeline--make-xpm (face-background (if (doom-modeline--active) @@ -816,8 +809,7 @@ Returns \"\" to not break --no-window-system." (declare-function eyebrowse--get 'eyebrowse) (doom-modeline-def-segment workspace-number - "The current workspace name or number. Requires `eyebrowse-mode' to be -enabled." + "The current workspace name or number. Requires `eyebrowse-mode' to be enabled." (if (and (bound-and-true-p eyebrowse-mode) (< 1 (length (eyebrowse--get 'window-configs)))) (let* ((num (eyebrowse--get 'current-slot)) From 1b32790cba57a56b13fc864260e111e2c92df2d5 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Sun, 1 Jul 2018 01:35:07 +0800 Subject: [PATCH 23/28] Fix warnings. --- doom-modeline.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doom-modeline.el b/doom-modeline.el index d9277af..30dc1b8 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -403,7 +403,7 @@ active.") 'face (if file-faces `(:inherit ,file-faces))))))))) (defun doom-modeline--buffer-file-name-relative (&optional include-project) - "Propertized variable `buffer-file-name' showing directories relative to `INCLUDE-PROJECT' root only." + "Propertized variable `buffer-file-name' showing directories relative to INCLUDE-PROJECT root only." (let ((root (doom-modeline-project-root)) (active (doom-modeline--active))) (if (null root) From f0ddd36c905a1eac38a490ad6217a66b291dac3f Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Sun, 1 Jul 2018 02:08:39 +0800 Subject: [PATCH 24/28] Fix anzu, evil and iedit. --- doom-modeline.el | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/doom-modeline.el b/doom-modeline.el index 30dc1b8..729fedf 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -635,17 +635,21 @@ icons." (doom-modeline-def-segment selection-info "Information about the current selection, such as how many characters and lines are selected, or the NxM dimensions of a block selection." - (when (and (doom-modeline--active) (or mark-active (eq evil-state 'visual))) + (when (and (doom-modeline--active) + (or mark-active + (and (bound-and-true-p evil-state) (eq evil-state 'visual)))) (let ((reg-beg (region-beginning)) (reg-end (region-end))) (propertize (let ((lines (count-lines reg-beg (min (1+ reg-end) (point-max))))) (cond ((or (bound-and-true-p rectangle-mark-mode) - (eq 'block evil-visual-selection)) + (and (bound-and-true-p evil-visual-selection) + (eq 'block evil-visual-selection))) (let ((cols (abs (- (doom-modeline-column reg-end) (doom-modeline-column reg-beg))))) (format "%dx%dB" lines cols))) - ((eq 'line evil-visual-selection) + ((and (bound-and-true-p evil-visual-selection) + (eq evil-visual-selection 'line)) (format "%dL" lines)) ((> lines 1) (format "%dC %dL" (- (1+ reg-end) reg-beg) lines)) @@ -674,8 +678,10 @@ lines are selected, or the NxM dimensions of a block selection." "Show the match index and total number thereof. Require `anzu', also `evil-anzu' if using `evil-mode' for compatibility with `evil-search'." - (setq anzu-cons-mode-line-p nil) - (when (and anzu--state (not iedit-mode)) + (when (and (featurep 'anzu) + anzu--state + (not (bound-and-true-p iedit-mode))) + (setq anzu-cons-mode-line-p nil) (propertize (let ((here anzu--current-position) (total anzu--total-matched)) @@ -691,7 +697,8 @@ Require `anzu', also `evil-anzu' if using `evil-mode' (defsubst doom-modeline--evil-substitute () "Show number of matches for evil-ex substitutions and highlights in real time." - (when (and evil-mode + (when (and (featurep 'evil) + evil-mode (or (assq 'evil-ex-substitute evil-ex-active-highlights-alist) (assq 'evil-ex-global-match evil-ex-active-highlights-alist) (assq 'evil-ex-buffer-match evil-ex-active-highlights-alist))) @@ -710,7 +717,7 @@ Require `anzu', also `evil-anzu' if using `evil-mode' (defsubst doom-modeline--iedit () "Show the number of iedit regions matches + what match you're on." - (when (and iedit-mode iedit-occurrences-overlays) + (when (and (featurep 'iedit) iedit-mode iedit-occurrences-overlays) (propertize (let ((this-oc (or (let ((inhibit-message t)) (iedit-find-current-occurrence-overlay)) From 7e8a09765e526c5b40ce26a215f1fdcd6167b45f Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Sun, 1 Jul 2018 02:25:00 +0800 Subject: [PATCH 25/28] Add comments. --- doom-modeline.el | 1 + 1 file changed, 1 insertion(+) diff --git a/doom-modeline.el b/doom-modeline.el index 729fedf..7e3a06d 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -713,6 +713,7 @@ Require `anzu', also `evil-anzu' if using `evil-mode' 'face (if (doom-modeline--active) 'doom-modeline-panel)))) (defun doom-modeline-themes--overlay-sort (a b) + "Sort overlay A and B." (< (overlay-start a) (overlay-start b))) (defsubst doom-modeline--iedit () From b2285954c6255f49998cd58b1ea4de2398152177 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Sun, 1 Jul 2018 02:26:13 +0800 Subject: [PATCH 26/28] Fix anzu. --- doom-modeline.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doom-modeline.el b/doom-modeline.el index 7e3a06d..139adf8 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -678,10 +678,10 @@ lines are selected, or the NxM dimensions of a block selection." "Show the match index and total number thereof. Require `anzu', also `evil-anzu' if using `evil-mode' for compatibility with `evil-search'." + (setq anzu-cons-mode-line-p nil) (when (and (featurep 'anzu) anzu--state (not (bound-and-true-p iedit-mode))) - (setq anzu-cons-mode-line-p nil) (propertize (let ((here anzu--current-position) (total anzu--total-matched)) From c8e559bfb284e7d69824ad575ab80823f0446b05 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Mon, 2 Jul 2018 15:51:25 +0800 Subject: [PATCH 27/28] Update comments. --- doom-modeline.el | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/doom-modeline.el b/doom-modeline.el index 139adf8..dd2f8d5 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -67,7 +67,7 @@ (defvar doom-modeline-buffer-file-name-style 'truncate-upto-project "Determines the style used by `doom-modeline-buffer-file-name'. - Given ~/Projects/FOSS/emacs/lisp/comint.el +Given ~/Projects/FOSS/emacs/lisp/comint.el truncate-upto-project => ~/P/F/emacs/lisp/comint.el truncate-upto-root => ~/P/F/e/lisp/comint.el truncate-all => ~/P/F/e/l/comint.el @@ -204,10 +204,10 @@ active.") (defmacro doom-modeline-def-modeline (name lhs &optional rhs) "Define a modeline format and byte-compiles it. - 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 `doom-modeline-def-segment'. - Example: +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 `doom-modeline-def-segment'. +Example: (doom-modeline-def-modeline minimal (bar matches \" \" buffer-info) (media-info major-mode)) @@ -239,7 +239,7 @@ active.") (defun doom-modeline-set-modeline (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." +If DEFAULT is non-nil, set the default mode-line for all buffers." (let ((modeline (doom-modeline key))) (setf (if default (default-value 'mode-line-format) @@ -249,7 +249,7 @@ active.") (defun doom-modeline-project-root () "Get the path to the root of your project. - If STRICT-P, return nil if no project was found, otherwise return +If STRICT-P, return nil if no project was found, otherwise return `default-directory'." (let (projectile-require-project-root) (projectile-project-root))) @@ -385,7 +385,7 @@ active.") (defun doom-modeline--buffer-file-name-truncate (&optional truncate-tail) "Propertized variable `buffer-file-name' that truncates every dir along path. - If TRUNCATE-TAIL is t also truncate the parent directory of the file." +If TRUNCATE-TAIL is t also truncate the parent directory of the file." (let ((dirs (shrink-path-prompt (file-name-directory buffer-file-truename))) (active (doom-modeline--active))) (if (null dirs) @@ -421,9 +421,9 @@ active.") (defun doom-modeline--buffer-file-name (truncate-project-root-parent) "Propertized variable `buffer-file-name'. - If TRUNCATE-PROJECT-ROOT-PARENT is t space will be saved by truncating it down +If TRUNCATE-PROJECT-ROOT-PARENT is t space will be saved by truncating it down fish-shell style. - Example: +Example: ~/Projects/FOSS/emacs/lisp/comint.el => ~/P/F/emacs/lisp/comint.el" (let* ((project-root (doom-modeline-project-root)) (file-name-split (shrink-path-file-mixed project-root From 7665721db1a39111744f2ee6d2e1abb272c605f8 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Thu, 5 Jul 2018 13:56:23 +0800 Subject: [PATCH 28/28] Update README and package descriptions. --- README.md | 10 ---------- doom-modeline.el | 11 ++++++++++- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index a7e33dd..453ab17 100644 --- a/README.md +++ b/README.md @@ -37,22 +37,12 @@ In `init.el`, (use-package doom-modeline :ensure t :defer t - :requires (shrink-path eldoc-eval) :hook (after-init . doom-modeline-init)) ``` This package requires the fonts included with `all-the-icons` to be installed. Run `M-x all-the-icons-install-fonts` to do so. -If you do not have them already installed, here are the dependencies: - -``` emacs-lisp -(use-package shrink-path) -(use-package all-the-icons) -(use-package eldoc-eval) -(use-package projectile) -``` - ## Screenshots ![modeline](https://github.com/hlissner/doom-emacs/raw/screenshots/ml.png) diff --git a/doom-modeline.el b/doom-modeline.el index dd2f8d5..730deb6 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -31,7 +31,6 @@ ;; ;; This package offers a modern modeline them which is extraced from DOOM Emacs ;; (https://github.com/hlissner/doom-emacs/tree/master/modules/ui/doom-modeline). -;; ;; It's also the part of Centaur Emacs (https://github.com/seagle0128/.emacs.d). ;; ;; The DOOM modeline was designed for minimalism, and offers: @@ -41,6 +40,16 @@ ;; 4. A customizable mode-line height (see doom-modeline-height) ;; 5. An error/warning count segment for flycheck ;; +;; Installation: +;; From melpa, `M-x package-install RET doom-modeline RET`. +;; In `init.el`, +;; (require 'doom-modeline) +;; (doom-modeline-init) +;; or +;; (use-package doom-modeline +;; :ensure t +;; :defer t +;; :hook (after-init . doom-modeline-init)) ;;; Code: