2019-01-17 23:42:33 +08:00
|
|
|
;;; doom-modeline-segments.el --- The segments for doom-modeline -*- lexical-binding: t; -*-
|
|
|
|
|
|
|
|
;; Copyright (C) 2018-2019 Vincent Zhang
|
|
|
|
|
|
|
|
;; This file is not part of GNU Emacs.
|
|
|
|
|
|
|
|
;;
|
|
|
|
;; This program is free software; you can redistribute it and/or
|
|
|
|
;; modify it under the terms of the GNU General Public License as
|
|
|
|
;; published by the Free Software Foundation; either version 2, or
|
|
|
|
;; (at your option) any later version.
|
|
|
|
;;
|
|
|
|
;; This program is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
;; General Public License for more details.
|
|
|
|
;;
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
|
|
;; along with this program; see the file COPYING. If not, write to
|
|
|
|
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
|
|
|
|
;; Floor, Boston, MA 02110-1301, USA.
|
|
|
|
;;
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
;;
|
|
|
|
;; The segments for doom-modeline.
|
|
|
|
;; Use `doom-modeline-def-segment' to create a new segment.
|
|
|
|
;;
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
2019-03-17 22:21:50 +07:00
|
|
|
(require 'all-the-icons)
|
2019-01-17 23:42:33 +08:00
|
|
|
(require 'subr-x)
|
|
|
|
(require 'doom-modeline-core)
|
|
|
|
(require 'doom-modeline-env)
|
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
;; Externals
|
|
|
|
;;
|
|
|
|
|
2019-05-10 01:53:14 +08:00
|
|
|
(defvar Info-current-file)
|
|
|
|
(defvar Info-current-node)
|
|
|
|
(defvar Info-mode-line-node-keymap)
|
2019-03-01 16:33:02 +07:00
|
|
|
(defvar anzu--cached-count)
|
2019-01-17 23:42:33 +08:00
|
|
|
(defvar anzu--current-position)
|
|
|
|
(defvar anzu--overflow-p)
|
|
|
|
(defvar anzu--state)
|
2019-03-01 18:20:25 +07:00
|
|
|
(defvar anzu--total-matched)
|
2019-01-17 23:42:33 +08:00
|
|
|
(defvar anzu-cons-mode-line-p)
|
|
|
|
(defvar aw-keys)
|
2019-02-28 23:58:47 +07:00
|
|
|
(defvar battery-echo-area-format)
|
2019-10-25 01:09:30 +08:00
|
|
|
(defvar battery-load-critical)
|
2019-10-25 01:58:28 +08:00
|
|
|
(defvar battery-mode-line-limit)
|
2019-10-25 01:09:30 +08:00
|
|
|
(defvar battery-status-function)
|
2019-03-16 02:43:21 +07:00
|
|
|
(defvar edebug-execution-mode)
|
2019-11-11 13:34:33 +08:00
|
|
|
(defvar eglot--managed-mode)
|
2019-01-17 23:42:33 +08:00
|
|
|
(defvar evil-ex-active-highlights-alist)
|
|
|
|
(defvar evil-ex-argument)
|
|
|
|
(defvar evil-ex-range)
|
2019-03-07 14:11:00 +07:00
|
|
|
(defvar evil-mc-frozen)
|
2019-01-17 23:42:33 +08:00
|
|
|
(defvar evil-state)
|
|
|
|
(defvar evil-visual-beginning)
|
|
|
|
(defvar evil-visual-end)
|
|
|
|
(defvar evil-visual-selection)
|
|
|
|
(defvar flycheck-current-errors)
|
|
|
|
(defvar flycheck-mode-menu-map)
|
|
|
|
(defvar flymake--backend-state)
|
|
|
|
(defvar flymake--mode-line-format)
|
|
|
|
(defvar flymake-menu)
|
2019-08-16 20:05:39 +08:00
|
|
|
(defvar grip-port)
|
2019-08-18 22:08:46 +08:00
|
|
|
(defvar grip-process)
|
2019-05-10 03:17:15 +08:00
|
|
|
(defvar helm--mode-line-display-prefarg)
|
2019-01-17 23:42:33 +08:00
|
|
|
(defvar iedit-occurrences-overlays)
|
|
|
|
(defvar mc/mode-line)
|
|
|
|
(defvar minions-mode-line-lighter)
|
2019-03-01 16:17:02 +07:00
|
|
|
(defvar mu4e-alert-mode-line)
|
|
|
|
(defvar mu4e-alert-modeline-formatter)
|
2019-01-24 15:26:51 +08:00
|
|
|
(defvar nyan-minimum-window-width)
|
2019-04-22 23:36:57 +10:00
|
|
|
(defvar objed--obj-state)
|
2019-04-29 11:19:49 +08:00
|
|
|
(defvar objed--object)
|
|
|
|
(defvar objed-modeline-setup-func)
|
2019-01-18 18:09:34 +08:00
|
|
|
(defvar persp-nil-name)
|
2019-01-17 23:42:33 +08:00
|
|
|
(defvar symbol-overlay-keywords-alist)
|
|
|
|
(defvar symbol-overlay-temp-symbol)
|
|
|
|
(defvar text-scale-mode-amount)
|
2019-03-01 16:17:02 +07:00
|
|
|
(defvar tracking-buffers)
|
2019-01-17 23:42:33 +08:00
|
|
|
(defvar winum-auto-setup-mode-line)
|
|
|
|
(defvar xah-fly-insert-state-q)
|
|
|
|
|
|
|
|
(declare-function anzu--reset-status 'anzu)
|
|
|
|
(declare-function anzu--where-is-here 'anzu)
|
|
|
|
(declare-function async-inject-variables 'async)
|
2019-10-13 20:48:14 +08:00
|
|
|
(declare-function async-start 'async)
|
2019-01-17 23:42:33 +08:00
|
|
|
(declare-function avy-traverse 'avy)
|
|
|
|
(declare-function avy-tree 'avy)
|
|
|
|
(declare-function aw-update 'ace-window)
|
|
|
|
(declare-function aw-window-list 'ace-window)
|
2019-02-28 23:58:47 +07:00
|
|
|
(declare-function battery-format 'battery)
|
2019-10-25 04:35:49 +08:00
|
|
|
(declare-function battery-update 'battery)
|
2019-03-16 23:43:22 +07:00
|
|
|
(declare-function dap--cur-session 'dap-mode)
|
2019-07-13 01:52:22 +08:00
|
|
|
(declare-function dap--session-running 'dap-mode)
|
2019-03-16 23:43:22 +07:00
|
|
|
(declare-function dap-debug-recent 'dap-mode)
|
2019-03-17 00:00:32 +07:00
|
|
|
(declare-function dap-disconnect 'dap-mode)
|
2019-03-16 23:43:22 +07:00
|
|
|
(declare-function dap-hydra 'dap-hydra)
|
|
|
|
(declare-function dap-mode-line 'dap-mode)
|
2019-03-16 02:43:21 +07:00
|
|
|
(declare-function edebug-help 'edebug)
|
|
|
|
(declare-function edebug-next-mode 'edebug)
|
|
|
|
(declare-function edebug-stop 'edebug)
|
2019-03-12 00:59:28 +07:00
|
|
|
(declare-function eglot--current-server 'eglot)
|
2019-03-12 00:01:47 +07:00
|
|
|
(declare-function eglot--major-mode 'eglot)
|
|
|
|
(declare-function eglot--project-nickname 'eglot)
|
|
|
|
(declare-function eglot--spinner 'eglot)
|
|
|
|
(declare-function eglot-clear-status 'eglot)
|
|
|
|
(declare-function eglot-events-buffer 'eglot)
|
|
|
|
(declare-function eglot-forget-pending-continuations 'eglot)
|
|
|
|
(declare-function eglot-reconnect 'eglot)
|
|
|
|
(declare-function eglot-shutdown 'eglot)
|
|
|
|
(declare-function eglot-stderr-buffer 'eglot)
|
2019-01-17 23:42:33 +08:00
|
|
|
(declare-function evil-delimited-arguments 'evil-common)
|
|
|
|
(declare-function evil-emacs-state-p 'evil-states)
|
|
|
|
(declare-function evil-force-normal-state 'evil-commands)
|
|
|
|
(declare-function evil-insert-state-p 'evil-states)
|
|
|
|
(declare-function evil-motion-state-p 'evil-states)
|
|
|
|
(declare-function evil-normal-state-p 'evil-states)
|
|
|
|
(declare-function evil-operator-state-p 'evil-states)
|
|
|
|
(declare-function evil-replace-state-p 'evil-states)
|
|
|
|
(declare-function evil-state-property 'evil-common)
|
|
|
|
(declare-function evil-visual-state-p 'evil-states)
|
|
|
|
(declare-function eyebrowse--get 'eyebrowse)
|
2019-04-29 11:19:49 +08:00
|
|
|
(declare-function fancy-narrow-active-p 'fancy-narrow)
|
2019-03-09 02:41:20 +07:00
|
|
|
(declare-function fancy-narrow-to-region 'fancy-narrow)
|
|
|
|
(declare-function fancy-widen 'fancy-narrow)
|
2019-01-17 23:42:33 +08:00
|
|
|
(declare-function flycheck-buffer 'flycheck)
|
|
|
|
(declare-function flycheck-count-errors 'flycheck)
|
|
|
|
(declare-function flycheck-list-errors 'flycheck)
|
|
|
|
(declare-function flycheck-next-error 'flycheck)
|
|
|
|
(declare-function flycheck-previous-error 'flycheck)
|
|
|
|
(declare-function flymake--backend-state-diags 'flymake)
|
|
|
|
(declare-function flymake--diag-type 'flymake)
|
|
|
|
(declare-function flymake--handle-report 'flymake)
|
2019-05-04 13:51:02 +03:00
|
|
|
(declare-function flymake--lookup-type-property 'flymake)
|
2019-01-17 23:42:33 +08:00
|
|
|
(declare-function flymake-disabled-backends 'flymake)
|
|
|
|
(declare-function flymake-goto-next-error 'flymake)
|
|
|
|
(declare-function flymake-goto-prev-error 'flymake)
|
|
|
|
(declare-function flymake-reporting-backends 'flymake)
|
|
|
|
(declare-function flymake-running-backends 'flymake)
|
|
|
|
(declare-function flymake-show-diagnostics-buffer 'flymake)
|
|
|
|
(declare-function flymake-start 'flymake)
|
2019-10-13 20:48:14 +08:00
|
|
|
(declare-function grip-browse-preview 'grip-mode)
|
2019-08-16 20:05:39 +08:00
|
|
|
(declare-function grip-mode 'grip-mode)
|
2019-05-10 03:17:15 +08:00
|
|
|
(declare-function helm-candidate-number-at-point 'helm)
|
|
|
|
(declare-function helm-get-candidate-number 'helm)
|
2019-01-17 23:42:33 +08:00
|
|
|
(declare-function iedit-find-current-occurrence-overlay 'iedit-lib)
|
|
|
|
(declare-function iedit-prev-occurrence 'iedit-lib)
|
|
|
|
(declare-function image-get-display-property 'image-mode)
|
2019-03-12 00:01:47 +07:00
|
|
|
(declare-function jsonrpc--request-continuations 'jsonrpc)
|
|
|
|
(declare-function jsonrpc-last-error 'jsonrpc)
|
2019-02-26 15:20:39 +07:00
|
|
|
(declare-function lsp--workspace-print 'lsp-mode)
|
2019-03-12 00:51:37 +07:00
|
|
|
(declare-function lsp-describe-session 'lsp-mode)
|
2019-05-22 14:11:41 +08:00
|
|
|
(declare-function lsp-workspace-folders-open 'lsp-mode)
|
2019-05-23 16:47:30 +08:00
|
|
|
(declare-function lsp-workspace-restart 'lsp-mode)
|
|
|
|
(declare-function lsp-workspace-shutdown 'lsp-mode)
|
2019-03-01 16:17:02 +07:00
|
|
|
(declare-function lsp-workspaces 'lsp-mode)
|
2019-01-17 23:42:33 +08:00
|
|
|
(declare-function magit-toplevel 'magit-git)
|
2019-03-11 15:38:06 +07:00
|
|
|
(declare-function mc/num-cursors 'multiple-cursors-core)
|
2019-01-17 23:42:33 +08:00
|
|
|
(declare-function minions-minor-modes-menu 'minions)
|
2019-03-01 23:35:37 +07:00
|
|
|
(declare-function mu4e-alert-default-mode-line-formatter 'mu4e-alert)
|
2019-03-01 16:17:02 +07:00
|
|
|
(declare-function mu4e-alert-enable-mode-line-display 'mu4e-alert)
|
2019-01-17 23:42:33 +08:00
|
|
|
(declare-function nyan-create 'nyan-mode)
|
2019-08-12 22:46:30 +08:00
|
|
|
(declare-function org-edit-src-save 'org-src)
|
2019-04-04 01:04:09 +08:00
|
|
|
(declare-function org-narrow-to-block 'org)
|
|
|
|
(declare-function org-narrow-to-element 'org)
|
|
|
|
(declare-function org-narrow-to-subtree 'org)
|
2019-09-18 23:10:11 +08:00
|
|
|
(declare-function org-toggle-narrow-to-subtree 'org)
|
2019-01-17 23:42:33 +08:00
|
|
|
(declare-function parrot-create 'parrot)
|
|
|
|
(declare-function pdf-cache-number-of-pages 'pdf-cache)
|
|
|
|
(declare-function persp-add-buffer 'persp-mode)
|
|
|
|
(declare-function persp-contain-buffer-p 'persp-mode)
|
|
|
|
(declare-function persp-remove-buffer 'persp-mode)
|
|
|
|
(declare-function persp-switch 'persp-mode)
|
2019-03-11 15:38:06 +07:00
|
|
|
(declare-function popup-create 'popup)
|
|
|
|
(declare-function popup-delete 'popup)
|
2019-01-17 23:42:33 +08:00
|
|
|
(declare-function symbol-overlay-assoc 'symbol-overlay)
|
|
|
|
(declare-function symbol-overlay-get-list 'symbol-overlay)
|
|
|
|
(declare-function symbol-overlay-get-symbol 'symbol-overlay)
|
|
|
|
(declare-function symbol-overlay-rename 'symbol-overlay)
|
2019-03-01 16:17:02 +07:00
|
|
|
(declare-function tracking-shorten 'tracking)
|
2019-01-31 15:51:57 -07:00
|
|
|
(declare-function undo-tree-redo-1 'undo-tree)
|
|
|
|
(declare-function undo-tree-undo-1 'undo-tree)
|
2019-04-23 00:11:03 +03:00
|
|
|
(declare-function warning-numeric-level 'warnings)
|
2019-01-17 23:42:33 +08:00
|
|
|
(declare-function window-numbering-clear-mode-line 'window-numbering)
|
|
|
|
(declare-function window-numbering-get-number-string 'window-numbering)
|
|
|
|
(declare-function window-numbering-install-mode-line 'window-numbering)
|
|
|
|
(declare-function winum--clear-mode-line 'winum)
|
|
|
|
(declare-function winum--install-mode-line 'winum)
|
|
|
|
(declare-function winum-get-number-string 'winum)
|
|
|
|
|
2019-05-06 02:06:03 +08:00
|
|
|
|
2019-01-17 23:42:33 +08:00
|
|
|
;;
|
|
|
|
;; 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."
|
2019-07-25 03:47:13 +08:00
|
|
|
(let* ((active (doom-modeline--active))
|
|
|
|
(face (if active 'doom-modeline-buffer-path 'mode-line-inactive)))
|
2019-05-22 15:15:48 +08:00
|
|
|
(concat (doom-modeline-spc)
|
2019-10-23 02:50:04 +08:00
|
|
|
(doom-modeline-icon 'octicon "file-directory" "🖿" "" face
|
|
|
|
:v-adjust -0.05 :height 1.25)
|
|
|
|
(doom-modeline-spc)
|
2019-05-18 23:53:47 +08:00
|
|
|
(propertize (abbreviate-file-name default-directory)
|
2019-07-25 03:47:13 +08:00
|
|
|
'face face))))
|
2019-01-17 23:42:33 +08:00
|
|
|
|
|
|
|
;;
|
|
|
|
(defvar-local doom-modeline--buffer-file-icon nil)
|
|
|
|
(defun doom-modeline-update-buffer-file-icon (&rest _)
|
|
|
|
"Update file icon in mode-line."
|
|
|
|
(setq doom-modeline--buffer-file-icon
|
2019-10-26 00:06:10 +08:00
|
|
|
(when (and doom-modeline-icon doom-modeline-major-mode-icon)
|
2019-04-20 02:39:05 +08:00
|
|
|
(let* ((icon (if (and (buffer-file-name)
|
2019-04-16 20:53:32 +08:00
|
|
|
(all-the-icons-auto-mode-match?))
|
2019-04-20 02:39:05 +08:00
|
|
|
(all-the-icons-icon-for-file (file-name-nondirectory (buffer-file-name)))
|
|
|
|
(all-the-icons-icon-for-mode major-mode))))
|
2019-02-19 04:04:30 +08:00
|
|
|
(if (symbolp icon)
|
2019-04-16 20:53:32 +08:00
|
|
|
(setq icon (doom-modeline-icon-faicon "file-o"
|
|
|
|
:face 'all-the-icons-dsilver
|
2019-04-20 02:39:05 +08:00
|
|
|
:height 0.8
|
|
|
|
:v-adjust 0.0)))
|
2019-01-17 23:42:33 +08:00
|
|
|
(unless (symbolp icon)
|
|
|
|
(propertize icon
|
2019-03-04 16:58:24 +07:00
|
|
|
'help-echo (format "Major-mode: %s" (format-mode-line mode-name))
|
2019-01-17 23:42:33 +08:00
|
|
|
'display '(raise -0.125)))))))
|
|
|
|
(add-hook 'find-file-hook #'doom-modeline-update-buffer-file-icon)
|
|
|
|
(add-hook 'after-change-major-mode-hook #'doom-modeline-update-buffer-file-icon)
|
|
|
|
(add-hook 'clone-indirect-buffer-hook #'doom-modeline-update-buffer-file-icon)
|
|
|
|
|
2019-03-14 15:27:43 +07:00
|
|
|
(when (>= emacs-major-version 26)
|
2019-03-16 17:41:11 +07:00
|
|
|
(add-variable-watcher
|
|
|
|
'doom-modeline-icon
|
|
|
|
(lambda (_sym val op _where)
|
|
|
|
(when (eq op 'set)
|
|
|
|
(setq doom-modeline-icon val)
|
2019-03-17 17:54:01 +07:00
|
|
|
(dolist (buf (buffer-list))
|
|
|
|
(with-current-buffer buf
|
2019-04-20 02:39:05 +08:00
|
|
|
(doom-modeline-update-buffer-file-icon)))))))
|
2019-03-14 15:27:43 +07:00
|
|
|
|
2019-10-23 03:07:51 +08:00
|
|
|
(defun doom-modeline-buffer-file-state-icon (icon unicode text face)
|
|
|
|
"Displays an ICON of buffer state with FACE.
|
2019-01-17 23:42:33 +08:00
|
|
|
TEXT is the alternative if it is not applicable.
|
|
|
|
Uses `all-the-icons-material' to fetch the icon."
|
2019-10-23 02:50:04 +08:00
|
|
|
(when doom-modeline-buffer-state-icon
|
|
|
|
(doom-modeline-icon 'material icon unicode text face
|
2019-10-23 03:07:51 +08:00
|
|
|
:height 1.1
|
|
|
|
:v-adjust -0.225)))
|
2019-01-17 23:42:33 +08:00
|
|
|
|
|
|
|
(defvar-local doom-modeline--buffer-file-state-icon nil)
|
|
|
|
(defun doom-modeline-update-buffer-file-state-icon (&rest _)
|
|
|
|
"Update the buffer or file state in mode-line."
|
|
|
|
(setq doom-modeline--buffer-file-state-icon
|
2019-06-26 23:12:14 +08:00
|
|
|
(ignore-errors
|
|
|
|
(cond (buffer-read-only
|
|
|
|
(doom-modeline-buffer-file-state-icon
|
2019-10-23 02:50:04 +08:00
|
|
|
"lock" "🔒" "%1*" 'doom-modeline-warning))
|
2019-10-29 20:33:26 +08:00
|
|
|
((and buffer-file-name
|
|
|
|
(buffer-modified-p)
|
2019-06-26 23:12:14 +08:00
|
|
|
doom-modeline-buffer-modification-icon)
|
|
|
|
(doom-modeline-buffer-file-state-icon
|
2019-10-23 02:50:04 +08:00
|
|
|
"save" "💾" "%1*" 'doom-modeline-buffer-modified))
|
2019-06-26 23:12:14 +08:00
|
|
|
((and buffer-file-name
|
|
|
|
(not (file-exists-p buffer-file-name)))
|
|
|
|
(doom-modeline-buffer-file-state-icon
|
2019-10-23 02:50:04 +08:00
|
|
|
"do_not_disturb_alt" "🚫" "!" 'doom-modeline-urgent))
|
2019-06-26 23:12:14 +08:00
|
|
|
((or (buffer-narrowed-p)
|
|
|
|
(and (bound-and-true-p fancy-narrow-mode)
|
|
|
|
(fancy-narrow-active-p)))
|
|
|
|
(doom-modeline-buffer-file-state-icon
|
2019-10-23 02:50:04 +08:00
|
|
|
"vertical_align_center" "↕" "><" 'doom-modeline-warning))
|
2019-06-26 23:12:14 +08:00
|
|
|
(t "")))))
|
2019-01-17 23:42:33 +08:00
|
|
|
(add-hook 'find-file-hook #'doom-modeline-update-buffer-file-state-icon)
|
|
|
|
(add-hook 'after-revert-hook #'doom-modeline-update-buffer-file-state-icon)
|
|
|
|
(add-hook 'after-save-hook #'doom-modeline-update-buffer-file-state-icon)
|
|
|
|
(add-hook 'read-only-mode-hook #'doom-modeline-update-buffer-file-state-icon)
|
2019-06-26 22:55:46 +08:00
|
|
|
(add-hook 'after-change-functions #'doom-modeline-update-buffer-file-state-icon)
|
2019-01-17 23:42:33 +08:00
|
|
|
(add-hook 'clone-indirect-buffer-hook #'doom-modeline-update-buffer-file-state-icon)
|
2019-03-07 23:50:04 +07:00
|
|
|
(add-hook 'evil-insert-state-exit-hook #'doom-modeline-update-buffer-file-state-icon)
|
2019-01-17 23:42:33 +08:00
|
|
|
(advice-add #'undo :after #'doom-modeline-update-buffer-file-state-icon)
|
2019-01-31 15:51:57 -07:00
|
|
|
(advice-add #'undo-tree-undo-1 :after #'doom-modeline-update-buffer-file-state-icon)
|
|
|
|
(advice-add #'undo-tree-redo-1 :after #'doom-modeline-update-buffer-file-state-icon)
|
2019-10-03 04:39:06 +08:00
|
|
|
(advice-add #'fill-paragraph :after #'doom-modeline-update-buffer-file-state-icon)
|
2019-08-29 19:16:06 +08:00
|
|
|
(advice-add #'not-modified :after #'doom-modeline-update-buffer-file-state-icon)
|
2019-09-05 04:07:29 +08:00
|
|
|
(advice-add #'narrow-to-region :after #'doom-modeline-update-buffer-file-state-icon)
|
2019-01-17 23:42:33 +08:00
|
|
|
(advice-add #'widen :after #'doom-modeline-update-buffer-file-state-icon)
|
2019-03-09 02:41:20 +07:00
|
|
|
(advice-add #'fancy-narrow-to-region :after #'doom-modeline-update-buffer-file-state-icon)
|
|
|
|
(advice-add #'fancy-widen :after #'doom-modeline-update-buffer-file-state-icon)
|
2019-04-02 00:23:08 +08:00
|
|
|
(advice-add #'org-narrow-to-block :after #'doom-modeline-update-buffer-file-state-icon)
|
|
|
|
(advice-add #'org-narrow-to-element :after #'doom-modeline-update-buffer-file-state-icon)
|
2019-04-04 01:04:09 +08:00
|
|
|
(advice-add #'org-narrow-to-subtree :after #'doom-modeline-update-buffer-file-state-icon)
|
2019-09-18 17:38:06 +08:00
|
|
|
(advice-add #'org-toggle-narrow-to-subtree :after #'doom-modeline-update-buffer-file-state-icon)
|
2019-08-08 23:12:40 +08:00
|
|
|
(advice-add #'org-edit-src-save :after #'doom-modeline-update-buffer-file-state-icon)
|
2019-09-02 17:09:41 +08:00
|
|
|
(advice-add #'symbol-overlay-rename :after #'doom-modeline-update-buffer-file-state-icon)
|
2019-01-17 23:42:33 +08:00
|
|
|
|
|
|
|
(when (>= emacs-major-version 26)
|
|
|
|
(add-variable-watcher
|
|
|
|
'buffer-read-only
|
2019-03-28 16:25:35 +08:00
|
|
|
(lambda (_sym val _op _where)
|
|
|
|
(setq buffer-read-only val)
|
|
|
|
(doom-modeline-update-buffer-file-state-icon)))
|
2019-03-14 15:27:43 +07:00
|
|
|
|
|
|
|
(add-variable-watcher
|
|
|
|
'doom-modeline-icon
|
|
|
|
(lambda (_sym val op _where)
|
|
|
|
(when (eq op 'set)
|
|
|
|
(setq doom-modeline-icon val)
|
2019-03-17 17:54:01 +07:00
|
|
|
(dolist (buf (buffer-list))
|
|
|
|
(with-current-buffer buf
|
2019-04-20 02:39:05 +08:00
|
|
|
(doom-modeline-update-buffer-file-state-icon)))))))
|
2019-01-17 23:42:33 +08:00
|
|
|
|
|
|
|
(defvar-local doom-modeline--buffer-file-name nil)
|
|
|
|
(defun doom-modeline-update-buffer-file-name (&rest _)
|
|
|
|
"Update buffer file name in mode-line."
|
|
|
|
(setq doom-modeline--buffer-file-name
|
2019-06-26 23:12:14 +08:00
|
|
|
(ignore-errors
|
|
|
|
(save-match-data
|
|
|
|
(if buffer-file-name
|
|
|
|
(doom-modeline-buffer-file-name)
|
|
|
|
(propertize "%b"
|
2019-10-29 21:01:45 +08:00
|
|
|
'face 'doom-modeline-buffer-file
|
2019-11-07 17:44:47 +08:00
|
|
|
'mouse-face 'mode-line-highlight
|
2019-06-26 23:12:14 +08:00
|
|
|
'help-echo "Buffer name
|
2019-01-17 23:42:33 +08:00
|
|
|
mouse-1: Previous buffer\nmouse-3: Next buffer"
|
2019-06-26 23:12:14 +08:00
|
|
|
'local-map mode-line-buffer-identification-keymap))))))
|
2019-01-17 23:42:33 +08:00
|
|
|
(add-hook 'find-file-hook #'doom-modeline-update-buffer-file-name)
|
|
|
|
(add-hook 'after-revert-hook #'doom-modeline-update-buffer-file-name)
|
|
|
|
(add-hook 'after-save-hook #'doom-modeline-update-buffer-file-name)
|
|
|
|
(add-hook 'clone-indirect-buffer-hook #'doom-modeline-update-buffer-file-name)
|
2019-03-05 00:01:40 +07:00
|
|
|
(add-hook 'evil-insert-state-exit-hook #'doom-modeline-update-buffer-file-name)
|
2019-08-29 19:16:06 +08:00
|
|
|
(advice-add #'not-modified :after #'doom-modeline-update-buffer-file-name)
|
2019-01-17 23:42:33 +08:00
|
|
|
(advice-add #'rename-buffer :after #'doom-modeline-update-buffer-file-name)
|
|
|
|
(advice-add #'set-visited-file-name :after #'doom-modeline-update-buffer-file-name)
|
2019-05-21 21:21:02 +08:00
|
|
|
(advice-add #'pop-to-buffer :after #'doom-modeline-update-buffer-file-name)
|
2019-01-17 23:42:33 +08:00
|
|
|
(advice-add #'undo :after #'doom-modeline-update-buffer-file-name)
|
2019-01-31 15:51:57 -07:00
|
|
|
(advice-add #'undo-tree-undo-1 :after #'doom-modeline-update-buffer-file-name)
|
|
|
|
(advice-add #'undo-tree-redo-1 :after #'doom-modeline-update-buffer-file-name)
|
2019-10-03 04:39:06 +08:00
|
|
|
(advice-add #'fill-paragraph :after #'doom-modeline-update-buffer-file-name)
|
2019-03-11 00:22:13 +07:00
|
|
|
(advice-add #'popup-create :after #'doom-modeline-update-buffer-file-name)
|
|
|
|
(advice-add #'popup-delete :after #'doom-modeline-update-buffer-file-name)
|
2019-08-08 23:12:40 +08:00
|
|
|
(advice-add #'org-edit-src-save :after #'doom-modeline-update-buffer-file-name)
|
2019-09-02 17:09:41 +08:00
|
|
|
(advice-add #'symbol-overlay-rename :after #'doom-modeline-update-buffer-file-name)
|
2019-03-16 01:20:31 +07:00
|
|
|
|
|
|
|
(with-no-warnings
|
|
|
|
(if (boundp 'after-focus-change-function)
|
2019-06-27 17:41:29 +08:00
|
|
|
(add-function
|
|
|
|
:after after-focus-change-function
|
|
|
|
(lambda ()
|
|
|
|
(when (frame-focus-state)
|
|
|
|
(doom-modeline-update-buffer-file-name))))
|
2019-03-16 01:20:31 +07:00
|
|
|
(add-hook 'focus-in-hook #'doom-modeline-update-buffer-file-name t)))
|
2019-03-04 23:38:33 +07:00
|
|
|
|
2019-01-23 03:04:26 +08:00
|
|
|
(when (>= emacs-major-version 26)
|
|
|
|
(add-variable-watcher
|
|
|
|
'doom-modeline-buffer-file-name-style
|
|
|
|
(lambda (_sym val op _where)
|
|
|
|
(when (eq op 'set)
|
|
|
|
(setq doom-modeline-buffer-file-name-style val)
|
|
|
|
(dolist (buf (buffer-list))
|
|
|
|
(with-current-buffer buf
|
|
|
|
(if buffer-file-name
|
|
|
|
(doom-modeline-update-buffer-file-name))))))))
|
|
|
|
|
2019-09-02 17:09:41 +08:00
|
|
|
;; Optimize: just update the face of the buffer name in `after-change-functions', since
|
2019-09-02 17:18:51 +08:00
|
|
|
;; `doom-modeline--buffer-file-name' may consume lots of CPU if it's called too frequently.
|
2019-09-02 17:09:41 +08:00
|
|
|
(defun doom-modeline-update-buffer-file-name-face (&rest _)
|
|
|
|
"Update the face of buffer file name in mode-line."
|
2019-09-05 03:30:43 +08:00
|
|
|
(when (and buffer-file-name
|
|
|
|
doom-modeline--buffer-file-name
|
|
|
|
(buffer-modified-p))
|
2019-09-02 17:09:41 +08:00
|
|
|
(setq doom-modeline--buffer-file-name
|
|
|
|
(propertize doom-modeline--buffer-file-name 'face 'doom-modeline-buffer-modified))))
|
|
|
|
(add-hook 'after-change-functions #'doom-modeline-update-buffer-file-name-face)
|
|
|
|
|
2019-05-19 23:04:03 +08:00
|
|
|
(defsubst doom-modeline--buffer-mode-icon ()
|
|
|
|
"The icon of the current major mode."
|
2019-10-26 00:06:10 +08:00
|
|
|
(when (and doom-modeline-icon doom-modeline-major-mode-icon)
|
2019-05-19 23:04:03 +08:00
|
|
|
(when-let ((icon (or doom-modeline--buffer-file-icon
|
|
|
|
(doom-modeline-update-buffer-file-icon))))
|
|
|
|
(when icon
|
|
|
|
(concat
|
|
|
|
(if (doom-modeline--active)
|
2019-10-26 00:06:10 +08:00
|
|
|
(if doom-modeline-major-mode-color-icon
|
2019-10-25 05:54:42 +08:00
|
|
|
icon
|
|
|
|
(propertize icon 'face `(:inherit ,(let ((props (get-text-property 0 'face icon)))
|
|
|
|
props (remove :inherit props))
|
|
|
|
:inherit mode-line)))
|
2019-06-27 17:41:29 +08:00
|
|
|
(propertize icon 'face `(:inherit ,(get-text-property 0 'face icon)
|
|
|
|
:inherit mode-line-inactive)))
|
2019-05-19 23:04:03 +08:00
|
|
|
(doom-modeline-vspc))))))
|
|
|
|
|
|
|
|
(defsubst doom-modeline--buffer-state-icon ()
|
|
|
|
"The icon of the current buffer state."
|
|
|
|
(when-let ((icon (or doom-modeline--buffer-file-state-icon
|
|
|
|
(doom-modeline-update-buffer-file-state-icon))))
|
|
|
|
(when icon
|
|
|
|
(concat
|
|
|
|
(if (doom-modeline--active)
|
|
|
|
icon
|
2019-06-27 17:41:29 +08:00
|
|
|
(propertize icon 'face `(:inherit ,(get-text-property 0 'face icon)
|
|
|
|
:inherit mode-line-inactive)))
|
2019-05-19 23:04:03 +08:00
|
|
|
(doom-modeline-vspc)))))
|
|
|
|
|
|
|
|
(defsubst doom-modeline--buffer-name ()
|
|
|
|
"The current buffer name."
|
|
|
|
(when-let ((name (or doom-modeline--buffer-file-name
|
|
|
|
(doom-modeline-update-buffer-file-name))))
|
|
|
|
(if (doom-modeline--active)
|
|
|
|
name
|
|
|
|
(propertize name 'face 'mode-line-inactive))))
|
|
|
|
|
2019-01-17 23:42:33 +08:00
|
|
|
(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)."
|
2019-05-19 23:04:03 +08:00
|
|
|
(concat
|
2019-05-22 15:15:48 +08:00
|
|
|
(doom-modeline-spc)
|
2019-05-19 23:04:03 +08:00
|
|
|
(doom-modeline--buffer-mode-icon)
|
|
|
|
(doom-modeline--buffer-state-icon)
|
|
|
|
(doom-modeline--buffer-name)))
|
2019-01-17 23:42:33 +08:00
|
|
|
|
|
|
|
(doom-modeline-def-segment buffer-info-simple
|
|
|
|
"Display only the current buffer's name, but with fontification."
|
|
|
|
(propertize
|
|
|
|
" %b "
|
|
|
|
'face (cond ((and buffer-file-name (buffer-modified-p))
|
|
|
|
'doom-modeline-buffer-modified)
|
2019-02-12 02:44:31 +08:00
|
|
|
((doom-modeline--active) 'doom-modeline-buffer-file)
|
|
|
|
(t 'mode-line-inactive))))
|
2019-01-17 23:42:33 +08:00
|
|
|
|
2019-05-14 01:59:51 +08:00
|
|
|
|
|
|
|
;;
|
|
|
|
;; encoding
|
2019-01-17 23:42:33 +08:00
|
|
|
;;
|
2019-05-14 01:59:51 +08:00
|
|
|
|
2019-01-17 23:42:33 +08:00
|
|
|
(doom-modeline-def-segment buffer-encoding
|
2019-10-30 01:31:28 +08:00
|
|
|
"Displays the eol and the encoding style of the buffer the same way Atom does."
|
2019-05-14 02:11:40 +08:00
|
|
|
(when doom-modeline-buffer-encoding
|
2019-10-27 03:31:15 +08:00
|
|
|
(let ((face (if (doom-modeline--active) 'mode-line 'mode-line-inactive))
|
2019-11-07 17:44:47 +08:00
|
|
|
(mouse-face 'mode-line-highlight))
|
2019-10-27 03:31:15 +08:00
|
|
|
(concat
|
2019-11-07 17:44:47 +08:00
|
|
|
(doom-modeline-spc)
|
|
|
|
|
2019-10-27 03:31:15 +08:00
|
|
|
;; eol type
|
|
|
|
(let ((eol (coding-system-eol-type buffer-file-coding-system)))
|
|
|
|
(propertize
|
|
|
|
(pcase eol
|
2019-11-07 17:44:47 +08:00
|
|
|
(0 "LF")
|
|
|
|
(1 "CRLF")
|
|
|
|
(2 "CR")
|
2019-10-27 16:21:47 +08:00
|
|
|
(_ ""))
|
2019-10-27 03:31:15 +08:00
|
|
|
'face face
|
|
|
|
'mouse-face mouse-face
|
|
|
|
'help-echo (format "End-of-line style: %s\nmouse-1: Cycle"
|
|
|
|
(pcase eol
|
|
|
|
(0 "Unix-style LF")
|
|
|
|
(1 "DOS-style CRLF")
|
|
|
|
(2 "Mac-style CR")
|
|
|
|
(_ "Undecided")))
|
|
|
|
'local-map (let ((map (make-sparse-keymap)))
|
|
|
|
(define-key map [mode-line mouse-1] 'mode-line-change-eol)
|
|
|
|
map)))
|
2019-11-07 17:44:47 +08:00
|
|
|
|
|
|
|
(doom-modeline-spc)
|
|
|
|
|
2019-10-30 01:31:28 +08:00
|
|
|
;; coding system
|
2019-10-27 03:31:15 +08:00
|
|
|
(propertize
|
2019-11-07 17:44:47 +08:00
|
|
|
(let ((sys (coding-system-plist buffer-file-coding-system)))
|
|
|
|
(cond ((memq (plist-get sys :category)
|
|
|
|
'(coding-category-undecided coding-category-utf-8))
|
|
|
|
"UTF-8")
|
|
|
|
(t (upcase (symbol-name (plist-get sys :name))))))
|
2019-10-27 03:31:15 +08:00
|
|
|
'face face
|
|
|
|
'mouse-face mouse-face
|
|
|
|
'help-echo 'mode-line-mule-info-help-echo
|
2019-11-07 17:44:47 +08:00
|
|
|
'local-map mode-line-coding-system-map)
|
|
|
|
|
|
|
|
(doom-modeline-spc)))))
|
2019-01-17 23:42:33 +08:00
|
|
|
|
|
|
|
|
2019-05-14 01:59:51 +08:00
|
|
|
;;
|
|
|
|
;; indentation
|
|
|
|
;;
|
|
|
|
|
|
|
|
(doom-modeline-def-segment indent-info
|
|
|
|
"Displays the indentation information."
|
2019-05-14 02:11:40 +08:00
|
|
|
(when doom-modeline-indent-info
|
|
|
|
(propertize (format " %s %d "
|
|
|
|
(if indent-tabs-mode "TAB" "SPC") tab-width)
|
|
|
|
'face (if (doom-modeline--active) 'mode-line 'mode-line-inactive))))
|
2019-05-14 01:59:51 +08:00
|
|
|
|
2019-01-17 23:42:33 +08:00
|
|
|
;;
|
|
|
|
;; remote host
|
|
|
|
;;
|
|
|
|
|
|
|
|
(doom-modeline-def-segment remote-host
|
|
|
|
"Hostname for remote buffers."
|
|
|
|
(when default-directory
|
|
|
|
(when-let ((host (file-remote-p default-directory 'host)))
|
2019-02-12 02:44:31 +08:00
|
|
|
(propertize
|
|
|
|
(concat "@" host)
|
|
|
|
'face (if (doom-modeline--active) 'mode-line 'mode-line-inactive)))))
|
2019-01-17 23:42:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
;; major-mode
|
|
|
|
;;
|
|
|
|
|
|
|
|
(doom-modeline-def-segment major-mode
|
|
|
|
"The major mode, including environment and text-scale info."
|
|
|
|
(propertize
|
2019-05-18 23:53:47 +08:00
|
|
|
(concat
|
2019-05-22 15:15:48 +08:00
|
|
|
(doom-modeline-spc)
|
2019-08-03 14:38:10 +08:00
|
|
|
(propertize (format-mode-line
|
|
|
|
(or (and (boundp 'delighted-modes)
|
|
|
|
(cadr (assq major-mode delighted-modes)))
|
|
|
|
mode-name))
|
|
|
|
'help-echo "Major mode\n\
|
2019-01-17 23:42:33 +08:00
|
|
|
mouse-1: Display major mode menu\n\
|
|
|
|
mouse-2: Show help for major mode\n\
|
|
|
|
mouse-3: Toggle minor modes"
|
2019-08-03 14:38:10 +08:00
|
|
|
'mouse-face 'mode-line-highlight
|
|
|
|
'local-map mode-line-major-mode-keymap)
|
2019-05-18 23:53:47 +08:00
|
|
|
(when (and doom-modeline-env-version doom-modeline-env--version)
|
|
|
|
(format " %s" doom-modeline-env--version))
|
|
|
|
(and (boundp 'text-scale-mode-amount)
|
|
|
|
(/= text-scale-mode-amount 0)
|
|
|
|
(format
|
|
|
|
(if (> text-scale-mode-amount 0)
|
|
|
|
" (%+d)"
|
|
|
|
" (%-d)")
|
|
|
|
text-scale-mode-amount))
|
2019-05-22 15:15:48 +08:00
|
|
|
(doom-modeline-spc))
|
2019-02-12 02:44:31 +08:00
|
|
|
'face (if (doom-modeline--active)
|
|
|
|
'doom-modeline-buffer-major-mode
|
|
|
|
'mode-line-inactive)))
|
2019-01-17 23:42:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
;; process
|
|
|
|
;;
|
|
|
|
|
|
|
|
(doom-modeline-def-segment process
|
|
|
|
"The process info."
|
2019-02-12 02:44:31 +08:00
|
|
|
(if (doom-modeline--active)
|
|
|
|
mode-line-process
|
2019-02-12 03:57:22 +08:00
|
|
|
(propertize
|
2019-05-29 13:35:55 +08:00
|
|
|
(format-mode-line mode-line-process)
|
2019-02-12 03:57:22 +08:00
|
|
|
'face 'mode-line-inactive)))
|
2019-01-17 23:42:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
;; minor modes
|
|
|
|
;;
|
|
|
|
|
|
|
|
(doom-modeline-def-segment minor-modes
|
|
|
|
(when doom-modeline-minor-modes
|
2019-08-03 14:38:10 +08:00
|
|
|
(let ((face (if (doom-modeline--active)
|
|
|
|
'doom-modeline-buffer-minor-mode
|
|
|
|
'mode-line-inactive)))
|
2019-01-17 23:42:33 +08:00
|
|
|
(if (bound-and-true-p minions-mode)
|
|
|
|
(concat
|
2019-05-22 15:15:48 +08:00
|
|
|
(doom-modeline-spc)
|
2019-01-17 23:42:33 +08:00
|
|
|
(propertize minions-mode-line-lighter
|
2019-08-03 14:38:10 +08:00
|
|
|
'face face
|
2019-01-17 23:42:33 +08:00
|
|
|
'help-echo "Minions
|
|
|
|
mouse-1: Display minor modes menu"
|
|
|
|
'mouse-face 'mode-line-highlight
|
|
|
|
'local-map (make-mode-line-mouse-map
|
|
|
|
'mouse-1 #'minions-minor-modes-menu))
|
2019-05-22 15:15:48 +08:00
|
|
|
(doom-modeline-spc))
|
2019-08-02 01:11:00 +08:00
|
|
|
(concat
|
2019-08-03 14:38:10 +08:00
|
|
|
(propertize (replace-regexp-in-string
|
2019-08-03 14:42:12 +08:00
|
|
|
"%" "%%%%"
|
2019-08-03 14:38:10 +08:00
|
|
|
(format-mode-line minor-mode-alist)
|
|
|
|
t t)
|
|
|
|
'face face)
|
|
|
|
(doom-modeline-spc))))))
|
2019-01-17 23:42:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
;; vcs
|
|
|
|
;;
|
|
|
|
|
2019-10-23 02:50:04 +08:00
|
|
|
(defun doom-modeline-vcs-icon (icon &optional unicode text face voffset)
|
2019-01-17 23:42:33 +08:00
|
|
|
"Displays the vcs ICON with FACE and VOFFSET.
|
2019-10-23 02:50:04 +08:00
|
|
|
|
|
|
|
UNICODE and TEXT are fallbacks.
|
2019-01-17 23:42:33 +08:00
|
|
|
Uses `all-the-icons-octicon' to fetch the icon."
|
2019-10-23 02:50:04 +08:00
|
|
|
(doom-modeline-icon 'octicon icon unicode text face :v-adjust (or voffset -0.1)))
|
2019-01-17 23:42:33 +08:00
|
|
|
|
|
|
|
(defvar-local doom-modeline--vcs-icon nil)
|
2019-03-16 18:46:57 +07:00
|
|
|
(defun doom-modeline-update-vcs-icon (&rest _)
|
2019-04-06 15:12:11 +08:00
|
|
|
"Update icon of vcs state in mode-line."
|
2019-01-17 23:42:33 +08:00
|
|
|
(setq doom-modeline--vcs-icon
|
|
|
|
(when (and vc-mode buffer-file-name)
|
|
|
|
(let* ((backend (vc-backend buffer-file-name))
|
|
|
|
(state (vc-state buffer-file-name backend)))
|
|
|
|
(cond ((memq state '(edited added))
|
2019-10-23 02:50:04 +08:00
|
|
|
(doom-modeline-vcs-icon "git-compare" "⇆" "*" 'doom-modeline-info -0.05))
|
2019-01-17 23:42:33 +08:00
|
|
|
((eq state 'needs-merge)
|
2019-10-23 02:50:04 +08:00
|
|
|
(doom-modeline-vcs-icon "git-merge" "⛙" "?" 'doom-modeline-info))
|
2019-01-17 23:42:33 +08:00
|
|
|
((eq state 'needs-update)
|
2019-10-23 02:50:04 +08:00
|
|
|
(doom-modeline-vcs-icon "arrow-down" "↓" "!" 'doom-modeline-warning))
|
2019-01-17 23:42:33 +08:00
|
|
|
((memq state '(removed conflict unregistered))
|
2019-10-23 02:50:04 +08:00
|
|
|
(doom-modeline-vcs-icon "alert" "⚠" "!" 'doom-modeline-urgent))
|
2019-01-17 23:42:33 +08:00
|
|
|
(t
|
2019-10-23 03:15:18 +08:00
|
|
|
(doom-modeline-vcs-icon "git-branch" "⑆" "@" 'doom-modeline-info -0.05)))))))
|
2019-03-16 18:46:57 +07:00
|
|
|
(add-hook 'find-file-hook #'doom-modeline-update-vcs-icon t)
|
|
|
|
(add-hook 'after-save-hook #'doom-modeline-update-vcs-icon)
|
|
|
|
(advice-add #'vc-refresh-state :after #'doom-modeline-update-vcs-icon)
|
2019-01-17 23:42:33 +08:00
|
|
|
|
2019-03-14 15:27:43 +07:00
|
|
|
(when (>= emacs-major-version 26)
|
|
|
|
(add-variable-watcher
|
|
|
|
'doom-modeline-icon
|
|
|
|
(lambda (_sym val op _where)
|
|
|
|
(when (eq op 'set)
|
|
|
|
(setq doom-modeline-icon val)
|
2019-10-23 02:50:04 +08:00
|
|
|
(dolist (buf (buffer-list))
|
|
|
|
(with-current-buffer buf
|
|
|
|
(doom-modeline-update-vcs-icon))))))
|
|
|
|
|
|
|
|
(add-variable-watcher
|
|
|
|
'doom-modeline-unicode-fallback
|
|
|
|
(lambda (_sym val op _where)
|
|
|
|
(when (eq op 'set)
|
|
|
|
(setq doom-modeline-unicode-fallback val)
|
2019-03-17 17:54:01 +07:00
|
|
|
(dolist (buf (buffer-list))
|
|
|
|
(with-current-buffer buf
|
2019-04-20 02:39:05 +08:00
|
|
|
(doom-modeline-update-vcs-icon)))))))
|
2019-03-14 15:27:43 +07:00
|
|
|
|
2019-01-17 23:42:33 +08:00
|
|
|
(defvar-local doom-modeline--vcs-text nil)
|
|
|
|
(defun doom-modeline-update-vcs-text (&rest _)
|
2019-04-06 15:12:11 +08:00
|
|
|
"Update text of vcs state in mode-line."
|
2019-01-17 23:42:33 +08:00
|
|
|
(setq doom-modeline--vcs-text
|
|
|
|
(when (and vc-mode buffer-file-name)
|
|
|
|
(let* ((backend (vc-backend buffer-file-name))
|
2019-04-06 15:12:11 +08:00
|
|
|
(state (vc-state buffer-file-name backend))
|
2019-10-31 16:57:48 +08:00
|
|
|
(str (if vc-display-status
|
|
|
|
(substring vc-mode (+ (if (eq backend 'Hg) 2 3) 2))
|
|
|
|
"")))
|
2019-04-06 15:12:11 +08:00
|
|
|
(propertize (if (> (length str) doom-modeline-vcs-max-length)
|
|
|
|
(concat
|
|
|
|
(substring str 0 (- doom-modeline-vcs-max-length 3))
|
|
|
|
"...")
|
|
|
|
str)
|
2019-11-07 17:44:47 +08:00
|
|
|
'mouse-face 'mode-line-highlight
|
2019-01-17 23:42:33 +08:00
|
|
|
'face (cond ((eq state 'needs-update)
|
|
|
|
'doom-modeline-warning)
|
|
|
|
((memq state '(removed conflict unregistered))
|
|
|
|
'doom-modeline-urgent)
|
|
|
|
(t 'doom-modeline-info)))))))
|
|
|
|
(add-hook 'find-file-hook #'doom-modeline-update-vcs-text t)
|
|
|
|
(add-hook 'after-save-hook #'doom-modeline-update-vcs-text)
|
|
|
|
(advice-add #'vc-refresh-state :after #'doom-modeline-update-vcs-text)
|
|
|
|
|
|
|
|
(doom-modeline-def-segment vcs
|
2019-11-07 17:44:47 +08:00
|
|
|
"Displays the current branch, colored based on its state."
|
|
|
|
(let ((active (doom-modeline--active)))
|
|
|
|
(when-let ((icon (or doom-modeline--vcs-icon (doom-modeline-update-vcs-icon)))
|
|
|
|
(text (or doom-modeline--vcs-text (doom-modeline-update-vcs-text))))
|
|
|
|
(concat
|
|
|
|
(doom-modeline-spc)
|
|
|
|
(propertize
|
2019-01-17 23:42:33 +08:00
|
|
|
(concat
|
2019-05-18 23:53:47 +08:00
|
|
|
(if active
|
2019-11-07 17:44:47 +08:00
|
|
|
icon
|
|
|
|
(propertize icon
|
|
|
|
'face `(:inherit ,(get-text-property 0 'face icon)
|
|
|
|
:inherit mode-line-inactive)))
|
|
|
|
(doom-modeline-vspc))
|
|
|
|
'mouse-face 'mode-line-highlight
|
|
|
|
'help-echo (get-text-property 1 'help-echo vc-mode)
|
|
|
|
'local-map (get-text-property 1 'local-map vc-mode))
|
|
|
|
(if active
|
|
|
|
text
|
|
|
|
(propertize text 'face 'mode-line-inactive))
|
|
|
|
(doom-modeline-spc)))))
|
2019-01-17 23:42:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
;; checker
|
|
|
|
;;
|
|
|
|
|
2019-10-23 02:50:04 +08:00
|
|
|
(defun doom-modeline-checker-icon (icon unicode text face)
|
|
|
|
"Displays the checker ICON with FACE.
|
2019-01-17 23:42:33 +08:00
|
|
|
|
2019-10-23 02:50:04 +08:00
|
|
|
UNICODE and TEXT are fallbacks.
|
2019-01-17 23:42:33 +08:00
|
|
|
Uses `all-the-icons-material' to fetch the icon."
|
2019-10-23 02:50:04 +08:00
|
|
|
(doom-modeline-icon 'material icon unicode text face :height 1.1 :v-adjust -0.225))
|
2019-01-17 23:42:33 +08:00
|
|
|
|
|
|
|
(defun doom-modeline-checker-text (text &optional face)
|
|
|
|
"Displays TEXT with FACE."
|
2019-10-23 02:50:04 +08:00
|
|
|
(propertize text 'face (or face 'mode-line)))
|
|
|
|
|
|
|
|
;; flycheck
|
2019-01-17 23:42:33 +08:00
|
|
|
|
|
|
|
(defvar-local doom-modeline--flycheck-icon nil)
|
|
|
|
(defun doom-modeline-update-flycheck-icon (&optional status)
|
|
|
|
"Update flycheck icon via STATUS."
|
|
|
|
(setq doom-modeline--flycheck-icon
|
|
|
|
(when-let
|
|
|
|
((icon
|
|
|
|
(pcase status
|
2019-10-23 02:50:04 +08:00
|
|
|
('finished (if flycheck-current-errors
|
2019-01-17 23:42:33 +08:00
|
|
|
(let-alist (flycheck-count-errors flycheck-current-errors)
|
2019-10-23 02:50:04 +08:00
|
|
|
(doom-modeline-checker-icon "do_not_disturb_alt" "🚫" "!"
|
2019-01-17 23:42:33 +08:00
|
|
|
(cond (.error 'doom-modeline-urgent)
|
|
|
|
(.warning 'doom-modeline-warning)
|
|
|
|
(t 'doom-modeline-info))))
|
2019-10-23 02:50:04 +08:00
|
|
|
(doom-modeline-checker-icon "check" "✔" "-" 'doom-modeline-info)))
|
|
|
|
('running (doom-modeline-checker-icon "access_time" "⏰" "*" 'doom-modeline-debug))
|
|
|
|
('no-checker (doom-modeline-checker-icon "sim_card_alert" "⚠" "-" 'doom-modeline-debug))
|
|
|
|
('errored (doom-modeline-checker-icon "sim_card_alert" "❗" "!" 'doom-modeline-urgent))
|
|
|
|
('interrupted (doom-modeline-checker-icon "pause" "·" "." 'doom-modeline-debug))
|
|
|
|
('suspicious (doom-modeline-checker-icon "priority_high" "❓" "?" 'doom-modeline-urgent))
|
2019-01-17 23:42:33 +08:00
|
|
|
(_ nil))))
|
2019-10-23 02:50:04 +08:00
|
|
|
(propertize icon
|
|
|
|
'help-echo (concat "Flycheck\n"
|
|
|
|
(pcase status
|
|
|
|
('finished "mouse-1: Display minor mode menu
|
2019-01-17 23:42:33 +08:00
|
|
|
mouse-2: Show help for minor mode")
|
2019-10-23 02:50:04 +08:00
|
|
|
('running "Running...")
|
|
|
|
('no-checker "No Checker")
|
|
|
|
('errored "Error")
|
|
|
|
('interrupted "Interrupted")
|
|
|
|
('suspicious "Suspicious")))
|
2019-11-07 17:44:47 +08:00
|
|
|
'mouse-face 'mode-line-highlight
|
2019-10-23 02:50:04 +08:00
|
|
|
'local-map (let ((map (make-sparse-keymap)))
|
|
|
|
(define-key map [mode-line down-mouse-1]
|
|
|
|
flycheck-mode-menu-map)
|
|
|
|
(define-key map [mode-line mouse-2]
|
|
|
|
(lambda ()
|
|
|
|
(interactive)
|
|
|
|
(describe-function 'flycheck-mode)))
|
|
|
|
map)))))
|
2019-01-17 23:42:33 +08:00
|
|
|
(add-hook 'flycheck-status-changed-functions #'doom-modeline-update-flycheck-icon)
|
|
|
|
(add-hook 'flycheck-mode-hook #'doom-modeline-update-flycheck-icon)
|
|
|
|
|
2019-03-14 15:27:43 +07:00
|
|
|
(when (>= emacs-major-version 26)
|
|
|
|
(add-variable-watcher
|
|
|
|
'doom-modeline-icon
|
|
|
|
(lambda (_sym val op _where)
|
|
|
|
(when (eq op 'set)
|
|
|
|
(setq doom-modeline-icon val)
|
2019-10-23 02:50:04 +08:00
|
|
|
(dolist (buf (buffer-list))
|
|
|
|
(with-current-buffer buf
|
|
|
|
(when (bound-and-true-p flycheck-mode)
|
|
|
|
(flycheck-buffer)))))))
|
|
|
|
|
|
|
|
(add-variable-watcher
|
|
|
|
'doom-modeline-unicode-fallback
|
|
|
|
(lambda (_sym val op _where)
|
|
|
|
(when (eq op 'set)
|
|
|
|
(setq doom-modeline-unicode-fallback val)
|
2019-03-17 17:54:01 +07:00
|
|
|
(dolist (buf (buffer-list))
|
|
|
|
(with-current-buffer buf
|
|
|
|
(when (bound-and-true-p flycheck-mode)
|
2019-04-20 02:39:05 +08:00
|
|
|
(flycheck-buffer))))))))
|
2019-03-14 15:27:43 +07:00
|
|
|
|
2019-01-17 23:42:33 +08:00
|
|
|
(defvar-local doom-modeline--flycheck-text nil)
|
|
|
|
(defun doom-modeline-update-flycheck-text (&optional status)
|
|
|
|
"Update flycheck text via STATUS."
|
|
|
|
(setq doom-modeline--flycheck-text
|
|
|
|
(when-let
|
|
|
|
((text
|
|
|
|
(pcase status
|
2019-10-23 02:50:04 +08:00
|
|
|
('finished (when flycheck-current-errors
|
2019-01-17 23:42:33 +08:00
|
|
|
(let-alist (flycheck-count-errors flycheck-current-errors)
|
|
|
|
(let ((error (or .error 0))
|
|
|
|
(warning (or .warning 0))
|
|
|
|
(info (or .info 0)))
|
2019-02-18 01:30:59 +08:00
|
|
|
(if doom-modeline-checker-simple-format
|
2019-10-23 02:50:04 +08:00
|
|
|
(doom-modeline-checker-text
|
|
|
|
(number-to-string (+ error warning info))
|
|
|
|
(cond ((> error 0) 'doom-modeline-urgent)
|
|
|
|
((> warning 0) 'doom-modeline-warning)
|
|
|
|
(t 'doom-modeline-info)))
|
2019-02-18 01:30:59 +08:00
|
|
|
(format "%s/%s/%s"
|
|
|
|
(doom-modeline-checker-text (number-to-string error)
|
|
|
|
'doom-modeline-urgent)
|
|
|
|
(doom-modeline-checker-text (number-to-string warning)
|
|
|
|
'doom-modeline-warning)
|
|
|
|
(doom-modeline-checker-text (number-to-string info)
|
|
|
|
'doom-modeline-info)))))))
|
2019-10-23 02:50:04 +08:00
|
|
|
('running nil)
|
|
|
|
('no-checker nil)
|
|
|
|
('errored (doom-modeline-checker-text "Error" 'doom-modeline-urgent))
|
|
|
|
('interrupted (doom-modeline-checker-text "Interrupted" 'doom-modeline-debug))
|
|
|
|
('suspicious (doom-modeline-checker-text "Suspicious" 'doom-modeline-urgent))
|
2019-01-17 23:42:33 +08:00
|
|
|
(_ nil))))
|
|
|
|
(propertize
|
|
|
|
text
|
|
|
|
'help-echo (pcase status
|
|
|
|
('finished
|
|
|
|
(concat
|
|
|
|
(if flycheck-current-errors
|
|
|
|
(let-alist (flycheck-count-errors flycheck-current-errors)
|
2019-05-14 01:19:48 +08:00
|
|
|
(format "error: %d, warning: %d, info: %d\n"
|
|
|
|
(or .error 0) (or .warning 0) (or .info 0))))
|
2019-01-17 23:42:33 +08:00
|
|
|
"mouse-1: Show all errors
|
2019-05-14 01:19:48 +08:00
|
|
|
mouse-3: Next error"
|
|
|
|
(if (featurep 'mwheel)
|
|
|
|
"\nwheel-up/wheel-down: Previous/next error")))
|
2019-01-17 23:42:33 +08:00
|
|
|
('running "Running...")
|
|
|
|
('no-checker "No Checker")
|
|
|
|
('errored "Error")
|
|
|
|
('interrupted "Interrupted")
|
|
|
|
('suspicious "Suspicious"))
|
|
|
|
'mouse-face 'mode-line-highlight
|
|
|
|
'local-map (let ((map (make-sparse-keymap)))
|
|
|
|
(define-key map [mode-line mouse-1]
|
|
|
|
#'flycheck-list-errors)
|
|
|
|
(define-key map [mode-line mouse-3]
|
|
|
|
#'flycheck-next-error)
|
2019-05-14 01:19:48 +08:00
|
|
|
(when (featurep 'mwheel)
|
|
|
|
(define-key map (vector 'mode-line
|
|
|
|
mouse-wheel-down-event)
|
|
|
|
(lambda (event)
|
|
|
|
(interactive "e")
|
|
|
|
(with-selected-window (posn-window (event-start event))
|
|
|
|
(flycheck-previous-error 1))))
|
|
|
|
(define-key map (vector 'mode-line
|
|
|
|
mouse-wheel-up-event)
|
|
|
|
(lambda (event)
|
|
|
|
(interactive "e")
|
|
|
|
(with-selected-window (posn-window (event-start event))
|
|
|
|
(flycheck-next-error 1))))
|
|
|
|
map))))))
|
2019-01-17 23:42:33 +08:00
|
|
|
(add-hook 'flycheck-status-changed-functions #'doom-modeline-update-flycheck-text)
|
|
|
|
(add-hook 'flycheck-mode-hook #'doom-modeline-update-flycheck-text)
|
|
|
|
|
|
|
|
;; flymake
|
|
|
|
|
|
|
|
(defvar-local doom-modeline--flymake-icon nil)
|
|
|
|
(defun doom-modeline-update-flymake-icon (&rest _)
|
|
|
|
"Update flymake icon."
|
|
|
|
(setq flymake--mode-line-format nil) ; remove the lighter of minor mode
|
|
|
|
(setq doom-modeline--flymake-icon
|
|
|
|
(let* ((known (hash-table-keys flymake--backend-state))
|
|
|
|
(running (flymake-running-backends))
|
|
|
|
(disabled (flymake-disabled-backends))
|
|
|
|
(reported (flymake-reporting-backends))
|
|
|
|
(all-disabled (and disabled (null running)))
|
|
|
|
(some-waiting (cl-set-difference running reported)))
|
|
|
|
(when-let
|
|
|
|
((icon
|
|
|
|
(cond
|
2019-10-23 02:50:04 +08:00
|
|
|
(some-waiting (doom-modeline-checker-icon "access_time" "⏰" "*" 'doom-modeline-debug))
|
|
|
|
((null known) (doom-modeline-checker-icon "sim_card_alert" "❓" "?" 'doom-modeline-debug))
|
|
|
|
(all-disabled (doom-modeline-checker-icon "sim_card_alert" "❗" "!" 'doom-modeline-urgent))
|
2019-04-23 00:11:03 +03:00
|
|
|
(t (let ((.error 0)
|
|
|
|
(.warning 0)
|
|
|
|
(.note 0))
|
|
|
|
(progn
|
|
|
|
(cl-loop
|
|
|
|
with warning-level = (warning-numeric-level :warning)
|
|
|
|
with note-level = (warning-numeric-level :debug)
|
|
|
|
for state being the hash-values of flymake--backend-state
|
|
|
|
do (cl-loop
|
|
|
|
with diags = (flymake--backend-state-diags state)
|
|
|
|
for diag in diags do
|
2019-05-04 13:51:02 +03:00
|
|
|
(let ((severity (flymake--lookup-type-property (flymake--diag-type diag) 'severity
|
|
|
|
(warning-numeric-level :error))))
|
2019-04-23 00:11:03 +03:00
|
|
|
(cond ((> severity warning-level) (cl-incf .error))
|
|
|
|
((> severity note-level) (cl-incf .warning))
|
|
|
|
(t (cl-incf .note))))))
|
|
|
|
(if (> (+ .error .warning .note) 0)
|
2019-10-23 02:50:04 +08:00
|
|
|
(doom-modeline-checker-icon "do_not_disturb_alt" "🚫" "!"
|
2019-04-23 00:11:03 +03:00
|
|
|
(cond ((> .error 0) 'doom-modeline-urgent)
|
|
|
|
((> .warning 0) 'doom-modeline-warning)
|
|
|
|
(t 'doom-modeline-info)))
|
2019-10-23 02:50:04 +08:00
|
|
|
(doom-modeline-checker-icon "check" "✔" "-" 'doom-modeline-info))))))))
|
2019-01-17 23:42:33 +08:00
|
|
|
(propertize
|
|
|
|
icon
|
|
|
|
'help-echo (concat "Flymake\n"
|
|
|
|
(cond
|
|
|
|
(some-waiting "Running...")
|
|
|
|
((null known) "No Checker")
|
|
|
|
(all-disabled "All Checkers Disabled")
|
|
|
|
(t (format "%d/%d backends running
|
|
|
|
mouse-1: Display minor mode menu
|
|
|
|
mouse-2: Show help for minor mode"
|
|
|
|
(length running) (length known)))))
|
2019-11-07 17:44:47 +08:00
|
|
|
'mouse-face 'mode-line-highlight
|
2019-01-17 23:42:33 +08:00
|
|
|
'local-map (let ((map (make-sparse-keymap)))
|
|
|
|
(define-key map [mode-line down-mouse-1]
|
|
|
|
flymake-menu)
|
|
|
|
(define-key map [mode-line mouse-2]
|
|
|
|
(lambda ()
|
|
|
|
(interactive)
|
|
|
|
(describe-function 'flymake-mode)))
|
|
|
|
map))))))
|
|
|
|
(advice-add #'flymake--handle-report :after #'doom-modeline-update-flymake-icon)
|
|
|
|
|
2019-03-14 15:27:43 +07:00
|
|
|
(when (>= emacs-major-version 26)
|
|
|
|
(add-variable-watcher
|
|
|
|
'doom-modeline-icon
|
|
|
|
(lambda (_sym val op _where)
|
|
|
|
(when (eq op 'set)
|
|
|
|
(setq doom-modeline-icon val)
|
2019-10-23 02:50:04 +08:00
|
|
|
(dolist (buf (buffer-list))
|
|
|
|
(with-current-buffer buf
|
|
|
|
(when (bound-and-true-p flymake-mode)
|
|
|
|
(flymake-start)))))))
|
|
|
|
|
|
|
|
(add-variable-watcher
|
|
|
|
'doom-modeline-unicode-fallback
|
|
|
|
(lambda (_sym val op _where)
|
|
|
|
(when (eq op 'set)
|
|
|
|
(setq doom-modeline-unicode-fallback val)
|
2019-03-17 17:54:01 +07:00
|
|
|
(dolist (buf (buffer-list))
|
|
|
|
(with-current-buffer buf
|
|
|
|
(when (bound-and-true-p flymake-mode)
|
2019-04-20 02:39:05 +08:00
|
|
|
(flymake-start))))))))
|
2019-03-14 15:27:43 +07:00
|
|
|
|
2019-01-17 23:42:33 +08:00
|
|
|
(defvar-local doom-modeline--flymake-text nil)
|
|
|
|
(defun doom-modeline-update-flymake-text (&rest _)
|
|
|
|
"Update flymake text."
|
|
|
|
(setq flymake--mode-line-format nil) ; remove the lighter of minor mode
|
|
|
|
(setq doom-modeline--flymake-text
|
|
|
|
(let* ((known (hash-table-keys flymake--backend-state))
|
|
|
|
(running (flymake-running-backends))
|
|
|
|
(disabled (flymake-disabled-backends))
|
|
|
|
(reported (flymake-reporting-backends))
|
|
|
|
(all-disabled (and disabled (null running)))
|
2019-04-23 00:11:03 +03:00
|
|
|
(some-waiting (cl-set-difference running reported))
|
|
|
|
(warning-level (warning-numeric-level :warning))
|
|
|
|
(note-level (warning-numeric-level :debug))
|
|
|
|
(.error 0)
|
|
|
|
(.warning 0)
|
|
|
|
(.note 0))
|
2019-01-17 23:42:33 +08:00
|
|
|
(maphash (lambda (_b state)
|
2019-04-23 00:11:03 +03:00
|
|
|
(cl-loop
|
|
|
|
with diags = (flymake--backend-state-diags state)
|
|
|
|
for diag in diags do
|
2019-05-04 13:51:02 +03:00
|
|
|
(let ((severity (flymake--lookup-type-property (flymake--diag-type diag) 'severity
|
|
|
|
(warning-numeric-level :error))))
|
2019-04-23 00:11:03 +03:00
|
|
|
(cond ((> severity warning-level) (cl-incf .error))
|
|
|
|
((> severity note-level) (cl-incf .warning))
|
|
|
|
(t (cl-incf .note))))))
|
2019-01-17 23:42:33 +08:00
|
|
|
flymake--backend-state)
|
2019-04-23 00:11:03 +03:00
|
|
|
(when-let
|
|
|
|
((text
|
|
|
|
(cond
|
2019-05-14 15:31:14 +03:00
|
|
|
(some-waiting doom-modeline--flymake-text)
|
2019-05-22 13:59:03 +08:00
|
|
|
((null known) nil)
|
|
|
|
(all-disabled nil)
|
2019-04-23 00:11:03 +03:00
|
|
|
(t (let ((num (+ .error .warning .note)))
|
|
|
|
(when (> num 0)
|
|
|
|
(if doom-modeline-checker-simple-format
|
|
|
|
(doom-modeline-checker-text (number-to-string num)
|
|
|
|
(cond ((> .error 0) 'doom-modeline-urgent)
|
|
|
|
((> .warning 0) 'doom-modeline-warning)
|
|
|
|
(t 'doom-modeline-info)))
|
|
|
|
(format "%s/%s/%s"
|
|
|
|
(doom-modeline-checker-text (number-to-string .error)
|
|
|
|
'doom-modeline-urgent)
|
|
|
|
(doom-modeline-checker-text (number-to-string .warning)
|
|
|
|
'doom-modeline-warning)
|
|
|
|
(doom-modeline-checker-text (number-to-string .note)
|
|
|
|
'doom-modeline-info)))))))))
|
|
|
|
(propertize
|
|
|
|
text
|
|
|
|
'help-echo (cond
|
|
|
|
(some-waiting "Running...")
|
|
|
|
((null known) "No Checker")
|
|
|
|
(all-disabled "All Checkers Disabled")
|
|
|
|
(t (format "error: %d, warning: %d, note: %d
|
2019-05-14 01:19:48 +08:00
|
|
|
mouse-1: List all problems%s"
|
2019-05-15 18:26:24 +08:00
|
|
|
.error .warning .note
|
2019-05-14 01:19:48 +08:00
|
|
|
(if (featurep 'mwheel)
|
2019-05-15 18:26:24 +08:00
|
|
|
"\nwheel-up/wheel-down: Previous/next problem"))))
|
2019-04-23 00:11:03 +03:00
|
|
|
'mouse-face 'mode-line-highlight
|
|
|
|
'local-map (let ((map (make-sparse-keymap)))
|
|
|
|
(define-key map [mode-line mouse-1]
|
|
|
|
#'flymake-show-diagnostics-buffer)
|
2019-05-14 01:19:48 +08:00
|
|
|
(when (featurep 'mwheel)
|
|
|
|
(define-key map (vector 'mode-line
|
|
|
|
mouse-wheel-down-event)
|
|
|
|
(lambda (event)
|
|
|
|
(interactive "e")
|
|
|
|
(with-selected-window (posn-window (event-start event))
|
|
|
|
(flymake-goto-prev-error 1 nil t))))
|
|
|
|
(define-key map (vector 'mode-line
|
|
|
|
mouse-wheel-up-event)
|
|
|
|
(lambda (event)
|
|
|
|
(interactive "e")
|
|
|
|
(with-selected-window (posn-window (event-start event))
|
|
|
|
(flymake-goto-next-error 1 nil t))))
|
|
|
|
map)))))))
|
2019-01-17 23:42:33 +08:00
|
|
|
(advice-add #'flymake--handle-report :after #'doom-modeline-update-flymake-text)
|
|
|
|
|
|
|
|
(doom-modeline-def-segment checker
|
2019-05-21 14:40:35 +08:00
|
|
|
"Displays color-coded error status in the current buffer with pretty icons."
|
2019-01-17 23:42:33 +08:00
|
|
|
(let ((active (doom-modeline--active))
|
|
|
|
(seg (cond ((and (bound-and-true-p flymake-mode)
|
|
|
|
(bound-and-true-p flymake--backend-state)) ; only support 26+
|
|
|
|
`(,doom-modeline--flymake-icon . ,doom-modeline--flymake-text))
|
|
|
|
((bound-and-true-p flycheck-mode)
|
|
|
|
`(,doom-modeline--flycheck-icon . ,doom-modeline--flycheck-text)))))
|
2019-05-21 14:40:35 +08:00
|
|
|
(if seg
|
|
|
|
(let ((icon (car seg))
|
|
|
|
(text (cdr seg)))
|
|
|
|
(concat
|
2019-05-22 15:15:48 +08:00
|
|
|
(doom-modeline-spc)
|
2019-05-21 14:40:35 +08:00
|
|
|
(when icon
|
|
|
|
(if active
|
|
|
|
icon
|
2019-06-27 17:41:29 +08:00
|
|
|
(propertize icon 'face `(:inherit ,(get-text-property 0 'face icon)
|
|
|
|
:inherit mode-line-inactive))))
|
2019-05-21 14:40:35 +08:00
|
|
|
(when text
|
2019-10-27 11:36:39 -07:00
|
|
|
(concat
|
|
|
|
(doom-modeline-vspc)
|
|
|
|
(if active
|
|
|
|
text
|
2019-11-11 13:34:33 +08:00
|
|
|
(propertize text 'face 'mode-line-inactive))))))
|
2019-05-21 14:40:35 +08:00
|
|
|
"")))
|
2019-01-17 23:42:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
;; selection-info
|
|
|
|
;;
|
|
|
|
|
|
|
|
(defsubst doom-modeline-column (pos)
|
|
|
|
"Get the column of the position `POS'."
|
|
|
|
(save-excursion (goto-char pos)
|
|
|
|
(current-column)))
|
|
|
|
|
|
|
|
(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 (or mark-active (and (bound-and-true-p evil-local-mode)
|
|
|
|
(eq evil-state 'visual)))
|
|
|
|
(doom-modeline--active))
|
|
|
|
(cl-destructuring-bind (beg . end)
|
|
|
|
(if (and (bound-and-true-p evil-local-mode) (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)))))
|
2019-05-22 15:15:48 +08:00
|
|
|
(concat (doom-modeline-spc)
|
2019-01-17 23:42:33 +08:00
|
|
|
(cond ((or (bound-and-true-p rectangle-mark-mode)
|
|
|
|
(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)))
|
|
|
|
((and (bound-and-true-p evil-visual-selection)
|
|
|
|
(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)))
|
2019-05-22 15:15:48 +08:00
|
|
|
(doom-modeline-spc)))
|
2019-01-17 23:42:33 +08:00
|
|
|
'face 'doom-modeline-highlight))))
|
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
;; matches (macro, anzu, evil-substitute, iedit, symbol-overlay and multi-cursors)
|
|
|
|
;;
|
|
|
|
|
|
|
|
(defsubst doom-modeline--macro-recording ()
|
|
|
|
"Display current Emacs or evil macro being recorded."
|
|
|
|
(when (and (doom-modeline--active) (or defining-kbd-macro executing-kbd-macro))
|
|
|
|
(let ((sep (propertize " " 'face 'doom-modeline-panel)))
|
|
|
|
(concat sep
|
2019-10-23 02:50:04 +08:00
|
|
|
(doom-modeline-icon 'material "fiber_manual_record" "●"
|
|
|
|
(if (bound-and-true-p evil-this-macro)
|
|
|
|
(char-to-string evil-this-macro)
|
|
|
|
"Macro")
|
|
|
|
'doom-modeline-panel
|
|
|
|
:v-adjust -0.225)
|
2019-01-17 23:42:33 +08:00
|
|
|
sep
|
2019-10-23 02:50:04 +08:00
|
|
|
(doom-modeline-icon 'octicon "triangle-right" "▶" ">"
|
|
|
|
'doom-modeline-panel
|
|
|
|
:v-adjust -0.05)
|
2019-01-17 23:42:33 +08:00
|
|
|
sep))))
|
|
|
|
|
|
|
|
;; anzu and evil-anzu expose current/total state that can be displayed in the
|
|
|
|
;; mode-line.
|
|
|
|
(defun doom-modeline-fix-anzu-count (positions here)
|
|
|
|
"Calulate anzu counts via POSITIONS and 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)
|
|
|
|
|
2019-02-28 15:20:13 -05:00
|
|
|
(setq anzu-cons-mode-line-p nil) ; manage modeline segment ourselves
|
2019-01-17 23:42:33 +08:00
|
|
|
;; Ensure anzu state is cleared when searches & iedit are done
|
|
|
|
(with-eval-after-load 'anzu
|
|
|
|
(add-hook 'isearch-mode-end-hook #'anzu--reset-status t)
|
|
|
|
(add-hook 'iedit-mode-end-hook #'anzu--reset-status)
|
2019-02-28 19:10:19 -05:00
|
|
|
(advice-add #'evil-force-normal-state :after #'anzu--reset-status)
|
|
|
|
;; Fix matches segment mirroring across all buffers
|
|
|
|
(mapc #'make-variable-buffer-local
|
2019-03-01 18:20:25 +07:00
|
|
|
'(anzu--total-matched
|
|
|
|
anzu--current-position anzu--state anzu--cached-count
|
2019-03-01 16:33:02 +07:00
|
|
|
anzu--cached-positions anzu--last-command
|
2019-02-28 19:10:19 -05:00
|
|
|
anzu--last-isearch-string anzu--overflow-p)))
|
2019-01-17 23:42:33 +08:00
|
|
|
|
|
|
|
(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'."
|
|
|
|
(when (and (bound-and-true-p anzu--state)
|
|
|
|
(not (bound-and-true-p iedit-mode)))
|
|
|
|
(propertize
|
|
|
|
(let ((here anzu--current-position)
|
2019-03-01 18:20:25 +07:00
|
|
|
(total anzu--total-matched))
|
2019-01-17 23:42:33 +08:00
|
|
|
(cond ((eq anzu--state 'replace-query)
|
2019-03-01 18:20:25 +07:00
|
|
|
(format " %d replace " anzu--cached-count))
|
2019-01-17 23:42:33 +08:00
|
|
|
((eq anzu--state 'replace)
|
|
|
|
(format " %d/%d " here total))
|
|
|
|
(anzu--overflow-p
|
|
|
|
(format " %s+ " total))
|
|
|
|
(t
|
|
|
|
(format " %s/%d " here total))))
|
2019-02-12 02:44:31 +08:00
|
|
|
'face (if (doom-modeline--active) 'doom-modeline-panel 'mode-line-inactive))))
|
2019-01-17 23:42:33 +08:00
|
|
|
|
|
|
|
(defsubst doom-modeline--evil-substitute ()
|
|
|
|
"Show number of matches for evil-ex substitutions and highlights in real time."
|
|
|
|
(when (and (bound-and-true-p evil-local-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)))
|
|
|
|
(propertize
|
|
|
|
(let ((range (if evil-ex-range
|
|
|
|
(cons (car evil-ex-range) (cadr evil-ex-range))
|
|
|
|
(cons (line-beginning-position) (line-end-position))))
|
|
|
|
(pattern (car-safe (evil-delimited-arguments evil-ex-argument 2))))
|
|
|
|
(if pattern
|
|
|
|
(format " %s matches " (how-many pattern (car range) (cdr range)))
|
|
|
|
" - "))
|
2019-02-12 02:44:31 +08:00
|
|
|
'face (if (doom-modeline--active) 'doom-modeline-panel 'mode-line-inactive))))
|
2019-01-17 23:42:33 +08:00
|
|
|
|
|
|
|
(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 (bound-and-true-p iedit-mode)
|
|
|
|
(bound-and-true-p iedit-occurrences-overlays))
|
|
|
|
(propertize
|
|
|
|
(let ((this-oc (or (let ((inhibit-message t))
|
|
|
|
(iedit-find-current-occurrence-overlay))
|
2019-10-19 02:54:28 +08:00
|
|
|
(save-excursion (iedit-prev-occurrence)
|
|
|
|
(iedit-find-current-occurrence-overlay))))
|
2019-01-17 23:42:33 +08:00
|
|
|
(length (length iedit-occurrences-overlays)))
|
|
|
|
(format " %s/%d "
|
|
|
|
(if this-oc
|
|
|
|
(- length
|
|
|
|
(length (memq this-oc (sort (append iedit-occurrences-overlays nil)
|
|
|
|
#'doom-modeline-themes--overlay-sort)))
|
|
|
|
-1)
|
|
|
|
"-")
|
|
|
|
length))
|
2019-02-12 02:44:31 +08:00
|
|
|
'face (if (doom-modeline--active) 'doom-modeline-panel 'mode-line-inactive))))
|
2019-01-17 23:42:33 +08:00
|
|
|
|
|
|
|
(defsubst doom-modeline--symbol-overlay ()
|
|
|
|
"Show the number of matches for symbol overlay."
|
2019-03-07 15:19:54 +07:00
|
|
|
(when (and (doom-modeline--active)
|
|
|
|
(bound-and-true-p symbol-overlay-keywords-alist)
|
2019-01-17 23:42:33 +08:00
|
|
|
(not (bound-and-true-p symbol-overlay-temp-symbol))
|
|
|
|
(not (bound-and-true-p iedit-mode)))
|
2019-06-08 18:49:20 +08:00
|
|
|
(let* ((keyword (symbol-overlay-assoc (symbol-overlay-get-symbol t)))
|
2019-01-17 23:42:33 +08:00
|
|
|
(symbol (car keyword))
|
2019-03-07 15:19:54 +07:00
|
|
|
(before (symbol-overlay-get-list -1 symbol))
|
|
|
|
(after (symbol-overlay-get-list 1 symbol))
|
2019-01-17 23:42:33 +08:00
|
|
|
(count (length before)))
|
|
|
|
(if (symbol-overlay-assoc symbol)
|
|
|
|
(propertize
|
|
|
|
(format (concat " %d/%d " (and (cadr keyword) "in scope "))
|
|
|
|
(+ count 1)
|
|
|
|
(+ count (length after)))
|
2019-02-12 02:44:31 +08:00
|
|
|
'face (if (doom-modeline--active) 'doom-modeline-panel 'mode-line-inactive))))))
|
2019-01-17 23:42:33 +08:00
|
|
|
|
|
|
|
(defsubst doom-modeline--multiple-cursors ()
|
|
|
|
"Show the number of multiple cursors."
|
2019-03-05 16:59:32 -05:00
|
|
|
(cl-destructuring-bind (count . face)
|
2019-03-09 02:32:27 +07:00
|
|
|
(cond ((bound-and-true-p multiple-cursors-mode)
|
2019-03-10 13:08:20 +01:00
|
|
|
(cons (mc/num-cursors)
|
2019-03-09 02:32:27 +07:00
|
|
|
(if (doom-modeline--active)
|
2019-03-11 15:38:06 +07:00
|
|
|
'doom-modeline-panel
|
2019-03-10 14:20:37 +01:00
|
|
|
'mode-line-inactive)))
|
2019-03-09 02:32:27 +07:00
|
|
|
((bound-and-true-p evil-mc-cursor-list)
|
|
|
|
(cons (length evil-mc-cursor-list)
|
|
|
|
(cond ((not (doom-modeline--active)) 'mode-line-inactive)
|
2019-03-11 15:38:06 +07:00
|
|
|
(evil-mc-frozen 'doom-modeline-bar)
|
|
|
|
('doom-modeline-panel))))
|
2019-03-09 02:32:27 +07:00
|
|
|
((cons nil nil)))
|
2019-03-05 16:59:32 -05:00
|
|
|
(when count
|
|
|
|
(concat (propertize " " 'face face)
|
2019-10-23 02:50:04 +08:00
|
|
|
(or (doom-modeline-icon 'faicon "i-cursor" nil nil face :v-adjust -0.0575)
|
|
|
|
(propertize "I"
|
|
|
|
'face `(:inherit ,face :height 1.4 :weight normal)
|
|
|
|
'display '(raise -0.1)))
|
2019-05-16 23:31:52 +08:00
|
|
|
(propertize (doom-modeline-vspc) 'face `(:inherit (variable-pitch ,face)))
|
2019-03-05 16:59:32 -05:00
|
|
|
(propertize (format "%d " count)
|
|
|
|
'face face)))))
|
2019-01-17 23:42:33 +08:00
|
|
|
|
|
|
|
(defsubst doom-modeline--buffer-size ()
|
|
|
|
"Show buffer size."
|
2019-11-08 23:43:45 +08:00
|
|
|
(when size-indication-mode
|
|
|
|
(concat (doom-modeline-spc)
|
|
|
|
(propertize "%I"
|
|
|
|
'face (if (doom-modeline--active) 'mode-line 'mode-line-inactive)
|
|
|
|
'help-echo "Buffer size
|
2019-01-17 23:42:33 +08:00
|
|
|
mouse-1: Display Line and Column Mode Menu"
|
2019-11-08 23:43:45 +08:00
|
|
|
'mouse-face 'mode-line-highlight
|
|
|
|
'local-map mode-line-column-line-number-mode-map)
|
|
|
|
(doom-modeline-spc))))
|
2019-01-17 23:42:33 +08:00
|
|
|
|
|
|
|
(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,
|
|
|
|
5. The current/total for the highlight term (with `symbol-overlay'), 6. The number
|
|
|
|
of active `multiple-cursors'."
|
|
|
|
(let ((meta (concat (doom-modeline--macro-recording)
|
|
|
|
(doom-modeline--anzu)
|
|
|
|
(doom-modeline--evil-substitute)
|
|
|
|
(doom-modeline--iedit)
|
|
|
|
(doom-modeline--symbol-overlay)
|
|
|
|
(doom-modeline--multiple-cursors))))
|
|
|
|
(or (and (not (equal meta "")) meta)
|
|
|
|
(doom-modeline--buffer-size))))
|
|
|
|
|
|
|
|
(doom-modeline-def-segment buffer-size
|
|
|
|
"Display buffer size"
|
|
|
|
(doom-modeline--buffer-size))
|
|
|
|
|
|
|
|
;;
|
|
|
|
;; 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)
|
|
|
|
(when (fboundp 'image-size)
|
|
|
|
(image-size (image-get-display-property) :pixels))
|
2019-02-12 02:44:31 +08:00
|
|
|
(propertize
|
|
|
|
(format " %dx%d " width height)
|
|
|
|
'face (if (doom-modeline--active) 'mode-line 'mode-line-inactive))))))
|
2019-01-17 23:42:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
;; bar
|
|
|
|
;;
|
|
|
|
|
|
|
|
(defvar doom-modeline--bar-active nil)
|
|
|
|
(defvar doom-modeline--bar-inactive nil)
|
|
|
|
(doom-modeline-def-segment bar
|
2019-05-23 16:35:15 +08:00
|
|
|
"The bar regulates the height of the mode-line in GUI."
|
|
|
|
(if (doom-modeline--active)
|
|
|
|
doom-modeline--bar-active
|
|
|
|
doom-modeline--bar-inactive))
|
2019-01-17 23:42:33 +08:00
|
|
|
|
|
|
|
(defun doom-modeline-refresh-bars (&optional width height)
|
|
|
|
"Refresh 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)
|
|
|
|
(max (or height doom-modeline-height)
|
2019-05-23 16:35:15 +08:00
|
|
|
(doom-modeline--font-height)))
|
2019-01-17 23:42:33 +08:00
|
|
|
doom-modeline--bar-inactive
|
|
|
|
(doom-modeline--make-xpm 'doom-modeline-inactive-bar
|
|
|
|
(or width doom-modeline-bar-width)
|
|
|
|
(max (or height doom-modeline-height)
|
2019-05-23 16:35:15 +08:00
|
|
|
(doom-modeline--font-height)))))
|
2019-01-17 23:42:33 +08:00
|
|
|
|
|
|
|
(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))))
|
|
|
|
|
|
|
|
(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)))))
|
|
|
|
|
2019-03-01 16:17:02 +07:00
|
|
|
(add-hook 'after-setting-font-hook #'doom-modeline-refresh-bars)
|
2019-05-22 23:42:59 +08:00
|
|
|
(add-hook 'window-configuration-change-hook #'doom-modeline-refresh-bars)
|
2019-01-17 23:42:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
;; window number
|
|
|
|
;;
|
|
|
|
|
|
|
|
;; HACK: `ace-window-display-mode' should respect the ignore buffers.
|
|
|
|
(defun doom-modeline-aw-update ()
|
|
|
|
"Update ace-window-path window parameter for all windows.
|
|
|
|
Ensure all windows are labeled so the user can select a specific
|
|
|
|
one. The ignored buffers are excluded unless `aw-ignore-on' is nil."
|
|
|
|
(let ((ignore-window-parameters t))
|
|
|
|
(avy-traverse
|
|
|
|
(avy-tree (aw-window-list) aw-keys)
|
|
|
|
(lambda (path leaf)
|
|
|
|
(set-window-parameter
|
|
|
|
leaf 'ace-window-path
|
|
|
|
(propertize
|
|
|
|
(apply #'string (reverse path))
|
|
|
|
'face 'aw-mode-line-face))))))
|
|
|
|
(advice-add #'aw-update :override #'doom-modeline-aw-update)
|
|
|
|
|
|
|
|
;; Remove original window number of `ace-window-display-mode'.
|
|
|
|
(add-hook 'ace-window-display-mode-hook
|
|
|
|
(lambda ()
|
|
|
|
(setq-default mode-line-format
|
|
|
|
(assq-delete-all 'ace-window-display-mode
|
|
|
|
(default-value 'mode-line-format)))))
|
|
|
|
|
|
|
|
(advice-add #'window-numbering-install-mode-line :override #'ignore)
|
|
|
|
(advice-add #'window-numbering-clear-mode-line :override #'ignore)
|
|
|
|
(advice-add #'winum--install-mode-line :override #'ignore)
|
|
|
|
(advice-add #'winum--clear-mode-line :override #'ignore)
|
|
|
|
|
|
|
|
(doom-modeline-def-segment window-number
|
|
|
|
(let ((num (cond
|
|
|
|
((bound-and-true-p ace-window-display-mode)
|
|
|
|
(aw-update)
|
|
|
|
(window-parameter (selected-window) 'ace-window-path))
|
|
|
|
((bound-and-true-p winum-mode)
|
|
|
|
(setq winum-auto-setup-mode-line nil)
|
|
|
|
(winum-get-number-string))
|
|
|
|
((bound-and-true-p window-numbering-mode)
|
|
|
|
(window-numbering-get-number-string))
|
|
|
|
(t ""))))
|
2019-04-15 18:01:50 +08:00
|
|
|
(if (and (< 0 (length num))
|
2019-05-06 06:02:59 +08:00
|
|
|
(< (if (active-minibuffer-window) 2 1)
|
2019-05-12 14:16:40 +08:00
|
|
|
(length (cl-mapcan #'window-list (visible-frame-list)))))
|
2019-01-17 23:42:33 +08:00
|
|
|
(propertize (format " %s " num)
|
|
|
|
'face (if (doom-modeline--active)
|
2019-02-12 02:44:31 +08:00
|
|
|
'doom-modeline-buffer-major-mode
|
|
|
|
'mode-line-inactive)))))
|
2019-01-17 23:42:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
;; workspace number
|
|
|
|
;;
|
|
|
|
|
2019-04-15 17:50:39 +08:00
|
|
|
(doom-modeline-def-segment workspace-name
|
2019-01-17 23:42:33 +08:00
|
|
|
"The current workspace name or number.
|
|
|
|
Requires `eyebrowse-mode' to be enabled."
|
|
|
|
(if (and (bound-and-true-p eyebrowse-mode)
|
|
|
|
(< 1 (length (eyebrowse--get 'window-configs))))
|
|
|
|
(let* ((num (eyebrowse--get 'current-slot))
|
|
|
|
(tag (when num (nth 2 (assoc num (eyebrowse--get 'window-configs)))))
|
|
|
|
(str (if (and tag (< 0 (length tag)))
|
|
|
|
tag
|
|
|
|
(when num (int-to-string num)))))
|
|
|
|
(assq-delete-all 'eyebrowse-mode mode-line-misc-info)
|
|
|
|
(propertize (format " %s " str) 'face
|
2019-02-12 02:44:31 +08:00
|
|
|
(if (doom-modeline--active)
|
|
|
|
'doom-modeline-buffer-major-mode
|
|
|
|
'mode-line-inactive)))))
|
2019-01-17 23:42:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
;; perspective name
|
|
|
|
;;
|
|
|
|
|
|
|
|
(defvar-local doom-modeline--persp-name nil)
|
|
|
|
(defun doom-modeline-update-persp-name (&rest _)
|
|
|
|
"Update perspective name in mode-line."
|
|
|
|
(setq doom-modeline--persp-name
|
|
|
|
;; Support `persp-mode', while not support `perspective'
|
|
|
|
(when (and doom-modeline-persp-name
|
|
|
|
(bound-and-true-p persp-mode)
|
|
|
|
(fboundp 'safe-persp-name)
|
|
|
|
(fboundp 'get-current-persp))
|
2019-01-18 18:09:34 +08:00
|
|
|
(let* ((persp (get-current-persp))
|
2019-07-01 23:23:33 +05:00
|
|
|
(name (safe-persp-name persp))
|
2019-07-02 13:52:00 +08:00
|
|
|
(face (if (and persp
|
|
|
|
(not (persp-contain-buffer-p (current-buffer) persp)))
|
|
|
|
'doom-modeline-persp-buffer-not-in-persp
|
2019-07-16 00:39:05 +08:00
|
|
|
'doom-modeline-persp-name))
|
2019-10-23 02:50:04 +08:00
|
|
|
(icon (doom-modeline-icon 'material "folder" "🖿" "#"
|
|
|
|
`(:inherit ,face :slant normal)
|
|
|
|
:height 1.1
|
|
|
|
:v-adjust -0.225)))
|
2019-01-18 18:09:34 +08:00
|
|
|
(unless (string-equal persp-nil-name name)
|
2019-07-16 00:39:05 +08:00
|
|
|
(concat (doom-modeline-spc)
|
2019-10-23 02:50:04 +08:00
|
|
|
(propertize (concat icon
|
|
|
|
(doom-modeline-vspc)
|
|
|
|
(propertize name 'face face))
|
2019-07-16 00:39:05 +08:00
|
|
|
'help-echo "mouse-1: Switch perspective
|
2019-01-17 23:42:33 +08:00
|
|
|
mouse-2: Show help for minor mode"
|
2019-07-16 00:39:05 +08:00
|
|
|
'mouse-face 'mode-line-highlight
|
|
|
|
'local-map (let ((map (make-sparse-keymap)))
|
|
|
|
(define-key map [mode-line mouse-1]
|
|
|
|
#'persp-switch)
|
|
|
|
(define-key map [mode-line mouse-2]
|
|
|
|
(lambda ()
|
|
|
|
(interactive)
|
|
|
|
(describe-function 'persp-mode)))
|
|
|
|
map))
|
|
|
|
(doom-modeline-spc)))))))
|
2019-01-17 23:42:33 +08:00
|
|
|
|
|
|
|
(add-hook 'find-file-hook #'doom-modeline-update-persp-name)
|
|
|
|
(add-hook 'persp-activated-functions #'doom-modeline-update-persp-name)
|
|
|
|
(add-hook 'persp-renamed-functions #'doom-modeline-update-persp-name)
|
2019-06-06 17:11:26 +08:00
|
|
|
(advice-add #'select-window :after #'doom-modeline-update-persp-name)
|
2019-01-17 23:42:33 +08:00
|
|
|
|
|
|
|
(doom-modeline-def-segment persp-name
|
|
|
|
"The current perspective name."
|
|
|
|
(if (doom-modeline--active)
|
2019-02-12 02:44:31 +08:00
|
|
|
doom-modeline--persp-name))
|
2019-01-17 23:42:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
;; misc info
|
|
|
|
;;
|
|
|
|
|
|
|
|
(doom-modeline-def-segment misc-info
|
|
|
|
"Mode line construct for miscellaneous information.
|
|
|
|
By default, this shows the information specified by `global-mode-string'."
|
|
|
|
(if (doom-modeline--active)
|
2019-03-11 15:36:29 +07:00
|
|
|
'("" mode-line-misc-info)))
|
2019-01-17 23:42:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
;; position
|
|
|
|
;;
|
|
|
|
|
|
|
|
;; Be compatible with Emacs 25.
|
|
|
|
(defvar doom-modeline-column-zero-based
|
|
|
|
(if (boundp 'column-number-indicator-zero-based)
|
|
|
|
column-number-indicator-zero-based
|
|
|
|
t)
|
|
|
|
"When non-nil, mode line displays column numbers zero-based.
|
|
|
|
See `column-number-indicator-zero-based'.")
|
|
|
|
|
|
|
|
(defvar doom-modeline-percent-position
|
|
|
|
(if (boundp 'mode-line-percent-position)
|
|
|
|
mode-line-percent-position
|
|
|
|
'(-3 "%p"))
|
|
|
|
"Specification of \"percentage offset\" of window through buffer.
|
|
|
|
See `mode-line-percent-position'.")
|
|
|
|
|
|
|
|
(when (>= emacs-major-version 26)
|
|
|
|
(add-variable-watcher
|
|
|
|
'column-number-indicator-zero-based
|
|
|
|
(lambda (_sym val op _where)
|
|
|
|
(when (eq op 'set)
|
|
|
|
(setq doom-modeline-column-zero-based val))))
|
|
|
|
|
|
|
|
(add-variable-watcher
|
|
|
|
'mode-line-percent-position
|
|
|
|
(lambda (_sym val op _where)
|
|
|
|
(when (eq op 'set)
|
|
|
|
(setq doom-modeline-percent-position val)))))
|
|
|
|
|
|
|
|
(doom-modeline-def-segment buffer-position
|
|
|
|
"The buffer position information."
|
2019-11-08 03:01:36 +08:00
|
|
|
(let* ((active (doom-modeline--active))
|
|
|
|
(lc '(line-number-mode
|
|
|
|
(column-number-mode
|
|
|
|
(doom-modeline-column-zero-based "%l:%c" "%l:%C")
|
|
|
|
"%l")
|
|
|
|
(column-number-mode (doom-modeline-column-zero-based ":%c" ":%C"))))
|
|
|
|
(face (if active 'mode-line 'mode-line-inactive))
|
|
|
|
(mouse-face 'mode-line-highlight)
|
|
|
|
(help-echo "Buffer position\n\
|
|
|
|
mouse-1: Display Line and Column Mode Menu")
|
|
|
|
(local-map mode-line-column-line-number-mode-map))
|
|
|
|
(concat
|
|
|
|
(doom-modeline-spc)
|
|
|
|
(doom-modeline-spc)
|
|
|
|
(if (and active
|
|
|
|
(bound-and-true-p nyan-mode)
|
|
|
|
(>= (window-width) nyan-minimum-window-width))
|
|
|
|
(concat
|
|
|
|
(nyan-create)
|
|
|
|
(doom-modeline-spc)
|
|
|
|
(propertize (format-mode-line lc)
|
|
|
|
'help-echo help-echo
|
|
|
|
'mouse-face mouse-face
|
|
|
|
'local-map local-map))
|
|
|
|
(concat
|
|
|
|
(propertize (format-mode-line lc)
|
|
|
|
'face face
|
|
|
|
'help-echo help-echo
|
|
|
|
'mouse-face mouse-face
|
|
|
|
'local-map local-map)
|
|
|
|
(when doom-modeline-percent-position
|
|
|
|
(concat
|
|
|
|
(doom-modeline-spc)
|
|
|
|
(propertize (format-mode-line '("" doom-modeline-percent-position "%%"))
|
|
|
|
'face face
|
|
|
|
'help-echo help-echo
|
|
|
|
'mouse-face mouse-face
|
|
|
|
'local-map local-map)))
|
|
|
|
(when (or line-number-mode column-number-mode doom-modeline-percent-position)
|
|
|
|
(doom-modeline-spc)))))))
|
2019-01-17 23:42:33 +08:00
|
|
|
|
|
|
|
;;
|
|
|
|
;; party parrot
|
|
|
|
;;
|
|
|
|
(doom-modeline-def-segment parrot
|
|
|
|
"The party parrot animated icon. Requires `parrot-mode' to be enabled."
|
|
|
|
(when (and (bound-and-true-p parrot-mode)
|
|
|
|
(doom-modeline--active))
|
2019-05-22 15:15:48 +08:00
|
|
|
(concat (doom-modeline-spc)
|
|
|
|
(doom-modeline-spc)
|
2019-05-17 01:56:09 +08:00
|
|
|
(parrot-create)
|
2019-05-22 15:15:48 +08:00
|
|
|
(doom-modeline-spc))))
|
2019-01-17 23:42:33 +08:00
|
|
|
|
|
|
|
;;
|
2019-11-06 00:56:45 +08:00
|
|
|
;; modals (evil, overwrite, god, ryo and xah-fly-keys, etc.)
|
2019-01-17 23:42:33 +08:00
|
|
|
;;
|
|
|
|
|
2019-04-22 23:35:52 +08:00
|
|
|
(defsubst doom-modeline--evil ()
|
2019-01-17 23:42:33 +08:00
|
|
|
"The current evil state. Requires `evil-mode' to be enabled."
|
|
|
|
(when (bound-and-true-p evil-local-mode)
|
2019-11-06 00:26:26 +08:00
|
|
|
(propertize (concat
|
|
|
|
(doom-modeline-spc)
|
|
|
|
(doom-modeline-icon
|
|
|
|
'material
|
|
|
|
(when doom-modeline-evil-state-icon "fiber_manual_record")
|
|
|
|
"●"
|
|
|
|
(string-trim (evil-state-property evil-state :tag t))
|
2019-01-17 23:42:33 +08:00
|
|
|
(if (doom-modeline--active)
|
|
|
|
(cond ((evil-normal-state-p) 'doom-modeline-evil-normal-state)
|
|
|
|
((evil-emacs-state-p) 'doom-modeline-evil-emacs-state)
|
|
|
|
((evil-insert-state-p) 'doom-modeline-evil-insert-state)
|
|
|
|
((evil-motion-state-p) 'doom-modeline-evil-motion-state)
|
|
|
|
((evil-visual-state-p) 'doom-modeline-evil-visual-state)
|
|
|
|
((evil-operator-state-p) 'doom-modeline-evil-operator-state)
|
2019-11-06 00:26:26 +08:00
|
|
|
((evil-replace-state-p) 'doom-modeline-evil-replace-state)
|
|
|
|
(t 'mode-line))
|
|
|
|
'mode-line-inactive)
|
|
|
|
:v-adjust -0.225)
|
|
|
|
(doom-modeline-spc))
|
|
|
|
'help-echo (evil-state-property evil-state :name t))))
|
2019-01-17 23:42:33 +08:00
|
|
|
|
2019-05-19 04:01:56 +08:00
|
|
|
(defsubst doom-modeline--overwrite ()
|
|
|
|
"The current overwrite state. Requires `overwrite-mode' to be enabled."
|
2019-08-07 21:03:30 +08:00
|
|
|
(when (and (bound-and-true-p overwrite-mode)
|
|
|
|
(not (bound-and-true-p evil-local-mode)))
|
2019-11-06 00:56:45 +08:00
|
|
|
(propertize (concat
|
|
|
|
(doom-modeline-spc)
|
|
|
|
(doom-modeline-icon 'material "fiber_manual_record" "●" "<O>"
|
|
|
|
(if (doom-modeline--active)
|
|
|
|
'doom-modeline-urgent
|
|
|
|
'mode-line-inactive)
|
|
|
|
:v-adjust -0.225)
|
|
|
|
(doom-modeline-spc))
|
|
|
|
'help-echo "Overwrite state")))
|
2019-05-19 04:01:56 +08:00
|
|
|
|
2019-04-22 23:35:52 +08:00
|
|
|
(defsubst doom-modeline--god ()
|
2019-01-17 23:42:33 +08:00
|
|
|
"The current god state. Requires `god-mode' to be enabled."
|
|
|
|
(when (bound-and-true-p god-local-mode)
|
2019-11-06 00:56:45 +08:00
|
|
|
(propertize (concat
|
|
|
|
(doom-modeline-spc)
|
|
|
|
(doom-modeline-icon 'material "fiber_manual_record" "●" "<G>"
|
|
|
|
(if (doom-modeline--active)
|
|
|
|
'doom-modeline-evil-normal-state
|
|
|
|
'mode-line-inactive)
|
|
|
|
:v-adjust -0.225)
|
|
|
|
(doom-modeline-spc))
|
|
|
|
'help-echo "God mode")))
|
2019-01-17 23:42:33 +08:00
|
|
|
|
2019-04-22 23:35:52 +08:00
|
|
|
(defsubst doom-modeline--ryo ()
|
2019-01-17 23:42:33 +08:00
|
|
|
"The current ryo-modal state. Requires `ryo-modal-mode' to be enabled."
|
|
|
|
(when (bound-and-true-p ryo-modal-mode)
|
2019-11-06 00:56:45 +08:00
|
|
|
(propertize (concat
|
|
|
|
(doom-modeline-spc)
|
|
|
|
(doom-modeline-icon 'material "fiber_manual_record" "●" "<R>"
|
|
|
|
(if (doom-modeline--active)
|
|
|
|
'doom-modeline-evil-normal-state
|
|
|
|
'mode-line-inactive)
|
|
|
|
:v-adjust -0.225)
|
|
|
|
(doom-modeline-spc))
|
|
|
|
'help-echo "Ryo modal")))
|
2019-01-17 23:42:33 +08:00
|
|
|
|
2019-04-22 23:35:52 +08:00
|
|
|
(defsubst doom-modeline--xah-fly-keys ()
|
|
|
|
"The current `xah-fly-keys' state."
|
2019-01-17 23:42:33 +08:00
|
|
|
(when (boundp 'xah-fly-insert-state-q)
|
2019-05-19 04:01:56 +08:00
|
|
|
(let ((active (doom-modeline--active)))
|
|
|
|
(if xah-fly-insert-state-q
|
2019-11-06 00:56:45 +08:00
|
|
|
(propertize (concat
|
|
|
|
(doom-modeline-spc)
|
|
|
|
(doom-modeline-icon 'material "fiber_manual_record" "●" "<I>"
|
|
|
|
(if active
|
|
|
|
'doom-modeline-evil-insert-state
|
|
|
|
'mode-line-inactive)
|
|
|
|
:v-adjust -0.225)
|
|
|
|
(doom-modeline-spc))
|
|
|
|
'help-echo "Xah-fly insert state")
|
|
|
|
(propertize (concat
|
|
|
|
(doom-modeline-spc)
|
|
|
|
(doom-modeline-icon 'material "fiber_manual_record" "●" "<C>"
|
|
|
|
(if active
|
|
|
|
'doom-modeline-evil-normal-state
|
|
|
|
'mode-line-inactive)
|
|
|
|
:v-adjust -0.225)
|
|
|
|
(doom-modeline-spc))
|
|
|
|
'help-echo "Xah-fly normal state")))))
|
2019-01-17 23:42:33 +08:00
|
|
|
|
2019-04-22 23:35:52 +08:00
|
|
|
(doom-modeline-def-segment modals
|
2019-05-19 04:01:56 +08:00
|
|
|
"Displays modal editing states, including `evil', `overwrite', `god', `ryo' and `xha-fly-kyes', etc."
|
2019-04-22 23:35:52 +08:00
|
|
|
(concat (doom-modeline--evil)
|
2019-05-19 04:01:56 +08:00
|
|
|
(doom-modeline--overwrite)
|
2019-04-22 23:35:52 +08:00
|
|
|
(doom-modeline--god)
|
|
|
|
(doom-modeline--ryo)
|
|
|
|
(doom-modeline--xah-fly-keys)))
|
|
|
|
|
2019-04-22 23:36:57 +10:00
|
|
|
|
|
|
|
;;
|
|
|
|
;; objed-state
|
|
|
|
;;
|
|
|
|
|
|
|
|
(defvar doom-modeline--objed-active nil)
|
|
|
|
|
|
|
|
(defun doom-modeline-update-objed (_ &optional reset)
|
|
|
|
"Update `objed' status, inactive when RESET is true."
|
|
|
|
(setq doom-modeline--objed-active (not reset)))
|
|
|
|
|
|
|
|
(setq objed-modeline-setup-func #'doom-modeline-update-objed)
|
|
|
|
|
|
|
|
(doom-modeline-def-segment objed-state ()
|
|
|
|
"The current objed state."
|
|
|
|
(when (and doom-modeline--objed-active
|
|
|
|
(doom-modeline--active))
|
2019-11-06 00:26:26 +08:00
|
|
|
(propertize (format " %s(%s) "
|
2019-04-22 23:36:57 +10:00
|
|
|
(symbol-name objed--object)
|
2019-11-06 00:26:26 +08:00
|
|
|
(char-to-string (aref (symbol-name objed--obj-state) 0)))
|
|
|
|
'face 'doom-modeline-evil-emacs-state
|
|
|
|
'help-echo (format "Objed object: %s (%s)"
|
|
|
|
(symbol-name objed--object)
|
|
|
|
(symbol-name objed--obj-state)))))
|
2019-04-22 23:36:57 +10:00
|
|
|
|
|
|
|
|
2019-01-17 23:42:33 +08:00
|
|
|
;;
|
|
|
|
;; input method
|
|
|
|
;;
|
|
|
|
|
|
|
|
(doom-modeline-def-segment input-method
|
|
|
|
"The current input method."
|
2019-11-06 00:26:26 +08:00
|
|
|
(propertize (cond (current-input-method
|
|
|
|
(concat (doom-modeline-spc)
|
|
|
|
current-input-method-title
|
|
|
|
(doom-modeline-spc)))
|
|
|
|
((and (bound-and-true-p evil-local-mode)
|
|
|
|
(bound-and-true-p evil-input-method))
|
|
|
|
(concat
|
|
|
|
(doom-modeline-spc)
|
|
|
|
(nth 3 (assoc default-input-method input-method-alist))
|
|
|
|
(doom-modeline-spc)))
|
|
|
|
(t ""))
|
|
|
|
'face (if (doom-modeline--active)
|
|
|
|
'doom-modeline-buffer-major-mode
|
|
|
|
'mode-line-inactive)
|
|
|
|
'help-echo (concat
|
|
|
|
"Current input method: "
|
|
|
|
current-input-method
|
|
|
|
"\n\
|
2019-01-17 23:42:33 +08:00
|
|
|
mouse-2: Disable input method\n\
|
|
|
|
mouse-3: Describe current input method")
|
2019-11-06 00:26:26 +08:00
|
|
|
'mouse-face 'mode-line-highlight
|
|
|
|
'local-map mode-line-input-method-map))
|
2019-01-17 23:42:33 +08:00
|
|
|
|
|
|
|
|
2019-05-10 01:53:14 +08:00
|
|
|
;;
|
|
|
|
;; Info
|
|
|
|
;;
|
|
|
|
|
2019-05-12 01:14:48 +08:00
|
|
|
(doom-modeline-def-segment info-nodes
|
|
|
|
"The topic and nodes in the Info buffer."
|
2019-05-10 01:53:14 +08:00
|
|
|
(let ((active (doom-modeline--active)))
|
|
|
|
(concat
|
2019-06-27 03:48:10 +08:00
|
|
|
(propertize " (" 'face (if active 'mode-line 'mode-line-inactive))
|
2019-05-10 01:53:14 +08:00
|
|
|
;; topic
|
|
|
|
(propertize (if (stringp Info-current-file)
|
|
|
|
(replace-regexp-in-string
|
|
|
|
"%" "%%"
|
|
|
|
(file-name-sans-extension
|
|
|
|
(file-name-nondirectory Info-current-file)))
|
|
|
|
(format "*%S*" Info-current-file))
|
|
|
|
'face (if active 'doom-modeline-info 'mode-line-inactive))
|
2019-06-27 03:48:10 +08:00
|
|
|
(propertize ") " 'face (if active 'mode-line 'mode-line-inactive))
|
2019-05-10 01:53:14 +08:00
|
|
|
;; node
|
2019-06-27 03:48:10 +08:00
|
|
|
(when Info-current-node
|
|
|
|
(propertize (replace-regexp-in-string
|
|
|
|
"%" "%%" Info-current-node)
|
|
|
|
'face (if active 'doom-modeline-buffer-path 'mode-line-inactive)
|
|
|
|
'help-echo
|
|
|
|
"mouse-1: scroll forward, mouse-3: scroll back"
|
|
|
|
'mouse-face 'mode-line-highlight
|
|
|
|
'local-map Info-mode-line-node-keymap)))))
|
2019-05-10 01:53:14 +08:00
|
|
|
|
|
|
|
|
2019-01-17 23:42:33 +08:00
|
|
|
;;
|
|
|
|
;; LSP
|
|
|
|
;;
|
|
|
|
|
2019-05-06 21:52:36 +08:00
|
|
|
(defun doom-modeline-lsp-icon (text face)
|
|
|
|
"Display LSP icon (or TEXT in terminal) with FACE."
|
2019-10-23 02:50:04 +08:00
|
|
|
(doom-modeline-icon 'faicon "rocket" "🚀" text face :height 1.0 :v-adjust -0.0575))
|
2019-05-06 21:52:36 +08:00
|
|
|
|
2019-06-14 00:52:18 +08:00
|
|
|
(defvar-local doom-modeline--lsp nil)
|
2019-03-23 14:02:29 +08:00
|
|
|
(defun doom-modeline-update-lsp (&rest _)
|
2019-03-22 03:00:45 +08:00
|
|
|
"Update `lsp-mode' status."
|
|
|
|
(setq doom-modeline--lsp
|
2019-05-14 03:41:59 +08:00
|
|
|
(let* ((workspaces (lsp-workspaces))
|
2019-08-02 02:02:43 +08:00
|
|
|
(face (if workspaces 'doom-modeline-lsp-success 'doom-modeline-lsp-warning))
|
2019-05-14 03:41:59 +08:00
|
|
|
(icon (doom-modeline-lsp-icon "LSP" face)))
|
|
|
|
(propertize icon
|
2019-05-23 16:47:30 +08:00
|
|
|
'help-echo
|
|
|
|
(if workspaces
|
|
|
|
(concat "LSP Connected "
|
2019-06-29 01:21:32 +08:00
|
|
|
(string-join
|
|
|
|
(mapcar (lambda (w)
|
|
|
|
(format "[%s]\n" (lsp--workspace-print w)))
|
|
|
|
workspaces))
|
2019-05-23 16:47:30 +08:00
|
|
|
"C-mouse-1: Switch to another workspace folder
|
2019-03-12 17:50:18 +07:00
|
|
|
mouse-1: Describe current session
|
2019-03-12 00:51:37 +07:00
|
|
|
mouse-2: Quit server
|
|
|
|
mouse-3: Reconnect to server")
|
2019-05-23 16:47:30 +08:00
|
|
|
"LSP Disconnected
|
2019-03-22 22:40:08 +08:00
|
|
|
mouse-1: Reload to start server")
|
2019-11-07 17:44:47 +08:00
|
|
|
'mouse-face 'mode-line-highlight
|
2019-06-29 01:21:32 +08:00
|
|
|
'local-map (let ((map (make-sparse-keymap)))
|
|
|
|
(if workspaces
|
|
|
|
(progn
|
|
|
|
(define-key map [mode-line C-mouse-1]
|
|
|
|
#'lsp-workspace-folders-open)
|
|
|
|
(define-key map [mode-line mouse-1]
|
|
|
|
#'lsp-describe-session)
|
|
|
|
(define-key map [mode-line mouse-2]
|
|
|
|
#'lsp-workspace-shutdown)
|
|
|
|
(define-key map [mode-line mouse-3]
|
|
|
|
#'lsp-workspace-restart))
|
|
|
|
(progn
|
|
|
|
(define-key map [mode-line mouse-1]
|
|
|
|
(lambda ()
|
|
|
|
(interactive)
|
|
|
|
(ignore-errors (revert-buffer t t))))))
|
|
|
|
map)))))
|
|
|
|
(add-hook 'lsp-before-initialize-hook #'doom-modeline-update-lsp)
|
2019-06-14 16:27:26 +08:00
|
|
|
(add-hook 'lsp-after-initialize-hook #'doom-modeline-update-lsp)
|
2019-03-23 01:49:20 +08:00
|
|
|
(add-hook 'lsp-after-uninitialized-hook #'doom-modeline-update-lsp)
|
2019-06-29 01:21:32 +08:00
|
|
|
(add-hook 'lsp-before-open-hook #'doom-modeline-update-lsp)
|
2019-06-14 16:27:26 +08:00
|
|
|
(add-hook 'lsp-after-open-hook #'doom-modeline-update-lsp)
|
2019-03-22 03:00:45 +08:00
|
|
|
|
2019-06-14 00:52:18 +08:00
|
|
|
(defvar-local doom-modeline--eglot nil)
|
2019-03-22 03:00:45 +08:00
|
|
|
(defun doom-modeline-update-eglot ()
|
|
|
|
"Update `eglot' status."
|
|
|
|
(setq doom-modeline--eglot
|
Fix Eglot update hook breaking Eglot shutdown
doom-modeline is using various Eglot internals to display its Eglot
segment. One of those internals, eglot--current-server, recently changed
so that it now triggers a cache variable, eglot--cached-current-server,
to be set.
The hook used by doom-modeline is run during shutdown, after the buffer
becomes unmanaged by Eglot, but before all of its internal state has
been updated. The call to eglot--current-server then triggers the cache
variable to be set to an outdated value, which remains after shutdown
completes.
Any further calls to Eglot will end up seeing the incorrectly cached
value, which causes all kinds of breakage.
Note that, with or without this fix, the implementation relies on Eglot
internals and is likely to be fragile.
2019-11-09 21:24:40 +01:00
|
|
|
(when eglot--managed-mode
|
|
|
|
(pcase-let* ((server (eglot--current-server))
|
|
|
|
(nick (and server (eglot--project-nickname server)))
|
|
|
|
(pending (and server (hash-table-count
|
|
|
|
(jsonrpc--request-continuations server))))
|
|
|
|
(`(,_id ,doing ,done-p ,detail) (and server (eglot--spinner server)))
|
|
|
|
(last-error (and server (jsonrpc-last-error server)))
|
|
|
|
(face (cond (last-error 'doom-modeline-lsp-error)
|
|
|
|
((and doing (not done-p)) 'compilation-mode-line-run)
|
|
|
|
((and pending (cl-plusp pending)) 'doom-modeline-lsp-warning)
|
|
|
|
(nick 'doom-modeline-lsp-success)
|
|
|
|
(t 'mode-line)))
|
|
|
|
(icon (doom-modeline-lsp-icon "EGLOT" face)))
|
|
|
|
(propertize icon
|
|
|
|
'help-echo (cond
|
|
|
|
(last-error
|
|
|
|
(format "EGLOT\nAn error occured: %s
|
2019-03-12 00:01:47 +07:00
|
|
|
mouse-3: clear this status" (plist-get last-error :message)))
|
Fix Eglot update hook breaking Eglot shutdown
doom-modeline is using various Eglot internals to display its Eglot
segment. One of those internals, eglot--current-server, recently changed
so that it now triggers a cache variable, eglot--cached-current-server,
to be set.
The hook used by doom-modeline is run during shutdown, after the buffer
becomes unmanaged by Eglot, but before all of its internal state has
been updated. The call to eglot--current-server then triggers the cache
variable to be set to an outdated value, which remains after shutdown
completes.
Any further calls to Eglot will end up seeing the incorrectly cached
value, which causes all kinds of breakage.
Note that, with or without this fix, the implementation relies on Eglot
internals and is likely to be fragile.
2019-11-09 21:24:40 +01:00
|
|
|
((and doing (not done-p))
|
|
|
|
(format "EGLOT\n%s%s" doing
|
|
|
|
(if detail (format "%s" detail) "")))
|
|
|
|
((and pending (cl-plusp pending))
|
|
|
|
(format "EGLOT\n%d outstanding requests" pending))
|
|
|
|
(nick (format "EGLOT Connected (%s/%s)
|
2019-03-12 00:01:47 +07:00
|
|
|
C-mouse-1: Disply server errors
|
|
|
|
mouse-1: Display server events
|
|
|
|
mouse-2: Quit server
|
|
|
|
mouse-3: Reconnect to server" nick (eglot--major-mode server)))
|
Fix Eglot update hook breaking Eglot shutdown
doom-modeline is using various Eglot internals to display its Eglot
segment. One of those internals, eglot--current-server, recently changed
so that it now triggers a cache variable, eglot--cached-current-server,
to be set.
The hook used by doom-modeline is run during shutdown, after the buffer
becomes unmanaged by Eglot, but before all of its internal state has
been updated. The call to eglot--current-server then triggers the cache
variable to be set to an outdated value, which remains after shutdown
completes.
Any further calls to Eglot will end up seeing the incorrectly cached
value, which causes all kinds of breakage.
Note that, with or without this fix, the implementation relies on Eglot
internals and is likely to be fragile.
2019-11-09 21:24:40 +01:00
|
|
|
(t "EGLOT Disconnected"))
|
|
|
|
'mouse-face 'mode-line-highlight
|
|
|
|
'local-map (let ((map (make-sparse-keymap)))
|
|
|
|
(cond (last-error
|
|
|
|
(define-key map [mode-line mouse-3]
|
|
|
|
#'eglot-clear-status))
|
|
|
|
((and pending (cl-plusp pending))
|
|
|
|
(define-key map [mode-line mouse-3]
|
|
|
|
#'eglot-forget-pending-continuations))
|
|
|
|
(nick
|
|
|
|
(define-key map [mode-line C-mouse-1]
|
|
|
|
#'eglot-stderr-buffer)
|
|
|
|
(define-key map [mode-line mouse-1]
|
|
|
|
#'eglot-events-buffer)
|
|
|
|
(define-key map [mode-line mouse-2]
|
|
|
|
#'eglot-shutdown)
|
|
|
|
(define-key map [mode-line mouse-3]
|
|
|
|
#'eglot-reconnect)))
|
|
|
|
map))))))
|
2019-03-22 03:00:45 +08:00
|
|
|
(add-hook 'eglot--managed-mode-hook #'doom-modeline-update-eglot)
|
|
|
|
|
|
|
|
(doom-modeline-def-segment lsp
|
|
|
|
"The LSP server state."
|
2019-05-06 22:55:49 +08:00
|
|
|
(when doom-modeline-lsp
|
2019-05-18 23:53:47 +08:00
|
|
|
(let ((active (doom-modeline--active))
|
|
|
|
(icon (cond ((bound-and-true-p lsp-mode)
|
|
|
|
doom-modeline--lsp)
|
|
|
|
((bound-and-true-p eglot--managed-mode)
|
|
|
|
doom-modeline--eglot))))
|
2019-05-19 23:04:34 +08:00
|
|
|
(when icon
|
|
|
|
(concat
|
2019-05-22 15:15:48 +08:00
|
|
|
(doom-modeline-spc)
|
2019-05-18 23:53:47 +08:00
|
|
|
(if active
|
|
|
|
icon
|
2019-06-27 17:41:29 +08:00
|
|
|
(propertize icon 'face `(:inherit ,(get-text-property 0 'face icon)
|
|
|
|
:inherit mode-line-inactive)))
|
2019-05-22 15:15:48 +08:00
|
|
|
(doom-modeline-spc))))))
|
2019-03-12 00:01:47 +07:00
|
|
|
|
|
|
|
(defun doom-modeline-override-eglot-modeline ()
|
|
|
|
"Override `eglot' mode-line."
|
|
|
|
(if (bound-and-true-p doom-modeline-mode)
|
|
|
|
(setq mode-line-misc-info
|
|
|
|
(delq (assq 'eglot--managed-mode mode-line-misc-info) mode-line-misc-info))
|
|
|
|
(add-to-list 'mode-line-misc-info
|
|
|
|
`(eglot--managed-mode (" [" eglot--mode-line-format "] ")))))
|
|
|
|
(with-eval-after-load 'eglot
|
|
|
|
(doom-modeline-override-eglot-modeline))
|
|
|
|
(add-hook 'doom-modeline-mode-hook #'doom-modeline-override-eglot-modeline)
|
2019-01-17 23:42:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
;; github
|
|
|
|
;;
|
|
|
|
|
2019-10-25 01:58:28 +08:00
|
|
|
(defvar doom-modeline--github-notification-counts 0)
|
2019-01-17 23:42:33 +08:00
|
|
|
(defvar doom-modeline-before-github-fetch-notification-hook nil
|
2019-08-18 03:56:39 +08:00
|
|
|
"Hooks before fetching GitHub notifications.
|
2019-01-17 23:42:33 +08:00
|
|
|
Example:
|
|
|
|
(add-hook 'doom-modeline-before-github-fetch-notification-hook #'auth-source-pass-enable)")
|
|
|
|
(defun doom-modeline--github-fetch-notifications ()
|
2019-08-18 03:56:39 +08:00
|
|
|
"Fetch GitHub notifications."
|
2019-01-17 23:42:33 +08:00
|
|
|
(when (and doom-modeline-github
|
2019-10-13 20:48:14 +08:00
|
|
|
(require 'async nil t))
|
2019-01-17 23:42:33 +08:00
|
|
|
(async-start
|
|
|
|
`(lambda ()
|
|
|
|
,(async-inject-variables "\\`\\(load-path\\|auth-sources\\|doom-modeline-before-github-fetch-notification-hook\\)\\'")
|
|
|
|
(run-hooks 'doom-modeline-before-github-fetch-notification-hook)
|
2019-10-13 20:48:14 +08:00
|
|
|
(when (require 'ghub nil t)
|
2019-01-17 23:42:33 +08:00
|
|
|
(with-timeout (10)
|
|
|
|
(ignore-errors
|
|
|
|
(if (ghub--token ghub-default-host
|
|
|
|
(ghub--username ghub-default-host)
|
|
|
|
'ghub
|
|
|
|
t)
|
|
|
|
(ghub-get "/notifications"
|
|
|
|
nil
|
|
|
|
:query '((notifications . "true"))
|
|
|
|
:noerror t))))))
|
|
|
|
(lambda (result)
|
2019-02-14 20:26:48 +08:00
|
|
|
(message "") ; suppress message
|
2019-10-25 01:58:28 +08:00
|
|
|
(setq doom-modeline--github-notification-counts
|
2019-01-17 23:42:33 +08:00
|
|
|
(length result))))))
|
|
|
|
|
|
|
|
(defvar doom-modeline--github-timer nil)
|
|
|
|
(defun doom-modeline-github-timer ()
|
2019-08-18 03:56:39 +08:00
|
|
|
"Start/Stop the timer for GitHub fetching."
|
2019-01-17 23:42:33 +08:00
|
|
|
(if (timerp doom-modeline--github-timer)
|
|
|
|
(cancel-timer doom-modeline--github-timer))
|
|
|
|
(setq doom-modeline--github-timer
|
|
|
|
(and doom-modeline-github
|
|
|
|
(run-with-timer 30
|
|
|
|
doom-modeline-github-interval
|
|
|
|
#'doom-modeline--github-fetch-notifications))))
|
|
|
|
|
|
|
|
(when (>= emacs-major-version 26)
|
|
|
|
(add-variable-watcher
|
|
|
|
'doom-modeline-github
|
|
|
|
(lambda (_sym val op _where)
|
|
|
|
(when (eq op 'set)
|
|
|
|
(setq doom-modeline-github val)
|
|
|
|
(doom-modeline-github-timer)))))
|
|
|
|
|
|
|
|
(doom-modeline-github-timer)
|
|
|
|
|
|
|
|
(doom-modeline-def-segment github
|
2019-08-18 03:56:39 +08:00
|
|
|
"The GitHub notifications."
|
2019-01-17 23:42:33 +08:00
|
|
|
(if (and doom-modeline-github
|
|
|
|
(doom-modeline--active)
|
2019-10-25 01:58:28 +08:00
|
|
|
(> doom-modeline--github-notification-counts 0))
|
2019-02-28 14:06:54 +07:00
|
|
|
(concat
|
2019-05-22 15:15:48 +08:00
|
|
|
(doom-modeline-spc)
|
2019-02-28 14:06:54 +07:00
|
|
|
(propertize
|
|
|
|
(concat
|
2019-10-23 02:50:04 +08:00
|
|
|
(doom-modeline-icon 'faicon "github" "⌗" "#" 'doom-modeline-warning :v-adjust -0.0575)
|
|
|
|
(doom-modeline-vspc)
|
2019-10-25 01:58:28 +08:00
|
|
|
(propertize
|
|
|
|
(if (> doom-modeline--github-notification-counts doom-modeline-number-limit)
|
|
|
|
(format "%d+" doom-modeline-number-limit)
|
|
|
|
(number-to-string doom-modeline--github-notification-counts))
|
|
|
|
'face '(:inherit (doom-modeline-warning doom-modeline-unread-number))))
|
2019-02-28 14:06:54 +07:00
|
|
|
'help-echo "Github Notifications
|
2019-01-17 23:42:33 +08:00
|
|
|
mouse-1: Show notifications
|
|
|
|
mouse-3: Fetch notifications"
|
2019-11-07 17:44:47 +08:00
|
|
|
'mouse-face 'mode-line-highlight
|
2019-02-28 14:06:54 +07:00
|
|
|
'local-map (let ((map (make-sparse-keymap)))
|
|
|
|
(define-key map [mode-line mouse-1]
|
|
|
|
(lambda ()
|
2019-08-18 03:56:39 +08:00
|
|
|
"Open GitHub notifications page."
|
2019-02-28 14:06:54 +07:00
|
|
|
(interactive)
|
2019-03-22 02:27:01 +08:00
|
|
|
(run-with-timer 300 nil #'doom-modeline--github-fetch-notifications)
|
2019-03-07 04:04:03 +07:00
|
|
|
(browse-url "https://github.com/notifications")))
|
2019-02-28 14:06:54 +07:00
|
|
|
(define-key map [mode-line mouse-3]
|
|
|
|
(lambda ()
|
2019-08-18 03:56:39 +08:00
|
|
|
"Fetching GitHub notifications."
|
2019-02-28 14:06:54 +07:00
|
|
|
(interactive)
|
2019-08-18 03:56:39 +08:00
|
|
|
(message "Fetching GitHub notifications...")
|
2019-02-28 14:06:54 +07:00
|
|
|
(doom-modeline--github-fetch-notifications)))
|
|
|
|
map))
|
2019-05-22 15:15:48 +08:00
|
|
|
(doom-modeline-spc))))
|
2019-01-17 23:42:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
;; debug state
|
|
|
|
;;
|
|
|
|
|
2019-10-23 02:50:04 +08:00
|
|
|
(defun doom-modeline-debug-icon (face &rest args)
|
|
|
|
"Display debug icon with FACE and ARGS."
|
|
|
|
(doom-modeline-icon 'faicon "bug" "🐛" "!" face :v-adjust -0.0575 args))
|
2019-03-16 02:43:21 +07:00
|
|
|
|
2019-06-24 14:13:08 +08:00
|
|
|
(defsubst doom-modeline--debug-dap ()
|
|
|
|
"The current `dap-mode' state."
|
|
|
|
(when (and (bound-and-true-p dap-mode)
|
|
|
|
(bound-and-true-p lsp-mode)
|
2019-07-13 01:52:22 +08:00
|
|
|
(dap--session-running (dap--cur-session)))
|
2019-06-24 14:13:08 +08:00
|
|
|
(propertize (doom-modeline-debug-icon 'doom-modeline-warning)
|
|
|
|
'help-echo (format "DAP (%s)
|
2019-03-16 23:43:22 +07:00
|
|
|
mouse-1: Display debug hydra
|
2019-03-17 00:00:32 +07:00
|
|
|
mouse-2: Display recent configurations
|
|
|
|
mouse-3: Disconnect session"
|
2019-06-24 14:13:08 +08:00
|
|
|
(dap-mode-line))
|
2019-11-07 17:44:47 +08:00
|
|
|
'mouse-face 'mode-line-highlight
|
2019-06-24 14:13:08 +08:00
|
|
|
'local-map (let ((map (make-sparse-keymap)))
|
|
|
|
(define-key map [mode-line mouse-1]
|
|
|
|
#'dap-hydra)
|
|
|
|
(define-key map [mode-line mouse-2]
|
|
|
|
#'dap-debug-recent)
|
|
|
|
(define-key map [mode-line mouse-3]
|
|
|
|
#'dap-disconnect)
|
|
|
|
map))))
|
|
|
|
|
|
|
|
(defsubst doom-modeline--debug-edebug ()
|
|
|
|
"The current `edebug' state."
|
|
|
|
(when (or (bound-and-true-p edebug-mode)
|
|
|
|
(bound-and-true-p edebug-x-mode))
|
|
|
|
(propertize (doom-modeline-debug-icon 'doom-modeline-warning)
|
|
|
|
'help-echo (format "EDebug (%s)
|
2019-03-16 02:43:21 +07:00
|
|
|
mouse-1: Show help
|
|
|
|
mouse-2: Next
|
|
|
|
mouse-3: Stop debugging"
|
2019-06-24 14:13:08 +08:00
|
|
|
edebug-execution-mode)
|
2019-11-07 17:44:47 +08:00
|
|
|
'mouse-face 'mode-line-highlight
|
2019-06-24 14:13:08 +08:00
|
|
|
'local-map (let ((map (make-sparse-keymap)))
|
|
|
|
(define-key map [mode-line mouse-1]
|
|
|
|
#'edebug-help)
|
|
|
|
(define-key map [mode-line mouse-2]
|
|
|
|
#'edebug-next-mode)
|
|
|
|
(define-key map [mode-line mouse-3]
|
|
|
|
#'edebug-stop)
|
|
|
|
map))))
|
|
|
|
|
|
|
|
(defsubst doom-modeline--debug-on-error ()
|
|
|
|
"The current `debug-on-error' state."
|
|
|
|
(when debug-on-error
|
|
|
|
(propertize (doom-modeline-debug-icon 'doom-modeline-urgent)
|
|
|
|
'help-echo "Debug on Error
|
2019-03-16 02:43:21 +07:00
|
|
|
mouse-1: Toggle Debug on Error"
|
2019-11-07 17:44:47 +08:00
|
|
|
'mouse-face 'mode-line-highlight
|
2019-06-24 14:13:08 +08:00
|
|
|
'local-map (make-mode-line-mouse-map 'mouse-1 #'toggle-debug-on-error))))
|
|
|
|
|
|
|
|
(defsubst doom-modeline--debug-on-quit ()
|
|
|
|
"The current `debug-on-quit' state."
|
|
|
|
(when debug-on-quit
|
2019-10-29 02:38:40 +08:00
|
|
|
(propertize (doom-modeline-debug-icon 'doom-modeline-info)
|
2019-06-24 14:13:08 +08:00
|
|
|
'help-echo "Debug on Quit
|
2019-01-17 23:42:33 +08:00
|
|
|
mouse-1: Toggle Debug on Quit"
|
2019-11-07 17:44:47 +08:00
|
|
|
'mouse-face 'mode-line-highlight
|
2019-06-24 14:13:08 +08:00
|
|
|
'local-map (make-mode-line-mouse-map 'mouse-1 #'toggle-debug-on-quit))))
|
|
|
|
|
|
|
|
(doom-modeline-def-segment debug
|
|
|
|
"The current debug state."
|
|
|
|
(when (doom-modeline--active)
|
|
|
|
(let* ((dap (doom-modeline--debug-dap))
|
|
|
|
(edebug (doom-modeline--debug-edebug))
|
|
|
|
(on-error (doom-modeline--debug-on-error))
|
|
|
|
(on-quit (doom-modeline--debug-on-quit))
|
2019-06-24 14:22:07 +08:00
|
|
|
(sep (doom-modeline-vspc))
|
|
|
|
(seg-sep (and (or dap edebug on-error on-quit) (doom-modeline-spc))))
|
|
|
|
(concat seg-sep
|
|
|
|
(and dap (concat dap sep))
|
|
|
|
(and edebug (concat edebug sep))
|
|
|
|
(and on-error (concat on-error sep))
|
2019-06-24 14:17:12 +08:00
|
|
|
on-quit
|
2019-06-24 14:22:07 +08:00
|
|
|
seg-sep))))
|
2019-01-17 23:42:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
;; pdf pages
|
|
|
|
;;
|
|
|
|
|
2019-03-22 02:19:25 +08:00
|
|
|
(defvar-local doom-modeline--pdf-pages nil)
|
|
|
|
(defun doom-modeline-update-pdf-pages ()
|
2019-03-22 03:00:45 +08:00
|
|
|
"Update PDF pages."
|
2019-03-22 02:19:25 +08:00
|
|
|
(setq doom-modeline--pdf-pages
|
|
|
|
(propertize
|
|
|
|
(format " P%d/%d "
|
|
|
|
(eval `(pdf-view-current-page))
|
|
|
|
(pdf-cache-number-of-pages))
|
2019-05-12 01:02:05 +08:00
|
|
|
'face (if (doom-modeline--active) 'mode-line 'mode-line-inactive))))
|
2019-03-22 02:19:25 +08:00
|
|
|
(add-hook 'pdf-view-change-page-hook #'doom-modeline-update-pdf-pages)
|
|
|
|
|
2019-01-17 23:42:33 +08:00
|
|
|
(doom-modeline-def-segment pdf-pages
|
2019-05-06 02:06:03 +08:00
|
|
|
"Display PDF pages."
|
2019-05-12 01:02:05 +08:00
|
|
|
doom-modeline--pdf-pages)
|
2019-01-17 23:42:33 +08:00
|
|
|
|
2019-01-28 23:57:41 -08:00
|
|
|
|
|
|
|
;;
|
|
|
|
;; mu4e-alert notifications
|
|
|
|
;;
|
|
|
|
|
|
|
|
(doom-modeline-def-segment mu4e
|
2019-05-06 02:06:03 +08:00
|
|
|
"Show notifications of any unread emails in `mu4e'."
|
2019-01-28 23:57:41 -08:00
|
|
|
(when (and doom-modeline-mu4e
|
|
|
|
(doom-modeline--active)
|
2019-10-25 01:58:28 +08:00
|
|
|
(bound-and-true-p mu4e-alert-mode-line)
|
|
|
|
(numberp mu4e-alert-mode-line)
|
|
|
|
;; don't display if the unread mails count is zero
|
|
|
|
(> mu4e-alert-mode-line 0))
|
|
|
|
(concat
|
|
|
|
(doom-modeline-spc)
|
|
|
|
(propertize
|
|
|
|
(concat
|
|
|
|
(doom-modeline-icon 'material "email" "📧" "#" 'doom-modeline-warning
|
|
|
|
:height 1.1 :v-adjust -0.225)
|
|
|
|
(doom-modeline-vspc)
|
|
|
|
(propertize
|
|
|
|
(if (> mu4e-alert-mode-line doom-modeline-number-limit)
|
|
|
|
(format "%d+" doom-modeline-number-limit)
|
|
|
|
(number-to-string mu4e-alert-mode-line))
|
|
|
|
'face '(:inherit (doom-modeline-warning doom-modeline-unread-number))))
|
2019-11-07 17:44:47 +08:00
|
|
|
'mouse-face 'mode-line-highlight
|
2019-10-25 01:58:28 +08:00
|
|
|
'help-echo (if (= mu4e-alert-mode-line 1)
|
|
|
|
"You have an unread email"
|
|
|
|
(format "You have %s unread emails" mu4e-alert-mode-line)))
|
|
|
|
(doom-modeline-spc))))
|
2019-01-28 23:57:41 -08:00
|
|
|
|
2019-03-01 16:17:02 +07:00
|
|
|
(defun doom-modeline-override-mu4e-alert-modeline (&rest _)
|
|
|
|
"Delete `mu4e-alert-mode-line' from global modeline string."
|
2019-03-01 23:35:37 +07:00
|
|
|
(when (featurep 'mu4e-alert)
|
|
|
|
(if (and doom-modeline-mu4e
|
|
|
|
(bound-and-true-p doom-modeline-mode))
|
2019-03-04 14:15:52 +07:00
|
|
|
;; Delete original modeline
|
2019-03-01 23:35:37 +07:00
|
|
|
(progn
|
|
|
|
(setq global-mode-string
|
2019-03-04 14:15:52 +07:00
|
|
|
(delete '(:eval mu4e-alert-mode-line) global-mode-string))
|
|
|
|
(setq mu4e-alert-modeline-formatter #'identity))
|
2019-03-01 23:35:37 +07:00
|
|
|
;; Recover default settings
|
|
|
|
(setq mu4e-alert-modeline-formatter #'mu4e-alert-default-mode-line-formatter))))
|
2019-10-25 01:58:28 +08:00
|
|
|
(advice-add #'mu4e-alert-enable-mode-line-display
|
|
|
|
:after #'doom-modeline-override-mu4e-alert-modeline)
|
2019-03-04 14:15:52 +07:00
|
|
|
(add-hook 'doom-modeline-mode-hook #'doom-modeline-override-mu4e-alert-modeline)
|
2019-03-01 16:17:02 +07:00
|
|
|
|
2019-02-01 15:55:14 -08:00
|
|
|
|
|
|
|
;;
|
|
|
|
;; irc notifications
|
|
|
|
;;
|
|
|
|
|
|
|
|
(defun doom-modeline--shorten-irc (name)
|
|
|
|
"Wrapper for `tracking-shorten' that only takes one NAME.
|
|
|
|
|
|
|
|
One key difference is that when `tracking-shorten' returns nil we
|
|
|
|
will instead return the original value of name. This is necessary
|
|
|
|
in cases where the user has stylized the name to be an icon and
|
|
|
|
we don't want to remove that so we just return the original."
|
|
|
|
(or (car (tracking-shorten (list name)))
|
|
|
|
name))
|
|
|
|
|
|
|
|
(defun doom-modeline--tracking-buffers (buffers)
|
|
|
|
"Logic to convert some irc BUFFERS to their font-awesome icon."
|
|
|
|
(mapconcat
|
|
|
|
(lambda (b)
|
|
|
|
(propertize
|
|
|
|
(doom-modeline--shorten-irc (funcall doom-modeline-irc-stylize b))
|
|
|
|
'face '(:inherit (warning doom-modeline-unread-number))
|
|
|
|
'help-echo b))
|
|
|
|
buffers
|
|
|
|
;; `space-width' only affects the width of the spaces here, so we can tighten
|
|
|
|
;; it to be a bit more compact
|
|
|
|
(propertize " · " 'display '(space-width 0.4))))
|
|
|
|
|
|
|
|
;; create a modeline segment that contains all the irc tracked buffers
|
|
|
|
(doom-modeline-def-segment irc-buffers
|
|
|
|
"The list of shortened, unread irc buffers."
|
|
|
|
(when (and doom-modeline-irc
|
|
|
|
(doom-modeline--active)
|
2019-02-28 15:34:57 +07:00
|
|
|
(boundp 'tracking-mode-line-buffers)
|
2019-02-01 15:55:14 -08:00
|
|
|
(derived-mode-p 'circe-mode))
|
|
|
|
;; add a space at the end to pad against the following segment
|
2019-05-22 15:15:48 +08:00
|
|
|
(concat (doom-modeline-spc)
|
2019-05-14 15:31:14 +03:00
|
|
|
(doom-modeline--tracking-buffers tracking-buffers)
|
2019-05-22 15:15:48 +08:00
|
|
|
(doom-modeline-spc))))
|
2019-02-01 15:55:14 -08:00
|
|
|
|
2019-02-03 23:06:51 -08:00
|
|
|
(doom-modeline-def-segment irc
|
|
|
|
"A notification icon for any unread irc buffer."
|
|
|
|
(when (and doom-modeline-irc
|
2019-02-28 14:00:27 +07:00
|
|
|
(doom-modeline--active)
|
2019-02-03 23:06:51 -08:00
|
|
|
(boundp 'tracking-mode-line-buffers)
|
2019-02-28 14:00:27 +07:00
|
|
|
(> (length tracking-buffers) 0))
|
2019-02-03 23:06:51 -08:00
|
|
|
(concat
|
2019-05-22 15:15:48 +08:00
|
|
|
(doom-modeline-spc)
|
2019-10-23 02:50:04 +08:00
|
|
|
(propertize (doom-modeline-icon 'material "message" "🗊" "#"
|
|
|
|
'doom-modeline-warning
|
|
|
|
:height 1.1 :v-adjust -0.225)
|
2019-02-03 23:06:51 -08:00
|
|
|
'help-echo (format "IRC Notifications: %s"
|
|
|
|
(doom-modeline--tracking-buffers
|
2019-02-28 15:34:57 +07:00
|
|
|
tracking-buffers)))
|
2019-05-22 15:15:48 +08:00
|
|
|
(doom-modeline-spc))))
|
2019-02-03 23:06:51 -08:00
|
|
|
|
2019-02-28 23:58:47 +07:00
|
|
|
|
|
|
|
;;
|
2019-10-25 01:09:30 +08:00
|
|
|
;; battery status
|
2019-02-28 23:58:47 +07:00
|
|
|
;;
|
|
|
|
|
2019-03-22 01:50:29 +08:00
|
|
|
(defvar-local doom-modeline--battery-status nil)
|
2019-10-25 01:09:30 +08:00
|
|
|
(defun doom-modeline-update-battery-status ()
|
|
|
|
"Update battery status."
|
2019-03-22 01:50:29 +08:00
|
|
|
(setq doom-modeline--battery-status
|
2019-10-25 05:54:42 +08:00
|
|
|
(when (bound-and-true-p display-battery-mode)
|
|
|
|
(let* ((data (and (bound-and-true-p battery-status-function)
|
|
|
|
(funcall battery-status-function)))
|
|
|
|
(charging? (string-equal "AC" (cdr (assoc ?L data))))
|
|
|
|
(percentage (min (car (read-from-string (cdr (assq ?p data))))
|
|
|
|
battery-mode-line-limit))
|
|
|
|
(face (when (numberp percentage)
|
|
|
|
(cond (charging? 'success)
|
|
|
|
((< percentage battery-load-critical) 'error)
|
|
|
|
((< percentage 25) 'warning)
|
|
|
|
((< percentage 95) 'mode-line)
|
|
|
|
(t 'success))))
|
|
|
|
(icon (if (numberp percentage)
|
|
|
|
(cond (charging?
|
|
|
|
(doom-modeline-icon 'alltheicon
|
|
|
|
"battery-charging"
|
|
|
|
"🔋"
|
|
|
|
"+"
|
|
|
|
face
|
|
|
|
:height 1.4
|
|
|
|
:v-adjust -0.1))
|
|
|
|
((> percentage 95)
|
|
|
|
(doom-modeline-icon 'faicon
|
|
|
|
"battery-full"
|
|
|
|
"🔋"
|
|
|
|
"-"
|
|
|
|
face
|
|
|
|
:v-adjust -0.0575))
|
|
|
|
((> percentage 70)
|
|
|
|
(doom-modeline-icon 'faicon
|
|
|
|
"battery-three-quarters"
|
|
|
|
"🔋"
|
|
|
|
"-"
|
|
|
|
face
|
|
|
|
:v-adjust -0.0575))
|
|
|
|
((> percentage 40)
|
|
|
|
(doom-modeline-icon 'faicon
|
|
|
|
"battery-half"
|
|
|
|
"🔋"
|
|
|
|
"-"
|
|
|
|
face
|
|
|
|
:v-adjust -0.0575))
|
|
|
|
((> percentage battery-load-critical)
|
|
|
|
(doom-modeline-icon 'faicon
|
|
|
|
"battery-quarter"
|
2019-10-25 01:09:30 +08:00
|
|
|
"🔋"
|
2019-10-25 05:54:42 +08:00
|
|
|
"-"
|
2019-10-25 01:09:30 +08:00
|
|
|
face
|
2019-10-25 05:54:42 +08:00
|
|
|
:v-adjust -0.0575))
|
|
|
|
(t (doom-modeline-icon 'faicon
|
|
|
|
"battery-empty"
|
|
|
|
"🔋"
|
|
|
|
"!"
|
|
|
|
face
|
|
|
|
:v-adjust -0.0575)))
|
|
|
|
(doom-modeline-icon 'faicon
|
|
|
|
"battery-empty"
|
|
|
|
"⚠"
|
|
|
|
"N/A"
|
|
|
|
'error
|
|
|
|
:v-adjust -0.0575)))
|
|
|
|
(text (if (numberp percentage)
|
|
|
|
(format "%d%%%%" percentage)
|
|
|
|
""))
|
|
|
|
(help-echo (if (and battery-echo-area-format (numberp percentage))
|
|
|
|
(battery-format battery-echo-area-format data)
|
|
|
|
"Battery status not available")))
|
|
|
|
(concat (doom-modeline-spc)
|
|
|
|
(propertize (concat icon
|
|
|
|
(doom-modeline-vspc)
|
|
|
|
(propertize text 'face face))
|
|
|
|
'help-echo help-echo)
|
|
|
|
(doom-modeline-spc))))))
|
2019-03-22 01:50:29 +08:00
|
|
|
|
2019-10-23 02:50:04 +08:00
|
|
|
(when (>= emacs-major-version 26)
|
|
|
|
(add-variable-watcher
|
|
|
|
'doom-modeline-icon
|
|
|
|
(lambda (_sym val op _where)
|
|
|
|
(when (eq op 'set)
|
|
|
|
(setq doom-modeline-icon val)
|
|
|
|
(dolist (buf (buffer-list))
|
|
|
|
(with-current-buffer buf
|
|
|
|
(doom-modeline-update-battery-status))))))
|
|
|
|
|
|
|
|
(add-variable-watcher
|
|
|
|
'doom-modeline-unicode-fallback
|
|
|
|
(lambda (_sym val op _where)
|
|
|
|
(when (eq op 'set)
|
|
|
|
(setq doom-modeline-unicode-fallback val)
|
|
|
|
(dolist (buf (buffer-list))
|
|
|
|
(with-current-buffer buf
|
|
|
|
(doom-modeline-update-battery-status)))))))
|
|
|
|
|
2019-10-25 01:09:30 +08:00
|
|
|
(doom-modeline-def-segment battery
|
2019-05-06 02:06:03 +08:00
|
|
|
"Display battery status."
|
2019-02-28 23:58:47 +07:00
|
|
|
(when (and (doom-modeline--active)
|
2019-10-25 01:09:30 +08:00
|
|
|
(bound-and-true-p display-battery-mode))
|
2019-03-22 01:50:29 +08:00
|
|
|
(or doom-modeline--battery-status (doom-modeline-update-battery-status))))
|
2019-03-01 16:17:02 +07:00
|
|
|
|
2019-10-25 01:09:30 +08:00
|
|
|
(defun doom-modeline-override-battery-modeline ()
|
|
|
|
"Override default battery mode-line."
|
2019-03-01 16:17:02 +07:00
|
|
|
(if (bound-and-true-p doom-modeline-mode)
|
2019-10-25 01:09:30 +08:00
|
|
|
(progn
|
|
|
|
(advice-add #'battery-update :override #'doom-modeline-update-battery-status)
|
|
|
|
(setq global-mode-string
|
|
|
|
(delq 'battery-mode-line-string global-mode-string)))
|
|
|
|
(progn
|
|
|
|
(advice-remove #'battery-update #'doom-modeline-update-battery-status)
|
|
|
|
(when display-battery-mode (display-battery-mode 1)))))
|
|
|
|
(add-hook 'display-battery-mode-hook #'doom-modeline-override-battery-modeline)
|
|
|
|
(add-hook 'doom-modeline-mode-hook #'doom-modeline-override-battery-modeline)
|
2019-02-28 23:58:47 +07:00
|
|
|
|
2019-05-06 17:43:15 +08:00
|
|
|
|
|
|
|
;;
|
|
|
|
;; package information
|
|
|
|
;;
|
|
|
|
|
2019-05-06 02:06:03 +08:00
|
|
|
(doom-modeline-def-segment package
|
|
|
|
"Show package information via `paradox'."
|
2019-05-06 17:43:15 +08:00
|
|
|
(let ((active (doom-modeline--active)))
|
2019-05-06 02:06:03 +08:00
|
|
|
(concat
|
2019-05-06 17:43:15 +08:00
|
|
|
(let ((front (format-mode-line 'mode-line-front-space)))
|
|
|
|
(if active
|
|
|
|
front
|
2019-05-15 07:34:52 +09:00
|
|
|
(propertize front 'face 'mode-line-inactive)))
|
2019-05-06 02:06:03 +08:00
|
|
|
|
2019-10-26 00:06:10 +08:00
|
|
|
(when (and doom-modeline-icon doom-modeline-major-mode-icon)
|
2019-05-22 15:15:48 +08:00
|
|
|
(concat (doom-modeline-spc)
|
2019-10-24 20:19:39 +08:00
|
|
|
(doom-modeline-icon-for-mode 'paradox-menu-mode
|
|
|
|
:v-adjust -0.15
|
|
|
|
:face (if active
|
2019-10-26 00:06:10 +08:00
|
|
|
(if doom-modeline-major-mode-color-icon
|
2019-10-25 05:54:42 +08:00
|
|
|
'all-the-icons-silver
|
|
|
|
'mode-line)
|
2019-10-24 20:19:39 +08:00
|
|
|
'mode-line-inactive))))
|
2019-05-06 17:43:15 +08:00
|
|
|
(let ((info (format-mode-line 'mode-line-buffer-identification)))
|
|
|
|
(if active
|
|
|
|
info
|
|
|
|
(propertize info 'face 'mode-line-inactive))))))
|
2019-05-06 02:06:03 +08:00
|
|
|
|
2019-05-10 03:17:15 +08:00
|
|
|
|
|
|
|
;;
|
|
|
|
;; Helm
|
|
|
|
;;
|
|
|
|
|
|
|
|
(defvar doom-modeline--helm-buffer-ids
|
|
|
|
'(("*helm*" . "HELM")
|
|
|
|
("*helm M-x*" . "HELM M-x")
|
|
|
|
("*swiper*" . "SWIPER")
|
|
|
|
("*Projectile Perspectives*" . "HELM Projectile Perspectives")
|
|
|
|
("*Projectile Layouts*" . "HELM Projectile Layouts")
|
|
|
|
("*helm-ag*" . (lambda ()
|
|
|
|
(format "HELM Ag: Using %s"
|
|
|
|
(car (split-string helm-ag-base-command))))))
|
|
|
|
"Alist of custom helm buffer names to use.
|
|
|
|
The cdr can also be a function that returns a name to use.")
|
2019-10-24 20:19:39 +08:00
|
|
|
|
2019-05-10 03:17:15 +08:00
|
|
|
(doom-modeline-def-segment helm-buffer-id
|
|
|
|
"Helm session identifier."
|
|
|
|
(when (bound-and-true-p helm-alive-p)
|
2019-07-25 03:20:37 +08:00
|
|
|
(let ((active (doom-modeline--active)))
|
|
|
|
(concat
|
|
|
|
(doom-modeline-spc)
|
|
|
|
(doom-modeline-icon-fileicon "elisp"
|
|
|
|
:height 1.0
|
|
|
|
:v-adjust -0.15
|
|
|
|
:face (if active
|
2019-10-26 00:06:10 +08:00
|
|
|
(if doom-modeline-major-mode-color-icon
|
2019-10-25 05:54:42 +08:00
|
|
|
'all-the-icons-purple
|
|
|
|
'mode-line)
|
2019-07-25 03:20:37 +08:00
|
|
|
'mode-line-inactive))
|
|
|
|
(when doom-modeline-icon (doom-modeline-spc))
|
|
|
|
(propertize
|
|
|
|
(let ((custom (cdr (assoc (buffer-name) doom-modeline--helm-buffer-ids)))
|
|
|
|
(case-fold-search t)
|
|
|
|
(name (replace-regexp-in-string "-" " " (buffer-name))))
|
|
|
|
(cond ((stringp custom) custom)
|
|
|
|
((functionp custom) (funcall custom))
|
|
|
|
(t
|
|
|
|
(string-match "\\*helm:? \\(mode \\)?\\([^\\*]+\\)\\*" name)
|
|
|
|
(concat "HELM " (capitalize (match-string 2 name))))))
|
|
|
|
'face (if active' doom-modeline-buffer-file 'mode-line-inactive))
|
|
|
|
(doom-modeline-spc)))))
|
2019-05-10 03:17:15 +08:00
|
|
|
|
|
|
|
(doom-modeline-def-segment helm-number
|
|
|
|
"Number of helm candidates."
|
|
|
|
(when (bound-and-true-p helm-alive-p)
|
2019-07-25 03:20:37 +08:00
|
|
|
(let ((active (doom-modeline--active)))
|
|
|
|
(concat
|
|
|
|
(propertize (format " %d/%d"
|
|
|
|
(helm-candidate-number-at-point)
|
|
|
|
(helm-get-candidate-number t))
|
|
|
|
'face (if active 'doom-modeline-buffer-path 'mode-line-inactive))
|
|
|
|
(propertize (format " (%d total) " (helm-get-candidate-number))
|
|
|
|
'face (if active 'doom-modeline-info 'mode-line-inactive))))))
|
2019-05-10 03:17:15 +08:00
|
|
|
|
|
|
|
(doom-modeline-def-segment helm-help
|
|
|
|
"Helm keybindings help."
|
|
|
|
(when (bound-and-true-p helm-alive-p)
|
2019-07-25 03:20:37 +08:00
|
|
|
(let ((active (doom-modeline--active)))
|
|
|
|
(-interleave
|
|
|
|
(mapcar (lambda (s)
|
|
|
|
(propertize (substitute-command-keys s)
|
|
|
|
'face (if active
|
|
|
|
'doom-modeline-buffer-file
|
|
|
|
'mode-line-inactive)))
|
|
|
|
'("\\<helm-map>\\[helm-help]"
|
|
|
|
"\\<helm-map>\\[helm-select-action]"
|
|
|
|
"\\<helm-map>\\[helm-maybe-exit-minibuffer]/F1/F2..."))
|
|
|
|
(mapcar (lambda (s)
|
|
|
|
(propertize s 'face (if active 'mode-line 'mode-line-inactive)))
|
|
|
|
'("(help) " "(actions) " "(action) "))))))
|
2019-05-10 03:17:15 +08:00
|
|
|
|
|
|
|
(doom-modeline-def-segment helm-prefix-argument
|
|
|
|
"Helm prefix argument."
|
|
|
|
(when (and (bound-and-true-p helm-alive-p)
|
|
|
|
helm--mode-line-display-prefarg)
|
|
|
|
(let ((arg (prefix-numeric-value (or prefix-arg current-prefix-arg))))
|
|
|
|
(unless (= arg 1)
|
2019-07-25 03:20:37 +08:00
|
|
|
(propertize (format "C-u %s" arg)
|
|
|
|
'face (if (doom-modeline--active)
|
|
|
|
'doom-modeline-info
|
|
|
|
'mode-line-inactive))))))
|
2019-05-10 03:17:15 +08:00
|
|
|
|
|
|
|
(defvar doom-modeline--helm-current-source nil
|
|
|
|
"The currently active helm source.")
|
|
|
|
(doom-modeline-def-segment helm-follow
|
|
|
|
"Helm follow indicator."
|
|
|
|
(when (and (bound-and-true-p helm-alive-p)
|
|
|
|
doom-modeline--helm-current-source
|
|
|
|
(eq 1 (cdr (assq 'follow doom-modeline--helm-current-source))))
|
2019-07-25 03:20:37 +08:00
|
|
|
(propertize "HF" 'face (if (doom-modeline--active)
|
|
|
|
'mode-line
|
|
|
|
'mode-line-inactive))))
|
2019-05-10 03:17:15 +08:00
|
|
|
|
2019-05-19 23:04:03 +08:00
|
|
|
;;
|
|
|
|
;; git timemachine
|
|
|
|
;;
|
|
|
|
|
|
|
|
(doom-modeline-def-segment git-timemachine
|
|
|
|
(let ((active (doom-modeline--active)))
|
|
|
|
(concat
|
2019-05-22 15:15:48 +08:00
|
|
|
(doom-modeline-spc)
|
2019-05-19 23:04:03 +08:00
|
|
|
|
2019-07-18 20:04:39 +08:00
|
|
|
(doom-modeline--buffer-mode-icon)
|
2019-05-19 23:04:03 +08:00
|
|
|
|
2019-10-23 03:07:51 +08:00
|
|
|
;; Snapshot icon
|
|
|
|
(doom-modeline-icon 'material "camera_alt" "📷" "%1*"
|
|
|
|
(if active 'warning 'mode-line-inactive)
|
|
|
|
:height 1.1 :v-adjust -0.25)
|
2019-05-19 23:04:03 +08:00
|
|
|
(doom-modeline-vspc)
|
|
|
|
|
|
|
|
;; buffer name
|
2019-07-18 20:04:39 +08:00
|
|
|
(propertize "*%b*" 'face (if active
|
2019-07-25 03:20:37 +08:00
|
|
|
'doom-modeline-buffer-file
|
|
|
|
'mode-line-inactive)))))
|
2019-05-19 23:04:03 +08:00
|
|
|
|
2019-08-16 20:05:39 +08:00
|
|
|
;;
|
|
|
|
;; Markdown/org preview
|
|
|
|
;;
|
|
|
|
|
|
|
|
(doom-modeline-def-segment grip
|
|
|
|
(when (bound-and-true-p grip-mode)
|
|
|
|
(concat
|
|
|
|
(doom-modeline-spc)
|
2019-08-18 22:08:46 +08:00
|
|
|
|
|
|
|
(let ((face (if (doom-modeline--active)
|
|
|
|
(if grip-process
|
|
|
|
(pcase (process-status grip-process)
|
2019-10-23 02:50:04 +08:00
|
|
|
('run '(:inherit (all-the-icons-lblue bold)))
|
|
|
|
('exit 'doom-modeline-warning)
|
|
|
|
(_ 'doom-modeline-error))
|
|
|
|
'doom-modeline-error)
|
2019-08-18 22:08:46 +08:00
|
|
|
'mode-line-inactive)))
|
|
|
|
(propertize
|
2019-10-23 02:50:04 +08:00
|
|
|
(doom-modeline-icon 'material "pageview" "🗐" "@"
|
|
|
|
(if doom-modeline-icon `(:inherit ,face :weight normal) face)
|
|
|
|
:height 1.2 :v-adjust -0.2)
|
2019-08-18 22:08:46 +08:00
|
|
|
'help-echo (format "Preview on: http://localhost:%d
|
2019-08-18 00:40:07 +08:00
|
|
|
mouse-1: Open browser
|
|
|
|
mouse-2: Stop preview"
|
2019-08-18 22:08:46 +08:00
|
|
|
grip-port)
|
2019-11-07 17:44:47 +08:00
|
|
|
'mouse-face 'mode-line-highlight
|
2019-08-18 22:08:46 +08:00
|
|
|
'local-map (let ((map (make-sparse-keymap)))
|
|
|
|
(define-key map [mode-line mouse-1]
|
2019-10-13 20:48:14 +08:00
|
|
|
#'grip-browse-preview)
|
2019-08-18 22:08:46 +08:00
|
|
|
(define-key map [mode-line mouse-2]
|
|
|
|
#'grip-mode)
|
|
|
|
map)))
|
|
|
|
|
2019-08-16 20:05:39 +08:00
|
|
|
(doom-modeline-spc))))
|
|
|
|
|
2019-01-17 23:42:33 +08:00
|
|
|
(provide 'doom-modeline-segments)
|
|
|
|
|
|
|
|
;;; doom-modeline-segments.el ends here
|