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