From ababcb464ff03860f80b8e4c832a522e7bfeb5ae Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Wed, 13 Jun 2018 20:43:03 +0800 Subject: [PATCH 01/52] Merge from develop branch of doom-theme. --- doom-modeline.el | 577 ++++++++++++++++++++++++++--------------------- 1 file changed, 321 insertions(+), 256 deletions(-) diff --git a/doom-modeline.el b/doom-modeline.el index bb16df9..91b7040 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -4,7 +4,7 @@ ;; Author: Vincent Zhang ;; URL: https://github.com/seagle0128/doom-modeline -;; Version: 0.1.1 +;; Version: 0.2.0 ;; 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")) ;; Keywords: modeline mode-line doom @@ -237,13 +237,23 @@ If STRICT-P, return nil if no project was found, otherwise return ;; 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)) +(when (featurep 'anzu) (setq anzu-cons-mode-line-p nil anzu-minimum-input-length 1 anzu-search-threshold 250) + (defun doom-modeline-fix-anzu-count (positions here) + (cl-loop for (start . end) in positions + collect t into before + when (and (>= here start) (<= here end)) + return (length before) + finally return 0)) + (advice-add #'anzu--where-is-here :override #'doom-modeline-fix-anzu-count)) + +(when (featurep 'evil-anzu) + (doom-modeline-add-transient-hook! #'evil-ex-start-search (require 'evil-anzu)) + ;; Avoid anzu conflicts across buffers (mapc #'make-variable-buffer-local '(anzu--total-matched anzu--current-position anzu--state @@ -262,12 +272,18 @@ If STRICT-P, return nil if no project was found, otherwise return "Set `doom-modeline-current-window' appropriately." (-when-let* ((win (frame-selected-window))) (unless (minibuffer-window-active-p win) - (setq doom-modeline-current-window win)))) + (setq doom-modeline-current-window win) + (force-mode-line-update)))) + +(defun doom-modeline-unset-selected-window () + (setq doom-modeline-current-window nil) + (force-mode-line-update)) (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) +(add-hook 'focus-in-hook #'doom-modeline-set-selected-window) +(add-hook 'focus-out-hook #'doom-modeline-unset-selected-window) +(add-hook 'doom-after-switch-window-hook #'doom-modeline-set-selected-window) +(add-hook 'doom-after-switch-frame-hook #'doom-modeline-set-selected-window) ;; ;; Variables @@ -279,12 +295,9 @@ If STRICT-P, return nil if no project was found, otherwise return (defvar doom-modeline-bar-width 3 "How wide the mode-line bar should be (only respected in GUI emacs).") -(defvar doom-modeline-vspc - (propertize " " 'face 'variable-pitch) - "TODO") - (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 @@ -305,26 +318,26 @@ file-name => comint.el") ;; (defgroup doom-modeline nil - "" - :group 'doom) + "TODO" + :group 'faces) (defface doom-modeline-buffer-path - '((t (:inherit mode-line-emphasis :bold t))) + '((t (:inherit (mode-line-emphasis bold)))) "Face used for the dirname part of the buffer path." :group 'doom-modeline) (defface doom-modeline-buffer-file - '((t (:inherit mode-line-buffer-id))) + '((t (:inherit (mode-line-buffer-id bold)))) "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))) + '((t (:inherit (error bold) :background nil))) "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))) + '((t (:inherit (mode-line-emphasis bold)))) "Face used for the major-mode segment in the mode-line." :group 'doom-modeline) @@ -340,17 +353,17 @@ file-name => comint.el") :group 'doom-modeline) (defface doom-modeline-info - `((t (:inherit success :bold t))) + `((t (:inherit (success bold)))) "Face for info-level messages in the modeline. Used by `*vc'." :group 'doom-modeline) (defface doom-modeline-warning - `((t (:inherit warning :bold t))) + `((t (:inherit (warning bold)))) "Face for warnings in the modeline. Used by `*flycheck'" :group 'doom-modeline) (defface doom-modeline-urgent - `((t (:inherit error :bold t))) + `((t (:inherit (error bold)))) "Face for errors in the modeline. Used by `*flycheck'" :group 'doom-modeline) @@ -368,18 +381,10 @@ active." "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) - ;; ;; Bootstrap ;; @@ -409,63 +414,65 @@ active." (defsubst doom-modeline--active () (eq (selected-window) doom-modeline-current-window)) -;; Inspired from `powerline's `pl/make-xpm'. -(defmemoize doom-modeline--make-xpm (color height width) - "Create an XPM bitmap." +(defun doom-modeline--make-xpm (face width height) + "Create an XPM bitmap. Inspired by `powerline''s `pl/make-xpm'." (propertize " " 'display (let ((data (make-list height (make-list width 1))) - (color (or color "None"))) - (create-image - (concat - (format "/* XPM */\nstatic char * percent[] = {\n\"%i %i 2 1\",\n\". c %s\",\n\" c %s\"," - (length (car data)) - (length data) - color - color) - (apply #'concat - (cl-loop with idx = 0 - with len = (length data) - for dl in data - do (cl-incf idx) - collect - (concat "\"" - (cl-loop for d in dl - if (= d 0) collect (string-to-char " ") - else collect (string-to-char ".")) - (if (eq idx len) "\"};" "\",\n"))))) - 'xpm t :ascent 'center)))) + (color (or (face-background face nil t) "None"))) + (ignore-errors + (create-image + (concat + (format "/* XPM */\nstatic char * percent[] = {\n\"%i %i 2 1\",\n\". c %s\",\n\" c %s\"," + (length (car data)) + (length data) + color + color) + (apply #'concat + (cl-loop with idx = 0 + with len = (length data) + for dl in data + do (cl-incf idx) + collect + (concat "\"" + (cl-loop for d in dl + if (= d 0) collect (string-to-char " ") + else collect (string-to-char ".")) + (if (eq idx len) "\"};" "\",\n"))))) + 'xpm t :ascent 'center))))) (defun doom-modeline-buffer-file-name () "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) - 'face - (let ((face (or (and (buffer-modified-p) - 'doom-modeline-buffer-modified) - (and (doom-modeline--active) - 'doom-modeline-buffer-file)))) - (when face `(:inherit ,face)))))) - 'help-echo buffer-file-truename)) + (let ((buffer-file-name (or buffer-file-name "")) + (buffer-file-truename (or buffer-file-truename ""))) + (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) + 'face + (let ((face (or (and (buffer-modified-p) + 'doom-modeline-buffer-modified) + (and (active) + 'doom-modeline-buffer-file)))) + (when face `(:inherit ,face)))))) + '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. 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))) + (doom-modeline--active (doom-modeline--active))) (if (null dirs) - (propertize "%b" 'face (if active 'doom-modeline-buffer-file)) + (propertize "%b" 'face (if doom-modeline--active 'doom-modeline-buffer-file)) (let ((modified-faces (if (buffer-modified-p) 'doom-modeline-buffer-modified))) (let ((dirname (car dirs)) (basename (cdr dirs)) - (dir-faces (or modified-faces (if active 'doom-modeline-project-root-dir))) - (file-faces (or modified-faces (if active 'doom-modeline-buffer-file)))) + (dir-faces (or modified-faces (if doom-modeline--active 'doom-modeline-project-root-dir))) + (file-faces (or modified-faces (if doom-modeline--active 'doom-modeline-buffer-file)))) (concat (propertize (concat dirname (if truncate-tail (substring basename 0 1) basename) "/") @@ -473,25 +480,21 @@ 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))))))))) +(defun doom-modeline-maybe-icon-octicon (&rest 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) + (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) + (when (and (display-graphic-p) (not (eq system-type 'windows-nt))) + (apply 'all-the-icons-material args))) + (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)) - (active (doom-modeline--active))) - (if (null root) - (propertize "%b" 'face (if active 'doom-modeline-buffer-file)) - (let* ((modified-faces (if (buffer-modified-p) 'doom-modeline-buffer-modified)) - (relative-dirs (file-relative-name (file-name-directory buffer-file-truename) - (if include-project (concat root "../") root))) - (relative-faces (or modified-faces (if active 'doom-modeline-buffer-path))) - (file-faces (or modified-faces (if active 'doom-modeline-buffer-file)))) - (if (equal "./" relative-dirs) (setq relative-dirs "")) - (concat (propertize relative-dirs 'face (if relative-faces `(:inherit ,relative-faces))) - (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)) @@ -500,16 +503,34 @@ If TRUNCATE-TAIL is t also truncate the parent directory of the file." (file-name-directory file-name) file-name)) +(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)) + (active (doom-modeline--active))) + (if (null root) + (propertize "%b" 'face (if active 'doom-modeline-buffer-file)) + (let* ((modified-faces (if (buffer-modified-p) 'doom-modeline-buffer-modified)) + (true-filename (file-truename buffer-file-name)) + (relative-dirs (file-relative-name (file-name-directory true-filename) + (if include-project (concat root "../") root))) + (relative-faces (or modified-faces (if active 'doom-modeline-buffer-path))) + (file-faces (or modified-faces (if active 'doom-modeline-buffer-file)))) + (if (equal "./" relative-dirs) (setq relative-dirs "")) + (concat (propertize relative-dirs 'face (if relative-faces `(:inherit ,relative-faces))) + (propertize (file-name-nondirectory true-filename) + 'face (if file-faces `(:inherit ,file-faces)))))))) + (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 fish-shell style. + 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) - buffer-file-truename)) + (file-name-directory buffer-file-name) + buffer-file-name)) (active (doom-modeline--active))) (if (null file-name-split) (propertize "%b" 'face (if active 'doom-modeline-buffer-file)) @@ -533,10 +554,9 @@ Example: ;; -;; Segments +;; buffer information ;; - (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." @@ -550,42 +570,39 @@ buffer where knowing the current project directory is important." (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 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 @@ -608,6 +625,9 @@ directory, the file name, and its state (modified, read-only or non-existent)." " ")) ;; +;; major-mode +;; + (doom-modeline-def-segment! major-mode "The major mode, including process, environment and text-scale info." (propertize @@ -622,56 +642,61 @@ directory, the file name, and its state (modified, read-only or non-existent)." 'face (if (doom-modeline--active) 'doom-modeline-buffer-major-mode))) -(defun doom-modeline-maybe-icon-octicon (&rest 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) - (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) - (when (and (display-graphic-p) (not (eq system-type 'windows-nt))) - (apply 'all-the-icons-material args))) - ;; +;; vcs +;; + +(defvar-local doom-modeline--vcs nil) +(defun doom-modeline--update-vcs () + (setq doom-modeline--vcs + (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 " " + (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)) + " ")))))) +(add-hook 'after-save-hook #'doom-modeline--update-vcs) +(add-hook 'find-file-hook #'doom-modeline--update-vcs t) + (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)) - " "))))) + doom-modeline--vcs) ;; +;; flycheck +;; + +(defvar doom-modeline-vspc + (propertize " " 'face 'variable-pitch) + "TODO") + (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." @@ -680,58 +705,75 @@ directory, the file name, and its state (modified, read-only or non-existent)." (concat (doom-modeline-maybe-icon-material icon :face face :height 1.1 :v-adjust (or voffset -0.2)) (if text doom-modeline-vspc))) - (when text - (propertize text 'face face)) + (if text (propertize text 'face face)) (if vc-mode " " " "))) +(defvar-local doom-modeline--flycheck nil) +(add-hook 'flycheck-status-changed-functions #'doom-modeline-update-flycheck-segment) +(add-hook 'flycheck-mode-hook #'doom-modeline-update-flycheck-segment) + +(defun doom-modeline-update-flycheck-segment (&optional status) + (setq doom-modeline--flycheck + (pcase status + ('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))))) + (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))))) -;; ('interrupted (doom-modeline-icon "x" "Interrupted" 'font-lock-doc-face))))) + doom-modeline--flycheck) ;; +;; selection-info +;; + (defsubst doom-modeline-column (pos) (save-excursion (goto-char pos) (current-column))) +(defvar-local doom-modeline-enable-word-count nil + "If non-nil, a word count will be added to the selection-info modeline +segment.") + (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))) - (let ((reg-beg (region-beginning)) - (reg-end (region-end))) + (when (and mark-active (doom-modeline--active)) + (cl-destructuring-bind (beg . end) + (if (eq evil-state 'visual) + (cons evil-visual-beginning evil-visual-end) + (cons (region-beginning) (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))))) + (let ((lines (count-lines beg (min end (point-max))))) + (concat (cond ((or (bound-and-true-p rectangle-mark-mode) + (eq 'block evil-visual-selection)) + (let ((cols (abs (- (doom-column end) + (doom-column beg))))) + (format "%dx%dB" lines cols))) + ((eq evil-visual-selection 'line) + (format "%dL" lines)) + ((> lines 1) + (format "%dC %dL" (- end beg) lines)) + ((format "%dC" (- end beg)))) + (when doom-modeline-enable-word-count + (format " %dW" (count-words beg end))))) 'face 'doom-modeline-highlight)))) - ;; +;; matches (anzu, evil-substitute, iedit, macro) +;; + (defun doom-modeline--macro-recording () "Display current Emacs or evil macro being recorded." (when (and (doom-modeline--active) (or defining-kbd-macro executing-kbd-macro)) @@ -744,13 +786,12 @@ 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'." - (setq anzu-cons-mode-line-p nil) (when (and anzu--state (not iedit-mode)) (propertize (let ((here anzu--current-position) @@ -814,61 +855,50 @@ with `evil-ex-substitute', and/or 4. The number of active `iedit' regions." (or (and (not (equal meta "")) meta) (if buffer-file-name " %I ")))) -;; TODO Include other information +;; +;; media-info +;; + (doom-modeline-def-segment! media-info "Metadata regarding the current file, such as dimensions for images." + ;; TODO Include other information (cond ((eq major-mode 'image-mode) (cl-destructuring-bind (width . height) (image-size (image-get-display-property) :pixels) (format " %dx%d " width height))))) +;; +;; bar +;; + +(defvar doom-modeline--bar-active nil) +(defvar doom-modeline--bar-inactive nil) (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 window-system + (if (doom-modeline--active) + doom-modeline--bar-active + doom-modeline--bar-inactive) "")) -(defun doom-modeline-eyebrowse-number () - (when (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))))) - str))) +(when (>= emacs-major-version 26) + (add-variable-watcher + 'doom-modeline-height + (lambda (_sym val op _where) + (when (and (eq op 'set) (integerp val)) + (doom-modeline-refresh-bars doom-modeline-bar-width val)))) -(defun doom-modeline-window-bottom-left-p () - (let* ((edges (window-edges)) - (minibuffer-edges (window-edges (minibuffer-window)))) - (and (eq 0 (car edges)) - (eq (nth 3 edges) - (cadr minibuffer-edges))))) + (add-variable-watcher + 'doom-modeline-bar-width + (lambda (_sym val op _where) + (when (and (eq op 'set) (integerp val)) + (doom-modeline-refresh-bars val doom-modeline-height))))) -(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))))) +;; +;; window number +;; (advice-add #'window-numbering-install-mode-line :override #'ignore) (advice-add #'window-numbering-clear-mode-line :override #'ignore) @@ -881,6 +911,10 @@ Returns \"\" to not break --no-window-system." 'doom-modeline-inactive-bar)) "")) +;; +;; workspace-number +;; + (declare-function eyebrowse--get 'eyebrowse) (doom-modeline-def-segment! workspace-number "The current workspace name or number. Requires `eyebrowse-mode' to be @@ -920,32 +954,63 @@ enabled." (media-info major-mode)) ;; -;; Bootstrap +;; Hooks ;; +(defun doom-modeline-refresh-bars (&optional width height) + (setq doom-modeline--bar-active + (doom-modeline--make-xpm 'doom-modeline-bar + (or width doom-modeline-bar-width) + (or height doom-modeline-height)) + doom-modeline--bar-inactive + (doom-modeline--make-xpm 'doom-modeline-inactive-bar + (or width doom-modeline-bar-width) + (or height doom-modeline-height)))) + ;;;###autoload (defun doom-modeline-init () - "Set the default modeline." - (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-modeline 'main)) - (with-current-buffer "*scratch*" - (doom-modeline-set-modeline 'main))) + ;; Create bars + (doom-modeline-refresh-bars) + (unless after-init-time + ;; These buffers are already created and don't get modelines. For the love + ;; of Emacs, someone give the man a modeline! + (dolist (bname '("*scratch*" "*Messages*")) + (with-current-buffer bname + (doom-modeline-set-modeline 'main))))) (defun doom-modeline-set-special-modeline () - "Set the special modeline." (doom-modeline-set-modeline 'special)) (defun doom-modeline-set-media-modeline () - "Set the media modeline." (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) +(defun doom-modeline-set-project-modeline () + (doom-modeline-set-modeline 'project)) + +;; +;; Bootstrap +;; + +(doom-modeline-set-modeline 'main t) ; set default modeline + +;; (add-hook 'doom-load-theme-hook #'doom-modeline-init) +;; (add-hook 'doom-scratch-buffer-hook #'doom-modeline-set-special-modeline) +;; (add-hook 'doom-dashboard-mode-hook #'doom-modeline-set-project-modeline) + +(add-hook 'image-mode-hook #'doom-modeline-set-media-modeline) +(add-hook 'circe-mode-hook #'doom-modeline-set-special-modeline) + +;; Ensure modeline is inactive when Emacs is unfocused (and active otherwise) +(defvar doom-modeline-remap-face-cookie nil) +(defun doom-modeline-focus () + (when doom-modeline-remap-face-cookie + (require 'face-remap) + (face-remap-remove-relative doom-modeline-remap-face-cookie))) +(defun doom-modeline-unfocus () + (setq doom-modeline-remap-face-cookie (face-remap-add-relative 'mode-line 'mode-line-inactive))) + +(add-hook 'focus-in-hook #'doom-modeline-focus) +(add-hook 'focus-out-hook #'doom-modeline-unfocus) (provide 'doom-modeline) From 553f1a8190254520954767f174c2e37b52d7b26b Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Wed, 13 Jun 2018 21:36:06 +0800 Subject: [PATCH 02/52] Remove memoize dependency. --- doom-modeline.el | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/doom-modeline.el b/doom-modeline.el index 91b7040..0577fb5 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) @@ -492,17 +491,6 @@ If TRUNCATE-TAIL is t also truncate the parent directory of the file." (when (and (display-graphic-p) (not (eq system-type 'windows-nt))) (apply 'all-the-icons-material args))) -(defmemoize doom-modeline-file-relative-name (filename directory) - (file-relative-name filename directory)) - -(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-relative (&optional include-project) "Propertized `buffer-file-name' showing directories relative to project's root only." (let ((root (doom-modeline-project-root)) From aee92fa4961502a3eadbc57093bc441122b2a034 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Thu, 14 Jun 2018 02:30:36 +0800 Subject: [PATCH 03/52] Update libs. --- doom-modeline.el | 221 ++++++++++++++++++++++++++--------------------- 1 file changed, 124 insertions(+), 97 deletions(-) diff --git a/doom-modeline.el b/doom-modeline.el index 0577fb5..b9b0e82 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.2.0 -;; 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 "25.1") (dash "2.11.0") (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. @@ -44,14 +44,15 @@ ;;; Code: -(require 'projectile) (require 'all-the-icons) (require 'dash) -(require 'shrink-path) (require 'eldoc-eval) +(require 'map) +(require 'projectile) +(require 'shrink-path) (eval-and-compile - (defun doom-modeline--resolve-hooks (hooks) + (defun doom-modeline--resolve-hook-forms (hooks) (cl-loop with quoted-p = (eq (car-safe hooks) 'quote) for hook in (doom-modeline-enlist (doom-modeline-unquote hooks)) if (eq (car-safe hook) 'quote) @@ -101,7 +102,7 @@ then it detaches itself." 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-hook 'enable-something) (same as `add-hook') (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) @@ -119,7 +120,7 @@ Body forms can access the hook's arguments through the let-bound variable (:append (setq append-p t)) (:local (setq local-p t)) (:remove (setq hook-fn 'remove-hook)))) - (let ((hooks (doom-modeline--resolve-hooks (pop args))) + (let ((hooks (doom-modeline--resolve-hook-forms (pop args))) (funcs (let ((val (car args))) (if (memq (car-safe val) '(quote function)) @@ -133,72 +134,99 @@ Body forms can access the hook's arguments through the let-bound variable `(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))) + (push (if (eq hook-fn 'remove-hook) + `(remove-hook ',hook ,fn ,local-p) + `(add-hook ',hook ,fn ,append-p ,local-p)) forms))) - `(progn ,@(nreverse forms))))) + `(progn ,@(if append-p (nreverse forms) forms))))) -(defmacro doom-modeline-def-segment! (name &rest forms) + +;; +;; Modeline library +;; + +(defvar doom-modeline-fn-alist ()) +(defvar doom-modeline-var-alist ()) + +(defmacro def-modeline-segment! (name &rest body) "Defines a modeline segment and byte compiles it." (declare (indent defun) (doc-string 2)) - (let ((sym (intern (format "doom-modeline-segment--%s" name)))) - `(progn - (defun ,sym () ,@forms) - ,(unless (bound-and-true-p byte-compile-current-file) - `(let (byte-compile-warnings) - (byte-compile #',sym)))))) + (let ((sym (intern (format "doom-modeline-segment--%s" name))) + (docstring (if (stringp (car body)) + (pop body) + (format "%s modeline segment" name)))) + (cond ((and (symbolp (car body)) + (not (cdr body))) + (map-put doom-modeline-var-alist name (car body)) + `(map-put doom-modeline-var-alist ',name ',(car body))) + (t + (map-put doom-modeline-fn-alist name sym) + `(progn + (fset ',sym (lambda () ,docstring ,@body)) + (map-put doom-modeline-fn-alist ',name ',sym) + ,(unless (bound-and-true-p byte-compile-current-file) + `(let (byte-compile-warnings) + (byte-compile #',sym)))))))) -(defsubst doom-modeline--prepare-modeline-segments (segments) - (cl-loop for seg in segments - if (stringp seg) - collect seg - else - collect (list (intern (format "doom-modeline-segment--%s" (symbol-name seg)))))) +(defsubst doom-modeline--prepare-segments (segments) + (let (forms it) + (dolist (seg segments) + (cond ((stringp seg) + (push seg forms)) + ((symbolp seg) + (cond ((setq it (cdr (assq seg doom-modeline-fn-alist))) + (push (list it) forms)) + ((setq it (cdr (assq seg doom-modeline-var-alist))) + (push it forms)) + ((error "%s is not a defined segment" seg)))) + ((error "%s is not a valid segment" seg)))) + (nreverse forms))) -(defmacro doom-modeline-def-modeline! (name lhs &optional rhs) +(defmacro 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!'. +modeline segments defined with `def-modeline-segment!'. Example: - (doom-modeline-def-modeline! minimal + (def-modeline! minimal (bar matches \" \" buffer-info) (media-info major-mode)) - (doom-modeline-set-modeline 'minimal t)" + (doom-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)) - (rhs (list ,@rhs-forms))) - (let ((rhs-str (format-mode-line rhs))) - (list lhs - (propertize - " " 'display - `((space :align-to (- (+ right right-fringe right-margin) - ,(+ 1 (string-width rhs-str)))))) - rhs-str)))) + (fset ',sym + (lambda () + ,(concat "Modeline:\n" + (format " %s\n %s" + (prin1-to-string lhs) + (prin1-to-string rhs))) + (let ((lhs (list ,@lhs-forms)) + (rhs (list ,@rhs-forms))) + (let ((rhs-str (format-mode-line rhs))) + (list lhs + (propertize + " " 'display + `((space :align-to (- (+ right right-fringe right-margin) + ,(+ 1 (string-width rhs-str)))))) + rhs-str))))) ,(unless (bound-and-true-p byte-compile-current-file) `(let (byte-compile-warnings) (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." +(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))) (setf (if default (default-value 'mode-line-format) (buffer-local-value 'mode-line-format (current-buffer))) - modeline))) + (list "%e" modeline)))) (defun doom-modeline-project-root () "Get the path to the root of your project. @@ -222,6 +250,7 @@ If STRICT-P, return nil if no project was found, otherwise return ;; 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." + (eldoc-in-minibuffer-mode +1) (with-current-buffer (eldoc-current-buffer) (let* ((str (and (stringp input) input)) (mode-line-format (or (and str (or (doom-modeline-eldoc str) str)) @@ -231,24 +260,22 @@ If STRICT-P, return nil if no project was found, otherwise return (sit-for eldoc-show-in-mode-line-delay)))) (setq eldoc-in-minibuffer-show-fn #'doom-modeline--show-eldoc) -(eldoc-in-minibuffer-mode +1) +;; (eldoc-in-minibuffer-mode +1) ;; 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 'anzu) - (setq anzu-cons-mode-line-p nil - anzu-minimum-input-length 1 - anzu-search-threshold 250) - - (defun doom-modeline-fix-anzu-count (positions here) - (cl-loop for (start . end) in positions - collect t into before - when (and (>= here start) (<= here end)) - return (length before) - finally return 0)) - (advice-add #'anzu--where-is-here :override #'doom-modeline-fix-anzu-count)) +(defun doom-modeline-fix-anzu-count (positions here) + (cl-loop for (start . end) in positions + collect t into before + when (and (>= here start) (<= here end)) + return (length before) + finally return 0)) +(advice-add #'anzu--where-is-here :override #'doom-modeline-fix-anzu-count) (when (featurep 'evil-anzu) (doom-modeline-add-transient-hook! #'evil-ex-start-search (require 'evil-anzu)) @@ -261,7 +288,7 @@ If STRICT-P, return nil if no project was found, otherwise return ;; 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 '+evil-esc-hook #'anzu--reset-status t) (add-hook 'iedit-mode-end-hook #'anzu--reset-status)) @@ -418,7 +445,7 @@ active." (propertize " " 'display (let ((data (make-list height (make-list width 1))) - (color (or (face-background face nil t) "None"))) + (color (or (when face (face-background face nil t)) "None"))) (ignore-errors (create-image (concat @@ -480,15 +507,15 @@ If TRUNCATE-TAIL is t also truncate the parent directory of the file." 'face (if file-faces `(:inherit ,file-faces))))))))) (defun doom-modeline-maybe-icon-octicon (&rest args) - (when (and (display-graphic-p) (not (eq system-type 'windows-nt))) + (when (and (featurep 'all-the-icons) (display-graphic-p) (not (eq system-type 'windows-nt))) (apply 'all-the-icons-octicon args))) (defun doom-modeline-maybe-icon-faicon (&rest args) - (when (and (display-graphic-p) (not (eq system-type 'windows-nt))) + (when (and (featurep 'all-the-icons) (display-graphic-p) (not (eq system-type 'windows-nt))) (apply 'all-the-icons-faicon args))) (defun doom-modeline-maybe-icon-material (&rest args) - (when (and (display-graphic-p) (not (eq system-type 'windows-nt))) + (when (and (featurep 'all-the-icons) (display-graphic-p) (not (eq system-type 'windows-nt))) (apply 'all-the-icons-material args))) (defun doom-modeline--buffer-file-name-relative (&optional include-project) @@ -545,7 +572,7 @@ Example: ;; buffer information ;; -(doom-modeline-def-segment! buffer-default-directory +(def-modeline-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))) @@ -559,7 +586,7 @@ buffer where knowing the current project directory is important." 'face face)))) ;; -(doom-modeline-def-segment! buffer-info +(def-modeline-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 (cond (buffer-read-only @@ -591,7 +618,7 @@ directory, the file name, and its state (modified, read-only or non-existent)." (doom-modeline-buffer-file-name) "%b"))) -(doom-modeline-def-segment! buffer-info-simple +(def-modeline-segment! buffer-info-simple "Display only the current buffer's name, but with fontification." (propertize "%b" @@ -600,7 +627,7 @@ directory, the file name, and its state (modified, read-only or non-existent)." ((doom-modeline--active) 'doom-modeline-buffer-file)))) ;; -(doom-modeline-def-segment! buffer-encoding +(def-modeline-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 ") @@ -616,7 +643,7 @@ directory, the file name, and its state (modified, read-only or non-existent)." ;; major-mode ;; -(doom-modeline-def-segment! major-mode +(def-modeline-segment! major-mode "The major mode, including process, environment and text-scale info." (propertize (concat (format-mode-line mode-name) @@ -672,7 +699,7 @@ directory, the file name, and its state (modified, read-only or non-existent)." (add-hook 'after-save-hook #'doom-modeline--update-vcs) (add-hook 'find-file-hook #'doom-modeline--update-vcs t) -(doom-modeline-def-segment! vcs +(def-modeline-segment! vcs "Displays the current branch, colored based on its state." doom-modeline--vcs) @@ -716,7 +743,7 @@ directory, the file name, and its state (modified, read-only or non-existent)." ('errored (doom-modeline-icon "sim_card_alert" "Error" 'doom-modeline-urgent)) ('interrupted (doom-modeline-icon "pause" "Interrupted" 'font-lock-doc-face))))) -(doom-modeline-def-segment! flycheck +(def-modeline-segment! flycheck "Displays color-coded flycheck error status in the current buffer with pretty icons." doom-modeline--flycheck) @@ -734,7 +761,7 @@ icons." "If non-nil, a word count will be added to the selection-info modeline segment.") -(doom-modeline-def-segment! selection-info +(def-modeline-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 mark-active (doom-modeline--active)) @@ -832,7 +859,7 @@ lines are selected, or the NxM dimensions of a block selection." length)) 'face (if (doom-modeline--active) 'doom-modeline-panel)))) -(doom-modeline-def-segment! matches +(def-modeline-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." @@ -847,7 +874,7 @@ with `evil-ex-substitute', and/or 4. The number of active `iedit' regions." ;; media-info ;; -(doom-modeline-def-segment! media-info +(def-modeline-segment! media-info "Metadata regarding the current file, such as dimensions for images." ;; TODO Include other information (cond ((eq major-mode 'image-mode) @@ -861,7 +888,7 @@ with `evil-ex-substitute', and/or 4. The number of active `iedit' regions." (defvar doom-modeline--bar-active nil) (defvar doom-modeline--bar-inactive nil) -(doom-modeline-def-segment! bar +(def-modeline-segment! bar "The bar regulates the height of the mode-line in GUI Emacs. Returns \"\" to not break --no-window-system." (if window-system @@ -891,7 +918,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 +(def-modeline-segment! window-number (if (bound-and-true-p window-numbering-mode) (propertize (format " %s " (window-numbering-get-number-string)) 'face (if (doom-modeline--active) @@ -904,7 +931,7 @@ Returns \"\" to not break --no-window-system." ;; (declare-function eyebrowse--get 'eyebrowse) -(doom-modeline-def-segment! workspace-number +(def-modeline-segment! workspace-number "The current workspace name or number. Requires `eyebrowse-mode' to be enabled." (if (and (bound-and-true-p eyebrowse-mode) @@ -921,25 +948,25 @@ enabled." ;; Mode lines ;; -(doom-modeline-def-modeline! main - (workspace-number bar matches " " buffer-info " %l:%c %p " selection-info) - (buffer-encoding major-mode vcs flycheck)) +(def-modeline! 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)) +(def-modeline! 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)) +(def-modeline! 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)) +(def-modeline! project + (bar buffer-default-directory) + (major-mode)) -(doom-modeline-def-modeline! media - (bar " %b ") - (media-info major-mode)) +(def-modeline! media + (bar " %b ") + (media-info major-mode)) ;; ;; Hooks @@ -964,22 +991,22 @@ enabled." ;; of Emacs, someone give the man a modeline! (dolist (bname '("*scratch*" "*Messages*")) (with-current-buffer bname - (doom-modeline-set-modeline 'main))))) + (doom-modeline-set 'main))))) (defun doom-modeline-set-special-modeline () - (doom-modeline-set-modeline 'special)) + (doom-modeline-set 'special)) (defun doom-modeline-set-media-modeline () - (doom-modeline-set-modeline 'media)) + (doom-modeline-set 'media)) (defun doom-modeline-set-project-modeline () - (doom-modeline-set-modeline 'project)) + (doom-modeline-set 'project)) ;; ;; Bootstrap ;; -(doom-modeline-set-modeline 'main t) ; set default modeline +(doom-modeline-set 'main t) ; set default modeline ;; (add-hook 'doom-load-theme-hook #'doom-modeline-init) ;; (add-hook 'doom-scratch-buffer-hook #'doom-modeline-set-special-modeline) From 0509ac47f48f79f06a0723df5eba6ec6baaaaba8 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Thu, 14 Jun 2018 02:41:13 +0800 Subject: [PATCH 04/52] Fix eldoc in minibuffer. --- doom-modeline.el | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/doom-modeline.el b/doom-modeline.el index b9b0e82..0de2e21 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -250,7 +250,6 @@ If STRICT-P, return nil if no project was found, otherwise return ;; 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." - (eldoc-in-minibuffer-mode +1) (with-current-buffer (eldoc-current-buffer) (let* ((str (and (stringp input) input)) (mode-line-format (or (and str (or (doom-modeline-eldoc str) str)) @@ -260,7 +259,7 @@ If STRICT-P, return nil if no project was found, otherwise return (sit-for eldoc-show-in-mode-line-delay)))) (setq eldoc-in-minibuffer-show-fn #'doom-modeline--show-eldoc) -;; (eldoc-in-minibuffer-mode +1) +(eldoc-in-minibuffer-mode +1) ;; anzu and evil-anzu expose current/total state that can be displayed in the From f98597f06c18ccadccbfb77874363e5ebad64690 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Thu, 14 Jun 2018 02:51:07 +0800 Subject: [PATCH 05/52] Fix face of eldoc-in-minibuffer. --- doom-modeline.el | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/doom-modeline.el b/doom-modeline.el index 0de2e21..3cb55ce 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -241,10 +241,9 @@ If STRICT-P, return nil if no project was found, otherwise return (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)) + (doom-modeline--make-xpm 'doom-modeline-eldoc-bar + doom-modeline-height + doom-modeline-bar-width)) text)) ;; Show eldoc in the mode-line with `eval-expression' @@ -444,7 +443,9 @@ active." (propertize " " 'display (let ((data (make-list height (make-list width 1))) - (color (or (when face (face-background face nil t)) "None"))) + (color (or (when face + (face-background face nil t)) + "None"))) (ignore-errors (create-image (concat From 25c5d2919f46046378a1a4d69ebc7c750f8017b2 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Thu, 14 Jun 2018 17:57:29 +0800 Subject: [PATCH 06/52] Fix: quote -> backquote. --- doom-modeline.el | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/doom-modeline.el b/doom-modeline.el index 0577fb5..a1cfb55 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -703,7 +703,7 @@ directory, the file name, and its state (modified, read-only or non-existent)." (defun doom-modeline-update-flycheck-segment (&optional status) (setq doom-modeline--flycheck (pcase status - ('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" @@ -711,10 +711,10 @@ directory, the file name, and its state (modified, read-only or non-existent)." (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))))) (doom-modeline-def-segment! flycheck "Displays color-coded flycheck error status in the current buffer with pretty From af221ea1d84143ed3d41ba4a1ede682f9a6ca9f8 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Fri, 15 Jun 2018 14:53:45 +0800 Subject: [PATCH 07/52] =?UTF-8?q?Fix:=20Symbol=E2=80=99s=20value=20as=20va?= =?UTF-8?q?riable=20is=20void:=20doom-modeline-fn-alist.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doom-modeline.el | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/doom-modeline.el b/doom-modeline.el index 0d1c2fe..102c954 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -145,8 +145,9 @@ Body forms can access the hook's arguments through the let-bound variable ;; Modeline library ;; -(defvar doom-modeline-fn-alist ()) -(defvar doom-modeline-var-alist ()) +(eval-and-compile + (defvar doom-modeline-fn-alist ()) + (defvar doom-modeline-var-alist ())) (defmacro def-modeline-segment! (name &rest body) "Defines a modeline segment and byte compiles it." From 0946408dbe7d4303c5ca335441cff00b73522d59 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Fri, 15 Jun 2018 23:05:14 +0800 Subject: [PATCH 08/52] Remove dash. --- doom-modeline.el | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/doom-modeline.el b/doom-modeline.el index 102c954..45c6fdc 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.2.0 -;; Package-Requires: ((emacs "25.1") (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 "25.1") (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. @@ -45,12 +45,14 @@ ;;; Code: (require 'all-the-icons) -(require 'dash) (require 'eldoc-eval) (require 'map) (require 'projectile) (require 'shrink-path) +(when (>= emacs-major-version 26) + (defalias 'when-let 'when-let*)) + (eval-and-compile (defun doom-modeline--resolve-hook-forms (hooks) (cl-loop with quoted-p = (eq (car-safe hooks) 'quote) @@ -223,7 +225,7 @@ Example: (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))) + (when-let ((modeline (doom-modeline key))) (setf (if default (default-value 'mode-line-format) (buffer-local-value 'mode-line-format (current-buffer))) @@ -295,7 +297,7 @@ If STRICT-P, return nil if no project was found, otherwise return (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))) + (when-let ((win (frame-selected-window))) (unless (minibuffer-window-active-p win) (setq doom-modeline-current-window win) (force-mode-line-update)))) From 50dd00528687e26c074984e584aa28c33d1c29a0 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Sun, 17 Jun 2018 18:12:02 +0800 Subject: [PATCH 09/52] Fix warnings. --- doom-modeline.el | 134 +++++++++++++++++++++++------------------------ 1 file changed, 67 insertions(+), 67 deletions(-) diff --git a/doom-modeline.el b/doom-modeline.el index 45c6fdc..6719708 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -151,7 +151,7 @@ Body forms can access the hook's arguments through the let-bound variable (defvar doom-modeline-fn-alist ()) (defvar doom-modeline-var-alist ())) -(defmacro def-modeline-segment! (name &rest body) +(defmacro doom-modeline-def-segment! (name &rest body) "Defines a modeline segment and byte compiles it." (declare (indent defun) (doc-string 2)) (let ((sym (intern (format "doom-modeline-segment--%s" name))) @@ -185,12 +185,12 @@ Body forms can access the hook's arguments through the let-bound variable ((error "%s is not a valid segment" seg)))) (nreverse forms))) -(defmacro def-modeline! (name lhs &optional rhs) +(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 `def-modeline-segment!'. +modeline segments defined with `doom-modeline-def-segment!'. Example: - (def-modeline! minimal + (doom-modeline-def-modeline! minimal (bar matches \" \" buffer-info) (media-info major-mode)) (doom-set-modeline 'minimal t)" @@ -575,53 +575,53 @@ Example: ;; buffer information ;; -(def-modeline-segment! buffer-default-directory - "Displays `default-directory'. This is for special buffers like the scratch +(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))) - (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)))) ;; -(def-modeline-segment! buffer-info - "Combined information about the current buffer, including the current working +(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 (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"))) -(def-modeline-segment! buffer-info-simple +(doom-modeline-def-segment! buffer-info-simple "Display only the current buffer's name, but with fontification." (propertize "%b" @@ -630,7 +630,7 @@ directory, the file name, and its state (modified, read-only or non-existent)." ((doom-modeline--active) 'doom-modeline-buffer-file)))) ;; -(def-modeline-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 ") @@ -646,7 +646,7 @@ directory, the file name, and its state (modified, read-only or non-existent)." ;; major-mode ;; -(def-modeline-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) @@ -702,7 +702,7 @@ directory, the file name, and its state (modified, read-only or non-existent)." (add-hook 'after-save-hook #'doom-modeline--update-vcs) (add-hook 'find-file-hook #'doom-modeline--update-vcs t) -(def-modeline-segment! vcs +(doom-modeline-def-segment! vcs "Displays the current branch, colored based on its state." doom-modeline--vcs) @@ -746,7 +746,7 @@ directory, the file name, and its state (modified, read-only or non-existent)." (`errored (doom-modeline-icon "sim_card_alert" "Error" 'doom-modeline-urgent)) (`interrupted (doom-modeline-icon "pause" "Interrupted" 'font-lock-doc-face))))) -(def-modeline-segment! flycheck +(doom-modeline-def-segment! flycheck "Displays color-coded flycheck error status in the current buffer with pretty icons." doom-modeline--flycheck) @@ -764,7 +764,7 @@ icons." "If non-nil, a word count will be added to the selection-info modeline segment.") -(def-modeline-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 mark-active (doom-modeline--active)) @@ -862,7 +862,7 @@ lines are selected, or the NxM dimensions of a block selection." length)) 'face (if (doom-modeline--active) 'doom-modeline-panel)))) -(def-modeline-segment! matches +(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." @@ -877,7 +877,7 @@ with `evil-ex-substitute', and/or 4. The number of active `iedit' regions." ;; media-info ;; -(def-modeline-segment! media-info +(doom-modeline-def-segment! media-info "Metadata regarding the current file, such as dimensions for images." ;; TODO Include other information (cond ((eq major-mode 'image-mode) @@ -891,7 +891,7 @@ with `evil-ex-substitute', and/or 4. The number of active `iedit' regions." (defvar doom-modeline--bar-active nil) (defvar doom-modeline--bar-inactive nil) -(def-modeline-segment! bar +(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 window-system @@ -921,7 +921,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) -(def-modeline-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) @@ -934,7 +934,7 @@ Returns \"\" to not break --no-window-system." ;; (declare-function eyebrowse--get 'eyebrowse) -(def-modeline-segment! workspace-number +(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) @@ -951,23 +951,23 @@ enabled." ;; Mode lines ;; -(def-modeline! 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)) -(def-modeline! minimal - (bar matches " " buffer-info) - (media-info major-mode)) +(doom-modeline-def-modeline! minimal + (bar matches " " buffer-info) + (media-info major-mode)) -(def-modeline! 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)) -(def-modeline! project +(doom-modeline-def-modeline! project (bar buffer-default-directory) (major-mode)) -(def-modeline! media +(doom-modeline-def-modeline! media (bar " %b ") (media-info major-mode)) From 9a8231ca35c6b4e9e8aa4ab143054ca7fe495aa8 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Sun, 17 Jun 2018 22:45:59 +0800 Subject: [PATCH 10/52] Fix: when-let for Emacs26. --- doom-modeline.el | 1 + 1 file changed, 1 insertion(+) diff --git a/doom-modeline.el b/doom-modeline.el index 6719708..8d67dd6 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -51,6 +51,7 @@ (require 'shrink-path) (when (>= emacs-major-version 26) + (require 'subr-x) (defalias 'when-let 'when-let*)) (eval-and-compile From b66b92c6fc400c2ed967c28a2f5d51d16a3a1db8 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Sun, 17 Jun 2018 22:48:51 +0800 Subject: [PATCH 11/52] Add GLP3 license. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 46c38e2..597061e 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 2d9ce25bccb03007b2e7cec52e9e389f4ff95ca4 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Tue, 19 Jun 2018 14:11:39 +0800 Subject: [PATCH 12/52] Update format. --- doom-modeline.el | 86 ++++++++++++++++++++++++------------------------ 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/doom-modeline.el b/doom-modeline.el index 8d67dd6..ff06806 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -577,50 +577,50 @@ 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." @@ -965,12 +965,12 @@ enabled." (buffer-encoding major-mode flycheck)) (doom-modeline-def-modeline! project - (bar buffer-default-directory) - (major-mode)) + (bar buffer-default-directory) + (major-mode)) (doom-modeline-def-modeline! media - (bar " %b ") - (media-info major-mode)) + (bar " %b ") + (media-info major-mode)) ;; ;; Hooks From 0234007b08f7086ab66fc7e6a58e1c271fb51047 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Tue, 19 Jun 2018 17:58:24 +0800 Subject: [PATCH 13/52] Merge new codes and fix warnings. --- doom-modeline.el | 114 ++++++++++++++++++++++++++--------------------- 1 file changed, 64 insertions(+), 50 deletions(-) diff --git a/doom-modeline.el b/doom-modeline.el index ff06806..5ef6233 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -308,10 +308,19 @@ If STRICT-P, return nil if no project was found, otherwise return (force-mode-line-update)) (add-hook 'window-configuration-change-hook #'doom-modeline-set-selected-window) -(add-hook 'focus-in-hook #'doom-modeline-set-selected-window) -(add-hook 'focus-out-hook #'doom-modeline-unset-selected-window) (add-hook 'doom-after-switch-window-hook #'doom-modeline-set-selected-window) -(add-hook 'doom-after-switch-frame-hook #'doom-modeline-set-selected-window) +(with-no-warnings + (if (not (boundp 'after-focus-change-function)) + (progn + (add-hook 'focus-in-hook #'doom-modeline-set-selected-window) + (add-hook 'focus-out-hook #'doom-modeline-unset-selected-window)) + (defun doom-modeline-refresh-frame () + (setq +doom-modeline-current-window nil) + (cl-loop for frame in (frame-list) + if (eq (frame-focus-state frame) t) + return (setq +doom-modeline-current-window (frame-selected-window frame))) + (force-mode-line-update)) + (add-function :after after-focus-change-function #'doom-modeline-refresh-frame))) ;; ;; Variables @@ -413,32 +422,25 @@ active." "The face used for eyebrowse." :group 'doom-modeline) -;; -;; 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) -(doom-modeline-add-hook! '(focus-in-hook find-file-hook) #'doom-modeline-update-env) -(defun doom-modeline-update-env () - (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 -(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")) - ;; ;; Modeline helpers ;; +(defun doom-modeline-maybe-icon-octicon (&rest args) + "Display octicon via `ARGS'." + (when (and (featurep 'all-the-icons) (display-graphic-p) (not (eq system-type 'windows-nt))) + (apply 'all-the-icons-octicon args))) + +(defun doom-modeline-maybe-icon-faicon (&rest args) + "Display font awesome icon via `ARGS'." + (when (and (featurep 'all-the-icons) (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 via `ARGS'." + (when (and (featurep 'all-the-icons) (display-graphic-p) (not (eq system-type 'windows-nt))) + (apply 'all-the-icons-material args))) + (defsubst doom-modeline--active () (eq (selected-window) doom-modeline-current-window)) @@ -447,9 +449,7 @@ active." (propertize " " 'display (let ((data (make-list height (make-list width 1))) - (color (or (when face - (face-background face nil t)) - "None"))) + (color (or (face-background face nil t) "None"))) (ignore-errors (create-image (concat @@ -472,7 +472,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'." (let ((buffer-file-name (or buffer-file-name "")) (buffer-file-truename (or buffer-file-truename ""))) (propertize @@ -495,14 +495,14 @@ active." "Propertized `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))) - (doom-modeline--active (doom-modeline--active))) + (active (doom-modeline--active))) (if (null dirs) - (propertize "%b" 'face (if doom-modeline--active 'doom-modeline-buffer-file)) + (propertize "%b" 'face (if active 'doom-modeline-buffer-file)) (let ((modified-faces (if (buffer-modified-p) 'doom-modeline-buffer-modified))) (let ((dirname (car dirs)) (basename (cdr dirs)) - (dir-faces (or modified-faces (if doom-modeline--active 'doom-modeline-project-root-dir))) - (file-faces (or modified-faces (if doom-modeline--active 'doom-modeline-buffer-file)))) + (dir-faces (or modified-faces (if active 'doom-modeline-project-root-dir))) + (file-faces (or modified-faces (if active 'doom-modeline-buffer-file)))) (concat (propertize (concat dirname (if truncate-tail (substring basename 0 1) basename) "/") @@ -510,18 +510,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))))))))) -(defun doom-modeline-maybe-icon-octicon (&rest args) - (when (and (featurep 'all-the-icons) (display-graphic-p) (not (eq system-type 'windows-nt))) - (apply 'all-the-icons-octicon args))) - -(defun doom-modeline-maybe-icon-faicon (&rest args) - (when (and (featurep 'all-the-icons) (display-graphic-p) (not (eq system-type 'windows-nt))) - (apply 'all-the-icons-faicon args))) - -(defun doom-modeline-maybe-icon-material (&rest args) - (when (and (featurep 'all-the-icons) (display-graphic-p) (not (eq system-type 'windows-nt))) - (apply 'all-the-icons-material args))) - (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)) @@ -667,6 +655,7 @@ directory, the file name, and its state (modified, read-only or non-existent)." (defvar-local doom-modeline--vcs nil) (defun doom-modeline--update-vcs () + "Update vsc status in mode-line." (setq doom-modeline--vcs (when (and vc-mode buffer-file-name) (let* ((backend (vc-backend buffer-file-name)) @@ -713,12 +702,12 @@ directory, the file name, and its state (modified, read-only or non-existent)." ;; (defvar doom-modeline-vspc - (propertize " " 'face 'variable-pitch) - "TODO") + "Text style with icons in mode-line." + (propertize " " 'face 'variable-pitch)) (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." + "Displays an ICON with FACE, followed by TEXT. +Uses `all-the-icons-material' to fetch the icon." (concat (if vc-mode " " " ") (when icon (concat @@ -895,7 +884,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." - (if window-system + (if (display-graphic-p) (if (doom-modeline--active) doom-modeline--bar-active doom-modeline--bar-inactive) @@ -977,6 +966,7 @@ enabled." ;; (defun doom-modeline-refresh-bars (&optional width height) + "Refreash mode-line bars with `WIDTH' and `HEIGHT'." (setq doom-modeline--bar-active (doom-modeline--make-xpm 'doom-modeline-bar (or width doom-modeline-bar-width) @@ -988,6 +978,7 @@ enabled." ;;;###autoload (defun doom-modeline-init () + "Initialize doom mode-line." ;; Create bars (doom-modeline-refresh-bars) (unless after-init-time @@ -998,12 +989,15 @@ enabled." (doom-modeline-set 'main))))) (defun doom-modeline-set-special-modeline () + "Set sepcial mode-line." (doom-modeline-set 'special)) (defun doom-modeline-set-media-modeline () + "Set media mode-line." (doom-modeline-set 'media)) (defun doom-modeline-set-project-modeline () + "Set project mode-line." (doom-modeline-set 'project)) ;; @@ -1019,13 +1013,33 @@ enabled." (add-hook 'image-mode-hook #'doom-modeline-set-media-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) +(doom-modeline-add-hook! '(focus-in-hook find-file-hook) #'doom-modeline-update-env) +(defun doom-modeline-update-env () + (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 +(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")) + ;; Ensure modeline is inactive when Emacs is unfocused (and active otherwise) (defvar doom-modeline-remap-face-cookie nil) (defun doom-modeline-focus () + "Focus mode-line." (when doom-modeline-remap-face-cookie (require 'face-remap) (face-remap-remove-relative doom-modeline-remap-face-cookie))) (defun doom-modeline-unfocus () + "Unfocus mode-line." (setq doom-modeline-remap-face-cookie (face-remap-add-relative 'mode-line 'mode-line-inactive))) (add-hook 'focus-in-hook #'doom-modeline-focus) From 747f060cdfb5965a12719012fefb134f3e1bad42 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Tue, 19 Jun 2018 18:06:01 +0800 Subject: [PATCH 14/52] Remove `doom-modeline-add-hook!`. --- doom-modeline.el | 58 ++++++------------------------------------------ 1 file changed, 7 insertions(+), 51 deletions(-) diff --git a/doom-modeline.el b/doom-modeline.el index 5ef6233..238b10f 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -96,54 +96,6 @@ then it detaches itself." ((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) (same as `add-hook') - (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-hook-forms (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 (if (eq hook-fn 'remove-hook) - `(remove-hook ',hook ,fn ,local-p) - `(add-hook ',hook ,fn ,append-p ,local-p)) - forms))) - `(progn ,@(if append-p (nreverse forms) forms))))) - - ;; ;; Modeline library ;; @@ -1016,7 +968,8 @@ enabled." ;; 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 () (when doom-modeline-env-command (let* ((default-directory (doom-modeline-project-root)) @@ -1028,8 +981,11 @@ enabled." ;; 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"))) ;; Ensure modeline is inactive when Emacs is unfocused (and active otherwise) (defvar doom-modeline-remap-face-cookie nil) From 998cfe1bd429e8e054716aaf317c6cba16194e38 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Tue, 19 Jun 2018 18:23:22 +0800 Subject: [PATCH 15/52] Minor fix. --- doom-modeline.el | 158 ++++++++++++++++++++++++----------------------- 1 file changed, 81 insertions(+), 77 deletions(-) diff --git a/doom-modeline.el b/doom-modeline.el index 238b10f..ef2837a 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -104,7 +104,7 @@ then it detaches itself." (defvar doom-modeline-fn-alist ()) (defvar doom-modeline-var-alist ())) -(defmacro doom-modeline-def-segment! (name &rest body) +(defmacro doom-modeline-def-segment (name &rest body) "Defines a modeline segment and byte compiles it." (declare (indent defun) (doc-string 2)) (let ((sym (intern (format "doom-modeline-segment--%s" name))) @@ -125,6 +125,7 @@ then it detaches itself." (byte-compile #',sym)))))))) (defsubst doom-modeline--prepare-segments (segments) + "Prepare mode-line `SEGMENTS'." (let (forms it) (dolist (seg segments) (cond ((stringp seg) @@ -138,15 +139,16 @@ then it detaches itself." ((error "%s is not a valid segment" seg)))) (nreverse forms))) -(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!'. +(defmacro doom-modeline-def (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'. Example: - (doom-modeline-def-modeline! minimal + (doom-modeline-def minimal (bar matches \" \" buffer-info) (media-info major-mode)) - (doom-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))) @@ -171,14 +173,16 @@ 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 (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))) + "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 (m (doom-modeline key)) (setf (if default (default-value 'mode-line-format) (buffer-local-value 'mode-line-format (current-buffer))) @@ -516,53 +520,53 @@ Example: ;; buffer information ;; -(doom-modeline-def-segment! buffer-default-directory - "Displays `default-directory'. This is for special buffers like the scratch +(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))) - (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 +(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 (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 +(doom-modeline-def-segment buffer-info-simple "Display only the current buffer's name, but with fontification." (propertize "%b" @@ -571,7 +575,7 @@ directory, the file name, and its state (modified, read-only or non-existent)." ((doom-modeline--active) 'doom-modeline-buffer-file)))) ;; -(doom-modeline-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 ") @@ -587,7 +591,7 @@ directory, the file name, and its state (modified, read-only or non-existent)." ;; major-mode ;; -(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) @@ -644,7 +648,7 @@ directory, the file name, and its state (modified, read-only or non-existent)." (add-hook 'after-save-hook #'doom-modeline--update-vcs) (add-hook 'find-file-hook #'doom-modeline--update-vcs t) -(doom-modeline-def-segment! vcs +(doom-modeline-def-segment vcs "Displays the current branch, colored based on its state." doom-modeline--vcs) @@ -688,7 +692,7 @@ Uses `all-the-icons-material' to fetch the icon." (`errored (doom-modeline-icon "sim_card_alert" "Error" 'doom-modeline-urgent)) (`interrupted (doom-modeline-icon "pause" "Interrupted" 'font-lock-doc-face))))) -(doom-modeline-def-segment! flycheck +(doom-modeline-def-segment flycheck "Displays color-coded flycheck error status in the current buffer with pretty icons." doom-modeline--flycheck) @@ -706,7 +710,7 @@ icons." "If non-nil, a word count will be added to the selection-info modeline segment.") -(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 mark-active (doom-modeline--active)) @@ -804,7 +808,7 @@ lines are selected, or the NxM dimensions of a block selection." length)) 'face (if (doom-modeline--active) 'doom-modeline-panel)))) -(doom-modeline-def-segment! matches +(doom-modeline-def-segment matches "Displays: 1. the currently recording macro, 2. A current/total for the 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." @@ -819,7 +823,7 @@ with `evil-ex-substitute', and/or 4. The number of active `iedit' regions." ;; media-info ;; -(doom-modeline-def-segment! media-info +(doom-modeline-def-segment media-info "Metadata regarding the current file, such as dimensions for images." ;; TODO Include other information (cond ((eq major-mode 'image-mode) @@ -833,7 +837,7 @@ with `evil-ex-substitute', and/or 4. The number of active `iedit' regions." (defvar doom-modeline--bar-active nil) (defvar doom-modeline--bar-inactive nil) -(doom-modeline-def-segment! bar +(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) @@ -863,7 +867,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) @@ -876,7 +880,7 @@ Returns \"\" to not break --no-window-system." ;; (declare-function eyebrowse--get 'eyebrowse) -(doom-modeline-def-segment! workspace-number +(doom-modeline-def-segment workspace-number "The current workspace name or number. Requires `eyebrowse-mode' to be enabled." (if (and (bound-and-true-p eyebrowse-mode) @@ -893,25 +897,25 @@ enabled." ;; 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)) ;; ;; Hooks From 64404ed72e9cf2eacaad406007c4a870f3dd2b73 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Tue, 19 Jun 2018 18:26:17 +0800 Subject: [PATCH 16/52] Remove `doom-modeline-add-transient-hook!`. --- doom-modeline.el | 39 ++++++++------------------------------- 1 file changed, 8 insertions(+), 31 deletions(-) diff --git a/doom-modeline.el b/doom-modeline.el index ef2837a..4b55f93 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -76,25 +76,6 @@ (defvar doom-modeline--transient-counter 0)) -(defmacro doom-modeline-add-transient-hook! (hook &rest forms) - "Attaches 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)))))) ;; ;; Modeline library @@ -235,19 +216,15 @@ If STRICT-P, return nil if no project was found, otherwise return finally return 0)) (advice-add #'anzu--where-is-here :override #'doom-modeline-fix-anzu-count) -(when (featurep 'evil-anzu) - (doom-modeline-add-transient-hook! #'evil-ex-start-search (require 'evil-anzu)) +;; 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 'iedit-mode-end-hook #'anzu--reset-status) ;; Keep `doom-modeline-current-window' up-to-date From 57fa2b22bb42316067ac0576f19938c83a904124 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Tue, 19 Jun 2018 18:36:43 +0800 Subject: [PATCH 17/52] Fix: `doom-modeline-set`. --- doom-modeline.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doom-modeline.el b/doom-modeline.el index 4b55f93..eb4ab51 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -163,7 +163,7 @@ Throws an error if it doesn't exist." (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 (m (doom-modeline key)) + (when-let ((modeline (doom-modeline key))) (setf (if default (default-value 'mode-line-format) (buffer-local-value 'mode-line-format (current-buffer))) From 03658c4f28b247c3ac74d4684f1f476237ed1607 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Tue, 19 Jun 2018 18:38:56 +0800 Subject: [PATCH 18/52] Fix: `doom-modeline-vspc`. --- doom-modeline.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doom-modeline.el b/doom-modeline.el index eb4ab51..b961c39 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -635,8 +635,8 @@ directory, the file name, and its state (modified, read-only or non-existent)." ;; (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.") (defun doom-modeline-icon (icon &optional text face voffset) "Displays an ICON with FACE, followed by TEXT. From 96d6fda059c89da38b50a80c0a9047b80d0f9457 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Tue, 19 Jun 2018 18:54:02 +0800 Subject: [PATCH 19/52] Fix anzu issue. --- doom-modeline.el | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doom-modeline.el b/doom-modeline.el index b961c39..1a17fc0 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -217,10 +217,10 @@ If STRICT-P, return nil if no project was found, otherwise return (advice-add #'anzu--where-is-here :override #'doom-modeline-fix-anzu-count) ;; 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)) +;; (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) From 55269e7288edb7e8c86129a3eb8481a9207f32e1 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Tue, 19 Jun 2018 19:01:56 +0800 Subject: [PATCH 20/52] Fix for `evil-anzu`. --- doom-modeline.el | 116 ++++++++++++++++++++++++----------------------- 1 file changed, 59 insertions(+), 57 deletions(-) diff --git a/doom-modeline.el b/doom-modeline.el index 1a17fc0..4745d0d 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -204,27 +204,29 @@ If STRICT-P, return nil if no project was found, otherwise return ;; 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 (feature 'evil-anzu) + (setq anzu-cons-mode-line-p nil + anzu-minimum-input-length 1 + anzu-search-threshold 250) -(defun doom-modeline-fix-anzu-count (positions here) - (cl-loop for (start . end) in positions - collect t into before - when (and (>= here start) (<= here end)) - return (length before) - finally return 0)) -(advice-add #'anzu--where-is-here :override #'doom-modeline-fix-anzu-count) + (defun doom-modeline-fix-anzu-count (positions here) + (cl-loop for (start . end) in positions + collect t into before + when (and (>= here start) (<= here end)) + return (length before) + finally return 0)) + (advice-add #'anzu--where-is-here :override #'doom-modeline-fix-anzu-count) -;; 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 '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 @@ -498,50 +500,50 @@ 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." From f281bd872f9a807d3a6d2190d6dd3c78c8da3137 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Tue, 19 Jun 2018 19:08:55 +0800 Subject: [PATCH 21/52] Refactor. --- doom-modeline.el | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/doom-modeline.el b/doom-modeline.el index 4745d0d..70bde39 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -120,16 +120,16 @@ ((error "%s is not a valid segment" seg)))) (nreverse forms))) -(defmacro doom-modeline-def (name lhs &optional rhs) +(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'. 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))) @@ -160,7 +160,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))) @@ -876,25 +876,25 @@ enabled." ;; 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)) ;; ;; Hooks @@ -921,25 +921,25 @@ enabled." ;; of Emacs, someone give the man a modeline! (dolist (bname '("*scratch*" "*Messages*")) (with-current-buffer bname - (doom-modeline-set 'main))))) + (doom-modeline-set-modeline 'main))))) (defun doom-modeline-set-special-modeline () "Set sepcial mode-line." - (doom-modeline-set 'special)) + (doom-modeline-set-modeline 'special)) (defun doom-modeline-set-media-modeline () "Set media mode-line." - (doom-modeline-set 'media)) + (doom-modeline-set-modeline 'media)) (defun doom-modeline-set-project-modeline () "Set project mode-line." - (doom-modeline-set 'project)) + (doom-modeline-set-modeline 'project)) ;; ;; Bootstrap ;; -(doom-modeline-set 'main t) ; set default modeline +(doom-modeline-set-modeline 'main t) ; set default modeline ;; (add-hook 'doom-load-theme-hook #'doom-modeline-init) ;; (add-hook 'doom-scratch-buffer-hook #'doom-modeline-set-special-modeline) From 1a98d961ddcab7a2dfe88f05d27ddc03894b2c14 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Thu, 21 Jun 2018 00:23:00 +0800 Subject: [PATCH 22/52] Silence compiler warnings. --- doom-modeline.el | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/doom-modeline.el b/doom-modeline.el index 70bde39..4d411da 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -279,11 +279,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 From 04641d56437d5aedd3c3f8ca0ba1b87c57f6e1fb Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Thu, 21 Jun 2018 15:45:42 +0800 Subject: [PATCH 23/52] Fix typo. --- doom-modeline.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doom-modeline.el b/doom-modeline.el index 4d411da..b06831c 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -204,7 +204,7 @@ If STRICT-P, return nil if no project was found, otherwise return ;; anzu and evil-anzu expose current/total state that can be displayed in the ;; mode-line. -(when (feature 'evil-anzu) +(when (featurep 'evil-anzu) (setq anzu-cons-mode-line-p nil anzu-minimum-input-length 1 anzu-search-threshold 250) From 14e4b8ba5a187fc679f14d2837c8440791a436fd Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Thu, 21 Jun 2018 17:40:00 +0800 Subject: [PATCH 24/52] Disable anzu modeline. --- doom-modeline.el | 1 + 1 file changed, 1 insertion(+) diff --git a/doom-modeline.el b/doom-modeline.el index b06831c..82245a5 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -735,6 +735,7 @@ lines are selected, or the NxM dimensions of a block selection." (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'." + (setq anzu-cons-mode-line-p nil) (when (and anzu--state (not iedit-mode)) (propertize (let ((here anzu--current-position) From 616fdabd8d7a48a174397c5e30eb52272f05d351 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Thu, 21 Jun 2018 18:31:16 +0800 Subject: [PATCH 25/52] Fix: set current window after switching window. --- doom-modeline.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doom-modeline.el b/doom-modeline.el index 82245a5..76e4297 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -243,17 +243,17 @@ If STRICT-P, return nil if no project was found, otherwise return (force-mode-line-update)) (add-hook 'window-configuration-change-hook #'doom-modeline-set-selected-window) -(add-hook 'doom-after-switch-window-hook #'doom-modeline-set-selected-window) +(add-hook 'switch-window-finish-hook #'doom-modeline-set-selected-window) (with-no-warnings (if (not (boundp 'after-focus-change-function)) (progn (add-hook 'focus-in-hook #'doom-modeline-set-selected-window) (add-hook 'focus-out-hook #'doom-modeline-unset-selected-window)) (defun doom-modeline-refresh-frame () - (setq +doom-modeline-current-window nil) + (setq doom-modeline-current-window nil) (cl-loop for frame in (frame-list) if (eq (frame-focus-state frame) t) - return (setq +doom-modeline-current-window (frame-selected-window frame))) + return (setq doom-modeline-current-window (frame-selected-window frame))) (force-mode-line-update)) (add-function :after after-focus-change-function #'doom-modeline-refresh-frame))) From 2beb80206a58ffbef69c183631a5697ca8e54fd0 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Thu, 21 Jun 2018 18:43:02 +0800 Subject: [PATCH 26/52] Fix: set current window after switching window via click. --- doom-modeline.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doom-modeline.el b/doom-modeline.el index 76e4297..e7fbac4 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -243,7 +243,8 @@ If STRICT-P, return nil if no project was found, otherwise return (force-mode-line-update)) (add-hook 'window-configuration-change-hook #'doom-modeline-set-selected-window) -(add-hook 'switch-window-finish-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) (with-no-warnings (if (not (boundp 'after-focus-change-function)) (progn From e69364282cb1aa1364c576fbbebc0dec7c7cbeac Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Thu, 21 Jun 2018 19:06:00 +0800 Subject: [PATCH 27/52] Update functions for icons. --- doom-modeline.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doom-modeline.el b/doom-modeline.el index e7fbac4..acb487c 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -364,17 +364,17 @@ active." (defun doom-modeline-maybe-icon-octicon (&rest args) "Display octicon via `ARGS'." - (when (and (featurep 'all-the-icons) (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 font awesome icon via `ARGS'." - (when (and (featurep 'all-the-icons) (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 via `ARGS'." - (when (and (featurep 'all-the-icons) (display-graphic-p) (not (eq system-type 'windows-nt))) + (when (display-graphic-p) (apply 'all-the-icons-material args))) (defsubst doom-modeline--active () From e7144403512371c57bea928e103276a6d8239dbb Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Thu, 21 Jun 2018 22:30:41 +0800 Subject: [PATCH 28/52] Support versions including Python, Ruby and Golang. --- doom-modeline.el | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/doom-modeline.el b/doom-modeline.el index 4d411da..b15f433 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -257,6 +257,19 @@ If STRICT-P, return nil if no project was found, otherwise return (force-mode-line-update)) (add-function :after after-focus-change-function #'doom-modeline-refresh-frame))) +;; 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 () + (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))))) + ;; ;; Variables ;; @@ -948,27 +961,17 @@ enabled." (add-hook 'image-mode-hook #'doom-modeline-set-media-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 () - (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 +;; 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"))) + (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'"))) + ;; Ensure modeline is inactive when Emacs is unfocused (and active otherwise) (defvar doom-modeline-remap-face-cookie nil) From 0db45235c3cbbb43ca5151c5284869521bd34f7a Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Fri, 22 Jun 2018 12:13:46 +0800 Subject: [PATCH 29/52] Enable 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 613c963..fd03127 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -892,7 +892,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 d4179d8d28f5e9c9e39b0b2de5849ea5d5c45ee2 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Fri, 22 Jun 2018 15:08:20 +0800 Subject: [PATCH 30/52] Update README. --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 597061e..5b8f391 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 f3abba25a81496f3f49ddbc99e9bb6081a8ab71c Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Mon, 25 Jun 2018 23:45:40 +0800 Subject: [PATCH 31/52] Update README. --- README.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5b8f391..37a47ce 100644 --- a/README.md +++ b/README.md @@ -37,12 +37,21 @@ 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 c712afc6259ea66eb223d5c9c2d0d3ce28390ece Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Mon, 25 Jun 2018 23:57:26 +0800 Subject: [PATCH 32/52] 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 2c7c908aa05cf18aab062d4ec60564e574965061 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Wed, 27 Jun 2018 01:34:08 +0800 Subject: [PATCH 33/52] Fix: doom-column -> doom-modeline-column. --- doom-modeline.el | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/doom-modeline.el b/doom-modeline.el index fd03127..f600bca 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -696,6 +696,7 @@ icons." ;; (defsubst doom-modeline-column (pos) + "Get the column of the position `POS'." (save-excursion (goto-char pos) (current-column))) @@ -715,8 +716,8 @@ lines are selected, or the NxM dimensions of a block selection." (let ((lines (count-lines beg (min end (point-max))))) (concat (cond ((or (bound-and-true-p rectangle-mark-mode) (eq 'block evil-visual-selection)) - (let ((cols (abs (- (doom-column end) - (doom-column beg))))) + (let ((cols (abs (- (doom-modeline-column end) + (doom-modeline-column beg))))) (format "%dx%dB" lines cols))) ((eq evil-visual-selection 'line) (format "%dL" lines)) From 0cc7118b6cdcc9a596af17bf26abbcd40d9d0540 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Wed, 27 Jun 2018 02:38:48 +0800 Subject: [PATCH 34/52] Fix warnings. --- doom-modeline.el | 238 +++++++++++++++++++++++++---------------------- 1 file changed, 126 insertions(+), 112 deletions(-) diff --git a/doom-modeline.el b/doom-modeline.el index f600bca..54080b2 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -50,9 +50,117 @@ (require 'projectile) (require 'shrink-path) -(when (>= emacs-major-version 26) - (require 'subr-x) - (defalias 'when-let 'when-let*)) +;; +;; Variables +;; + +(defvar doom-modeline-height 29 + "How tall the mode-line should be (only respected in GUI Emacs).") + +(defvar doom-modeline-bar-width 3 + "How wide the mode-line bar should be (only respected in GUI Emacs).") + +(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 + "TODO" + :group 'faces) + +(defface doom-modeline-buffer-path + '((t (:inherit (mode-line-emphasis bold)))) + "Face used for the dirname part of the buffer path." + :group 'doom-modeline) + +(defface doom-modeline-buffer-file + '((t (:inherit (mode-line-buffer-id bold)))) + "Face used for the filename part of the mode-line buffer path." + :group 'doom-modeline) + +(defface doom-modeline-buffer-modified + '((t (:inherit (error bold) :background nil))) + "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)))) + "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)))) + "Face for info-level messages in the modeline. Used by `*vc'." + :group 'doom-modeline) + +(defface doom-modeline-warning + `((t (:inherit (warning bold)))) + "Face for warnings in the modeline. Used by `*flycheck'" + :group 'doom-modeline) + +(defface doom-modeline-urgent + `((t (:inherit (error bold)))) + "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-eyebrowse '((t ())) + "The face used for eyebrowse." + :group 'doom-modeline) (eval-and-compile (defun doom-modeline--resolve-hook-forms (hooks) @@ -163,7 +271,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))) @@ -181,6 +289,7 @@ If STRICT-P, return nil if no project was found, otherwise return ;; (defun doom-modeline-eldoc (text) + "Get eldoc TEXT for mode-line." (concat (when (display-graphic-p) (doom-modeline--make-xpm 'doom-modeline-eldoc-bar doom-modeline-height @@ -189,7 +298,7 @@ If STRICT-P, return nil if no project was found, otherwise return ;; 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)) @@ -233,12 +342,13 @@ If STRICT-P, return nil if no project was found, otherwise return (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) (force-mode-line-update)))) (defun doom-modeline-unset-selected-window () + "Unset `doom-modeline-current-window' appropriately." (setq doom-modeline-current-window nil) (force-mode-line-update)) @@ -264,113 +374,13 @@ If STRICT-P, return nil if no project was found, otherwise return (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 info on 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))))) - -;; -;; Variables -;; - -(defvar doom-modeline-height 29 - "How tall the mode-line should be (only respected in GUI emacs).") - -(defvar doom-modeline-bar-width 3 - "How wide the mode-line bar should be (only respected in GUI emacs).") - -(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 - "TODO" - :group 'faces) - -(defface doom-modeline-buffer-path - '((t (:inherit (mode-line-emphasis bold)))) - "Face used for the dirname part of the buffer path." - :group 'doom-modeline) - -(defface doom-modeline-buffer-file - '((t (:inherit (mode-line-buffer-id bold)))) - "Face used for the filename part of the mode-line buffer path." - :group 'doom-modeline) - -(defface doom-modeline-buffer-modified - '((t (:inherit (error bold) :background nil))) - "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)))) - "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)))) - "Face for info-level messages in the modeline. Used by `*vc'." - :group 'doom-modeline) - -(defface doom-modeline-warning - `((t (:inherit (warning bold)))) - "Face for warnings in the modeline. Used by `*flycheck'" - :group 'doom-modeline) - -(defface doom-modeline-urgent - `((t (:inherit (error bold)))) - "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-eyebrowse '((t ())) - "The face used for eyebrowse." - :group 'doom-modeline) - ;; ;; Modeline helpers ;; @@ -391,6 +401,7 @@ active." (apply 'all-the-icons-material args))) (defsubst doom-modeline--active () + "Whether is an active window." (eq (selected-window) doom-modeline-current-window)) (defun doom-modeline--make-xpm (face width height) @@ -441,7 +452,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))) @@ -460,7 +471,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) @@ -477,7 +488,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. @@ -593,6 +604,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))) @@ -670,6 +682,7 @@ Uses `all-the-icons-material' to fetch the icon." (add-hook 'flycheck-mode-hook #'doom-modeline-update-flycheck-segment) (defun doom-modeline-update-flycheck-segment (&optional status) + "Update flycheck segment via STATUS." (setq doom-modeline--flycheck (pcase status (`finished (if flycheck-current-errors @@ -748,8 +761,9 @@ lines are selected, or the NxM dimensions of a block selection." 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. +Requires `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 From 2383b1c370ec9841dcff3a65bd5ecf89944c6eae Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Wed, 27 Jun 2018 04:44:26 +0800 Subject: [PATCH 35/52] Update vcs. --- doom-modeline.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doom-modeline.el b/doom-modeline.el index 54080b2..626cd37 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -624,7 +624,7 @@ directory, the file name, and its state (modified, read-only or non-existent)." (let ((face 'mode-line-inactive) (active (doom-modeline--active)) (all-the-icons-default-adjust -0.1)) - (concat " " + (concat (if (display-graphic-p) " ") (cond ((memq state '(edited added)) (if active (setq face 'doom-modeline-info)) (doom-modeline-maybe-icon-octicon From c354cdde0c458020601f379b31df2c73f83fb8f0 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Wed, 27 Jun 2018 14:32:23 +0800 Subject: [PATCH 36/52] Remove `map`. --- doom-modeline.el | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/doom-modeline.el b/doom-modeline.el index 626cd37..fdc40c2 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -46,7 +46,6 @@ (require 'all-the-icons) (require 'eldoc-eval) -(require 'map) (require 'projectile) (require 'shrink-path) @@ -202,13 +201,13 @@ active." (format "%s modeline segment" name)))) (cond ((and (symbolp (car body)) (not (cdr body))) - (map-put doom-modeline-var-alist name (car body)) - `(map-put doom-modeline-var-alist ',name ',(car body))) + (add-to-list 'doom-modeline-var-alist (cons name (car body))) + `(add-to-list 'doom-modeline-var-alist (cons ',name ',(car body)))) (t - (map-put doom-modeline-fn-alist name sym) + (add-to-list 'doom-modeline-fn-alist (cons name sym)) `(progn (fset ',sym (lambda () ,docstring ,@body)) - (map-put doom-modeline-fn-alist ',name ',sym) + (add-to-list 'doom-modeline-fn-alist (cons ',name ',sym)) ,(unless (bound-and-true-p byte-compile-current-file) `(let (byte-compile-warnings) (byte-compile #',sym)))))))) From bd097590a28f6a0a3ba388456ffbbb73af1a3336 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Thu, 28 Jun 2018 00:26:44 +0800 Subject: [PATCH 37/52] Fix: update vcs. --- doom-modeline.el | 72 +++++++++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 40 deletions(-) diff --git a/doom-modeline.el b/doom-modeline.el index fdc40c2..a69428d 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -613,48 +613,40 @@ directory, the file name, and its state (modified, read-only or non-existent)." ;; vcs ;; -(defvar-local doom-modeline--vcs nil) -(defun doom-modeline--update-vcs () - "Update vsc status in mode-line." - (setq doom-modeline--vcs - (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)) - " ")))))) -(add-hook 'after-save-hook #'doom-modeline--update-vcs) -(add-hook 'find-file-hook #'doom-modeline--update-vcs t) - (doom-modeline-def-segment vcs "Displays the current branch, colored based on its state." - doom-modeline--vcs) + (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)) + " "))))) ;; From 10ec55adcc69a08cbc3df814280f5e47f5f043c3 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Thu, 28 Jun 2018 17:06:11 +0800 Subject: [PATCH 38/52] Update vcs state in mode-line after refreshing in magit. --- doom-modeline.el | 85 ++++++++++++++++++++++++++++++------------------ 1 file changed, 53 insertions(+), 32 deletions(-) diff --git a/doom-modeline.el b/doom-modeline.el index a69428d..47daa02 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -613,40 +613,61 @@ directory, the file name, and its state (modified, read-only or non-existent)." ;; vcs ;; +(defvar-local doom-modeline--vcs nil) +(defun doom-modeline--update-vcs () + "Update vsc state in mode-line." + (setq doom-modeline--vcs + (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)) + " ")))))) +(add-hook 'after-save-hook #'doom-modeline--update-vcs) +(add-hook 'find-file-hook #'doom-modeline--update-vcs t) + +(declare-function magit-toplevel "magit-git") +(defun doom-modeline-magit-post-refresh () + "Update vcs state in mode-line after refreshing in magit." + (dolist (buf (buffer-list)) + (when (and (not (buffer-modified-p buf)) + (buffer-file-name buf) + (file-exists-p (buffer-file-name buf)) + (file-in-directory-p (buffer-file-name buf) (magit-toplevel))) + (with-current-buffer buf + (vc-refresh-state) + (doom-modeline--update-vcs))))) +(add-hook 'magit-post-refresh-hook #'doom-modeline-magit-post-refresh) + (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)) - " "))))) + doom-modeline--vcs) ;; From ae9d073377bb883087d57a2315a4863e08b3bb96 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Sun, 1 Jul 2018 02:19:54 +0800 Subject: [PATCH 39/52] Fix issues according to feedbacks from mepla. --- doom-modeline.el | 238 ++++++++++++++++++++++++++--------------------- 1 file changed, 130 insertions(+), 108 deletions(-) diff --git a/doom-modeline.el b/doom-modeline.el index a69428d..21b9b8c 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.2.0 -;; Package-Requires: ((emacs "25.1") (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 "25.1") (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. @@ -62,104 +62,92 @@ (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 - "TODO" + "Doom mode-line faces." :group 'faces) (defface doom-modeline-buffer-path '((t (:inherit (mode-line-emphasis bold)))) - "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 bold)))) - "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 bold) :background nil))) - "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)))) - "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)))) - "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)))) - "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)))) - "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-eyebrowse '((t ())) - "The face used for eyebrowse." - :group 'doom-modeline) + "The face used for eyebrowse.") (eval-and-compile (defun doom-modeline--resolve-hook-forms (hooks) @@ -193,7 +181,7 @@ active." (defvar doom-modeline-var-alist ())) (defmacro doom-modeline-def-segment (name &rest body) - "Defines a modeline segment and byte compiles it." + "Defines a modeline segment NAME with BODY and byte compiles it." (declare (indent defun) (doc-string 2)) (let ((sym (intern (format "doom-modeline-segment--%s" name))) (docstring (if (stringp (car body)) @@ -229,10 +217,11 @@ active." (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'. -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)) @@ -262,14 +251,16 @@ Example: (defun doom-modeline (key) "Return a mode-line configuration associated with KEY (a symbol). -Throws an error if it doesn't exist." + + Throws an error if it doesn't exist." (let ((fn (intern (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) @@ -278,7 +269,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))) @@ -404,7 +396,7 @@ If STRICT-P, return nil if no project was found, otherwise return (eq (selected-window) doom-modeline-current-window)) (defun doom-modeline--make-xpm (face width height) - "Create an XPM bitmap. Inspired by `powerline''s `pl/make-xpm'." + "Create an XPM bitmap via FACE, WIDTH and HEIGHT. Inspired by `powerline''s `pl/make-xpm'." (propertize " " 'display (let ((data (make-list height (make-list width 1))) @@ -452,7 +444,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) @@ -470,7 +463,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) @@ -488,11 +481,12 @@ 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 -fish-shell style. -Example: -~/Projects/FOSS/emacs/lisp/comint.el => ~/P/F/emacs/lisp/comint.el" + 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" (let* ((project-root (doom-modeline-project-root)) (file-name-split (shrink-path-file-mixed project-root (file-name-directory buffer-file-name) @@ -613,40 +607,61 @@ directory, the file name, and its state (modified, read-only or non-existent)." ;; vcs ;; +(defvar-local doom-modeline--vcs nil) +(defun doom-modeline--update-vcs () + "Update vsc state in mode-line." + (setq doom-modeline--vcs + (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)) + " ")))))) +(add-hook 'after-save-hook #'doom-modeline--update-vcs) +(add-hook 'find-file-hook #'doom-modeline--update-vcs t) + +(declare-function magit-toplevel "magit-git") +(defun doom-modeline-magit-post-refresh () + "Update vcs state in mode-line after refreshing in magit." + (dolist (buf (buffer-list)) + (when (and (not (buffer-modified-p buf)) + (buffer-file-name buf) + (file-exists-p (buffer-file-name buf)) + (file-in-directory-p (buffer-file-name buf) (magit-toplevel))) + (with-current-buffer buf + (vc-refresh-state) + (doom-modeline--update-vcs))))) +(add-hook 'magit-post-refresh-hook #'doom-modeline-magit-post-refresh) + (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)) - " "))))) + doom-modeline--vcs) ;; @@ -713,17 +728,19 @@ segment.") lines are selected, or the NxM dimensions of a block selection." (when (and mark-active (doom-modeline--active)) (cl-destructuring-bind (beg . end) - (if (eq evil-state 'visual) + (if (and (bound-and-true-p evil-state) (eq evil-state 'visual)) (cons evil-visual-beginning evil-visual-end) (cons (region-beginning) (region-end))) (propertize (let ((lines (count-lines beg (min end (point-max))))) (concat (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 end) (doom-modeline-column beg))))) (format "%dx%dB" lines cols))) - ((eq evil-visual-selection 'line) + ((and (bound-and-true-p evil-visual-selection) + (eq evil-visual-selection 'line)) (format "%dL" lines)) ((> lines 1) (format "%dC %dL" (- end beg) lines)) @@ -753,10 +770,13 @@ lines are selected, or the NxM dimensions of a block selection." (defsubst doom-modeline--anzu () "Show the match index and total number thereof. -Requires `anzu', also `evil-anzu' if using `evil-mode' for compatibility with + + Requires `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))) (propertize (let ((here anzu--current-position) (total anzu--total-matched)) @@ -772,7 +792,8 @@ Requires `anzu', also `evil-anzu' if using `evil-mode' for compatibility with (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))) @@ -787,11 +808,12 @@ Requires `anzu', also `evil-anzu' if using `evil-mode' for compatibility with '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 () "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 69e47314a3fbcd27cbc952560bb2ba585d0189e4 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Mon, 2 Jul 2018 16:28:16 +0800 Subject: [PATCH 40/52] Update comments. --- doom-modeline.el | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/doom-modeline.el b/doom-modeline.el index 21b9b8c..e659efd 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -62,7 +62,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 @@ -218,10 +218,10 @@ active.") (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'. - Example: +AME 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)) @@ -270,7 +270,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))) @@ -445,7 +445,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) @@ -771,7 +771,7 @@ lines are selected, or the NxM dimensions of a block selection." (defsubst doom-modeline--anzu () "Show the match index and total number thereof. - Requires `anzu', also `evil-anzu' if using `evil-mode' for compatibility with +Requires `anzu', also `evil-anzu' if using `evil-mode' for compatibility with `evil-search'." (setq anzu-cons-mode-line-p nil) (when (and (featurep 'anzu) From f6f73ddddb24b4ed7a7505af6fd67de24ec74d44 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Mon, 2 Jul 2018 17:35:21 +0800 Subject: [PATCH 41/52] Add window number for special, project and media modeline. --- doom-modeline.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doom-modeline.el b/doom-modeline.el index e659efd..16e2edd 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -928,15 +928,15 @@ enabled." (media-info major-mode)) (doom-modeline-def-modeline special - (bar matches " " buffer-info-simple " %l:%c %p " selection-info) + (window-number bar matches " " buffer-info-simple " %l:%c %p " selection-info) (buffer-encoding major-mode flycheck)) (doom-modeline-def-modeline project - (bar buffer-default-directory) + (window-number bar buffer-default-directory) (major-mode)) (doom-modeline-def-modeline media - (bar " %b ") + (window-number bar " %b ") (media-info major-mode)) ;; From 335074b2b5850ecf8c4b97d0276df33d05e6d313 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Mon, 2 Jul 2018 17:36:43 +0800 Subject: [PATCH 42/52] Autoload more functions. --- doom-modeline.el | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doom-modeline.el b/doom-modeline.el index 16e2edd..8dae58b 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -966,14 +966,17 @@ enabled." (with-current-buffer bname (doom-modeline-set-modeline 'main))))) +;;;###autoload (defun doom-modeline-set-special-modeline () "Set sepcial mode-line." (doom-modeline-set-modeline 'special)) +;;;###autoload (defun doom-modeline-set-media-modeline () "Set media mode-line." (doom-modeline-set-modeline 'media)) +;;;###autoload (defun doom-modeline-set-project-modeline () "Set project mode-line." (doom-modeline-set-modeline 'project)) From ed7027dbc9185ae042b2878633a0900c6bc03c9a Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Mon, 2 Jul 2018 17:57:23 +0800 Subject: [PATCH 43/52] Set special modeline for org-src-mode. --- doom-modeline.el | 1 + 1 file changed, 1 insertion(+) diff --git a/doom-modeline.el b/doom-modeline.el index 8dae58b..f53bacf 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -992,6 +992,7 @@ enabled." ;; (add-hook 'doom-dashboard-mode-hook #'doom-modeline-set-project-modeline) (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) ;; Versions, support Python, Ruby and Golang From b8e73dc982fa9ed9464c62c8eb9db0364044bed3 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Mon, 2 Jul 2018 18:10:59 +0800 Subject: [PATCH 44/52] Show window number while the count of windows is greater than 2. --- doom-modeline.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doom-modeline.el b/doom-modeline.el index f53bacf..c239c99 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -890,7 +890,8 @@ Returns \"\" to not break --no-window-system." (advice-add #'window-numbering-clear-mode-line :override #'ignore) (doom-modeline-def-segment window-number - (if (bound-and-true-p window-numbering-mode) + (if (and (bound-and-true-p window-numbering-mode) + (< 2 (length (window-list)))) (propertize (format " %s " (window-numbering-get-number-string)) 'face (if (doom-modeline--active) 'doom-modeline-bar From 4ef93c7aabd6a485eec6e9eeb68bda6f681f892f Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Mon, 2 Jul 2018 18:26:19 +0800 Subject: [PATCH 45/52] Ignore minibuffer while counting windows. --- doom-modeline.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doom-modeline.el b/doom-modeline.el index c239c99..054c4e6 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -891,7 +891,7 @@ Returns \"\" to not break --no-window-system." (doom-modeline-def-segment window-number (if (and (bound-and-true-p window-numbering-mode) - (< 2 (length (window-list)))) + (< 2 (length (window-list nil 'ignore)))) (propertize (format " %s " (window-numbering-get-number-string)) 'face (if (doom-modeline--active) 'doom-modeline-bar From 28000c45f452130e303c84d96c9f3f429729691d Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Mon, 2 Jul 2018 19:05:53 +0800 Subject: [PATCH 46/52] Support winum-mode. --- doom-modeline.el | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/doom-modeline.el b/doom-modeline.el index 054c4e6..fe0c7f6 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -49,6 +49,7 @@ (require 'projectile) (require 'shrink-path) + ;; ;; Variables ;; @@ -90,6 +91,9 @@ Given ~/Projects/FOSS/emacs/lisp/comint.el (defvar iedit-mode) (defvar iedit-occurrences-overlays) (defvar text-scale-mode-amount) +(defvar winum-auto-setup-mode-line) + + ;; ;; Custom faces ;; @@ -890,13 +894,20 @@ Returns \"\" to not break --no-window-system." (advice-add #'window-numbering-clear-mode-line :override #'ignore) (doom-modeline-def-segment window-number - (if (and (bound-and-true-p window-numbering-mode) - (< 2 (length (window-list nil 'ignore)))) - (propertize (format " %s " (window-numbering-get-number-string)) - 'face (if (doom-modeline--active) - 'doom-modeline-bar - 'doom-modeline-inactive-bar)) - "")) + (setq winum-auto-setup-mode-line nil) + (let ((num (cond + ((bound-and-true-p winum-mode) + (winum-get-number-string)) + ((bound-and-true-p window-numbering-mode) + (window-numbering-get-number-string)) + (t "")))) + (if (and (< 0 (length num)) + (< 2 (length (window-list nil 'ignore)))) + (propertize (format " %s " num) + 'face (if (doom-modeline--active) + 'doom-modeline-bar + 'doom-modeline-inactive-bar)) + ""))) ;; ;; workspace-number From ff3bd48b34e70b87208d2bdde998130be58d4140 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Mon, 2 Jul 2018 20:31:11 +0800 Subject: [PATCH 47/52] Always show window numbers in all frames. --- doom-modeline.el | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/doom-modeline.el b/doom-modeline.el index fe0c7f6..7357f40 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -901,8 +901,7 @@ Returns \"\" to not break --no-window-system." ((bound-and-true-p window-numbering-mode) (window-numbering-get-number-string)) (t "")))) - (if (and (< 0 (length num)) - (< 2 (length (window-list nil 'ignore)))) + (if (< 0 (length num)) (propertize (format " %s " num) 'face (if (doom-modeline--active) 'doom-modeline-bar From 28f91fd925d7e07819c37f91df091706dd562aa0 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Tue, 3 Jul 2018 21:44:37 +0800 Subject: [PATCH 48/52] Fix comments. --- doom-modeline.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doom-modeline.el b/doom-modeline.el index 7357f40..40f0ca3 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -222,7 +222,7 @@ active.") (defmacro doom-modeline-def-modeline (name lhs &optional rhs) "Defines a modeline format and byte-compiles it. -AME is a symbol to identify it (used by `doom-modeline' for retrieval). +NAME is a symbol to identify it (used by `doom-modeline' for retrieval). LHS and RHS are lists of symbols of modeline segments defined with `doom-modeline-def-segment'. Example: From 258179ba7a11cc297dce91dec60733b8c7bfe203 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Wed, 4 Jul 2018 02:15:48 +0800 Subject: [PATCH 49/52] Fix env versions on mode-line. --- doom-modeline.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doom-modeline.el b/doom-modeline.el index 40f0ca3..a16c67c 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -1009,13 +1009,13 @@ enabled." ;; Versions, support Python, Ruby and Golang (add-hook 'python-mode-hook (lambda () - (setq doom-modeline-env-command "python --version 2>&1 | cut -d' ' -f2"))) + (setq doom-modeline-env-command "python --version 2>&1 | cut -d' ' -f2 | sed -n '1p'"))) (add-hook 'ruby-mode-hook (lambda () - (setq doom-modeline-env-command "ruby --version 2>&1 | cut -d' ' -f2"))) + (setq doom-modeline-env-command "ruby --version 2>&1 | cut -d' ' -f2 | sed -n '1p'"))) (add-hook 'go-mode-hook (lambda () - (setq doom-modeline-env-command "go version 2>&1 | cut -d' ' -f3 | tr -d 'go'"))) + (setq doom-modeline-env-command "go version 2>&1 | cut -d' ' -f3 | tr -d 'go' | sed -n '1p'"))) ;; Ensure modeline is inactive when Emacs is unfocused (and active otherwise) From 926a83360c3c685279344f87fcfaffc6c655dcae Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Wed, 4 Jul 2018 02:24:34 +0800 Subject: [PATCH 50/52] Fix errors for env versions in mode-line. --- doom-modeline.el | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/doom-modeline.el b/doom-modeline.el index a16c67c..c064bc2 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -1009,13 +1009,16 @@ enabled." ;; Versions, support Python, Ruby and Golang (add-hook 'python-mode-hook (lambda () - (setq doom-modeline-env-command "python --version 2>&1 | cut -d' ' -f2 | sed -n '1p'"))) + (when (executable-find "python") + (setq doom-modeline-env-command "python --version 2>&1 | cut -d' ' -f2 | sed -n '1p'")))) (add-hook 'ruby-mode-hook (lambda () - (setq doom-modeline-env-command "ruby --version 2>&1 | cut -d' ' -f2 | sed -n '1p'"))) + (when (executable-find "ruby") + (setq doom-modeline-env-command "ruby --version 2>&1 | cut -d' ' -f2 | sed -n '1p'")))) (add-hook 'go-mode-hook (lambda () - (setq doom-modeline-env-command "go version 2>&1 | cut -d' ' -f3 | tr -d 'go' | sed -n '1p'"))) + (when (executable-find "go") + (setq doom-modeline-env-command "go version 2>&1 | cut -d' ' -f3 | tr -d 'go' | sed -n '1p'")))) ;; Ensure modeline is inactive when Emacs is unfocused (and active otherwise) From 774879ef0fbbc2881f57533e5c3459e57e595405 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Thu, 5 Jul 2018 14:01:47 +0800 Subject: [PATCH 51/52] Update README and package descriptions. --- README.md | 10 ---------- doom-modeline.el | 11 +++++++++++ 2 files changed, 11 insertions(+), 10 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 7357f40..ff00886 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -41,6 +41,17 @@ ;; 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: From b3525926cb71d957cbbda84d823bac26acf25ae6 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Thu, 5 Jul 2018 14:29:41 +0800 Subject: [PATCH 52/52] Update doom-modeline.el Remove duplicated codes. --- doom-modeline.el | 56 ------------------------------------------------ 1 file changed, 56 deletions(-) diff --git a/doom-modeline.el b/doom-modeline.el index 2766fa2..019e032 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -163,51 +163,6 @@ active.") (defface doom-modeline-eyebrowse '((t ())) "The face used for eyebrowse.") -;; -;; 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) -(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) ;; ;; Custom faces @@ -1162,17 +1117,6 @@ enabled." (add-hook 'focus-in-hook #'doom-modeline-focus) (add-hook 'focus-out-hook #'doom-modeline-unfocus) -;; 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) ;;; doom-modeline.el ends here