doom-modeline.el (10198B)
1 ;;; doom-modeline.el --- A minimal and modern mode-line -*- lexical-binding: t; -*- 2 3 ;; Copyright (C) 2018-2024 Vincent Zhang 4 5 ;; Author: Vincent Zhang <seagle0128@gmail.com> 6 ;; Homepage: https://github.com/seagle0128/doom-modeline 7 ;; Version: 4.2.0 8 ;; Package-Requires: ((emacs "25.1") (compat "29.1.4.2") (nerd-icons "0.1.0") (shrink-path "0.3.1")) 9 ;; Keywords: faces mode-line 10 11 ;; This file is not part of GNU Emacs. 12 13 ;; 14 ;; This program is free software; you can redistribute it and/or modify 15 ;; it under the terms of the GNU General Public License as published by 16 ;; the Free Software Foundation, either version 3 of the License, or 17 ;; (at your option) any later version. 18 ;; 19 ;; This program is distributed in the hope that it will be useful, 20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 ;; GNU General Public License for more details. 23 ;; 24 ;; You should have received a copy of the GNU General Public License 25 ;; along with this program. If not, see <https://www.gnu.org/licenses/>. 26 ;; 27 28 ;;; Commentary: 29 ;; 30 ;; This package offers a fancy and fast mode-line inspired by minimalism design. 31 ;; 32 ;; It's integrated into Doom Emacs (https://github.com/hlissner/doom-emacs) and 33 ;; Centaur Emacs (https://github.com/seagle0128/.emacs.d). 34 ;; 35 ;; The doom-modeline offers: 36 ;; - A match count panel (for anzu, iedit, multiple-cursors, symbol-overlay, 37 ;; evil-search and evil-substitute) 38 ;; - An indicator for recording a macro 39 ;; - Current environment version (e.g. python, ruby, go, etc.) in the major-mode 40 ;; - A customizable mode-line height (see doom-modeline-height) 41 ;; - A minor modes segment which is compatible with minions 42 ;; - An error/warning count segment for flymake/flycheck 43 ;; - A workspace number segment for eyebrowse 44 ;; - A perspective name segment for persp-mode 45 ;; - A window number segment for winum and window-numbering 46 ;; - An indicator for modal editing state, including evil, overwrite, god, ryo 47 ;; and xah-fly-keys, etc. 48 ;; - An indicator for battery status 49 ;; - An indicator for current input method 50 ;; - An indicator for debug state 51 ;; - An indicator for remote host 52 ;; - An indicator for LSP state with lsp-mode or eglot 53 ;; - An indicator for github notifications 54 ;; - An indicator for unread emails with mu4e-alert 55 ;; - An indicator for unread emails with gnus (basically builtin) 56 ;; - An indicator for irc notifications with circe, rcirc or erc. 57 ;; - An indicator for buffer position which is compatible with nyan-mode or poke-line 58 ;; - An indicator for party parrot 59 ;; - An indicator for PDF page number with pdf-tools 60 ;; - An indicator for markdown/org previews with grip 61 ;; - Truncated file name, file icon, buffer state and project name in buffer 62 ;; information segment, which is compatible with project, find-file-in-project 63 ;; and projectile 64 ;; - New mode-line for Info-mode buffers 65 ;; - New package mode-line for paradox 66 ;; - New mode-line for helm buffers 67 ;; - New mode-line for git-timemachine buffers 68 ;; 69 ;; Installation: 70 ;; From melpa, `M-x package-install RET doom-modeline RET`. 71 ;; In `init.el`, 72 ;; (require 'doom-modeline) 73 ;; (doom-modeline-mode 1) 74 ;; or 75 ;; (use-package doom-modeline 76 ;; :ensure t 77 ;; :hook (after-init . doom-modeline-mode)) 78 ;; 79 80 ;;; Code: 81 82 (require 'doom-modeline-core) 83 (require 'doom-modeline-segments) 84 85 86 ;; 87 ;; Mode lines 88 ;; 89 90 (doom-modeline-def-modeline 'main 91 '(eldoc bar workspace-name window-number modals matches follow buffer-info remote-host buffer-position word-count parrot selection-info) 92 '(compilation objed-state misc-info persp-name battery grip irc mu4e gnus github debug repl lsp minor-modes input-method indent-info buffer-encoding major-mode process vcs check time)) 93 94 (doom-modeline-def-modeline 'minimal 95 '(bar window-number modals matches buffer-info-simple) 96 '(media-info major-mode time)) 97 98 (doom-modeline-def-modeline 'special 99 '(eldoc bar window-number modals matches buffer-info remote-host buffer-position word-count parrot selection-info) 100 '(compilation objed-state misc-info battery irc-buffers debug minor-modes input-method indent-info buffer-encoding major-mode process time)) 101 102 (doom-modeline-def-modeline 'project 103 '(bar window-number modals buffer-default-directory remote-host buffer-position) 104 '(compilation misc-info battery irc mu4e gnus github debug minor-modes input-method major-mode process time)) 105 106 (doom-modeline-def-modeline 'dashboard 107 '(bar window-number modals buffer-default-directory-simple remote-host) 108 '(compilation misc-info battery irc mu4e gnus github debug minor-modes input-method major-mode process time)) 109 110 (doom-modeline-def-modeline 'vcs 111 '(bar window-number modals matches buffer-info remote-host buffer-position parrot selection-info) 112 '(compilation misc-info battery irc mu4e gnus github debug minor-modes buffer-encoding major-mode process time)) 113 114 (doom-modeline-def-modeline 'package 115 '(bar window-number modals package) 116 '(compilation misc-info major-mode process time)) 117 118 (doom-modeline-def-modeline 'info 119 '(bar window-number modals buffer-info info-nodes buffer-position parrot selection-info) 120 '(compilation misc-info buffer-encoding major-mode time)) 121 122 (doom-modeline-def-modeline 'media 123 '(bar window-number modals buffer-size buffer-info) 124 '(compilation misc-info media-info major-mode process vcs time)) 125 126 (doom-modeline-def-modeline 'message 127 '(eldoc bar window-number modals matches buffer-info-simple buffer-position word-count parrot selection-info) 128 '(compilation objed-state misc-info battery debug minor-modes input-method indent-info buffer-encoding major-mode time)) 129 130 (doom-modeline-def-modeline 'pdf 131 '(bar window-number modals matches buffer-info pdf-pages) 132 '(compilation misc-info major-mode process vcs time)) 133 134 (doom-modeline-def-modeline 'org-src 135 '(eldoc bar window-number modals matches buffer-info buffer-position word-count parrot selection-info) 136 '(compilation objed-state misc-info debug lsp minor-modes input-method indent-info buffer-encoding major-mode process check time)) 137 138 (doom-modeline-def-modeline 'helm 139 '(bar helm-buffer-id helm-number helm-follow helm-prefix-argument) 140 '(helm-help time)) 141 142 (doom-modeline-def-modeline 'timemachine 143 '(eldoc bar window-number modals matches git-timemachine buffer-position word-count parrot selection-info) 144 '(misc-info minor-modes indent-info buffer-encoding major-mode time)) 145 146 (doom-modeline-def-modeline 'calculator 147 '(window-number modals matches calc buffer-position) 148 '(misc-info minor-modes major-mode process)) 149 150 151 ;; 152 ;; Interfaces 153 ;; 154 155 ;;;###autoload 156 (defun doom-modeline-set-main-modeline (&optional default) 157 "Set main mode-line. 158 If DEFAULT is non-nil, set the default mode-line for all buffers." 159 (doom-modeline-set-modeline 'main default)) 160 161 162 ;; 163 ;; Minor mode 164 ;; 165 166 ;; Suppress warnings 167 (defvar 2C-mode-line-format) 168 (defvar flymake-mode-line-format) 169 (defvar helm-ag-show-status-function) 170 (declare-function helm-display-mode-line "ext:helm-core") 171 172 (defvar doom-modeline-mode-map (make-sparse-keymap)) 173 174 (defvar doom-modeline-mode-alist 175 '((message-mode . message) 176 (git-commit-mode . message) 177 (magit-mode . vcs) 178 (dashboard-mode . dashboard) 179 (Info-mode . info) 180 (image-mode . media) 181 (pdf-view-mode . pdf) 182 (org-src-mode . org-src) 183 (paradox-menu-mode . package) 184 (xwidget-webkit-mode . minimal) 185 (git-timemachine-mode . timemachine) 186 (calc-mode . calculator) 187 (calc-trail-mode . calculator) 188 (circe-mode . special) 189 (erc-mode . special) 190 (rcirc-mode . special)) 191 "Alist of major modes and mode-lines.") 192 193 (defun doom-modeline-auto-set-modeline () 194 "Set mode-line base on major-mode." 195 (catch 'found 196 (dolist (x doom-modeline-mode-alist) 197 (when (derived-mode-p (car x)) 198 (doom-modeline-set-modeline (cdr x)) 199 (throw 'found x))))) 200 201 (defun doom-modeline-set-helm-modeline (&rest _) ; To advice helm 202 "Set helm mode-line." 203 (doom-modeline-set-modeline 'helm)) 204 205 ;;;###autoload 206 (define-minor-mode doom-modeline-mode 207 "Toggle `doom-modeline' on or off." 208 :group 'doom-modeline 209 :global t 210 :lighter nil 211 :keymap doom-modeline-mode-map 212 (if doom-modeline-mode 213 (progn 214 (doom-modeline-refresh-bars) ; Create bars 215 (doom-modeline-set-main-modeline t) ; Set default mode-line 216 217 ;; Apply to all existing buffers. 218 (dolist (buf (buffer-list)) 219 (with-current-buffer buf 220 (unless (doom-modeline-auto-set-modeline) 221 (doom-modeline-set-main-modeline)))) 222 223 ;; For flymake 224 (setq flymake-mode-line-format nil) ; remove the lighter of minor mode 225 226 ;; For Eldoc 227 (setq eldoc-message-function #'doom-modeline-eldoc-minibuffer-message) 228 229 ;; For two-column editing 230 (setq 2C-mode-line-format (doom-modeline 'special)) 231 232 ;; Automatically set mode-lines 233 (add-hook 'after-change-major-mode-hook #'doom-modeline-auto-set-modeline) 234 235 ;; Special handles 236 (advice-add #'helm-display-mode-line :after #'doom-modeline-set-helm-modeline) 237 (setq helm-ag-show-status-function #'doom-modeline-set-helm-modeline)) 238 (progn 239 ;; Restore mode-line 240 (let ((original-format (doom-modeline--original-value 'mode-line-format))) 241 (setq-default mode-line-format original-format) 242 (dolist (buf (buffer-list)) 243 (with-current-buffer buf 244 (setq mode-line-format original-format)))) 245 246 ;; For flymake 247 (setq flymake-mode-line-format (doom-modeline--original-value 'flymake-mode-line-format)) 248 249 ;; For Eldoc 250 (setq eldoc-message-function #'eldoc-minibuffer-message) 251 252 ;; For two-column editing 253 (setq 2C-mode-line-format (doom-modeline--original-value '2C-mode-line-format)) 254 255 ;; Cleanup 256 (remove-hook 'after-change-major-mode-hook #'doom-modeline-auto-set-modeline) 257 (advice-remove #'helm-display-mode-line #'doom-modeline-set-helm-modeline) 258 (setq helm-ag-show-status-function (default-value 'helm-ag-show-status-function))))) 259 260 (provide 'doom-modeline) 261 262 ;;; doom-modeline.el ends here