2017-06-08 11:47:56 +02:00
|
|
|
;;; ui/doom-modeline/config.el -*- lexical-binding: t; -*-
|
2017-02-11 06:49:57 -05:00
|
|
|
|
2017-06-18 23:41:48 +02:00
|
|
|
(def-package! eldoc-eval
|
|
|
|
:demand t
|
2017-02-03 19:44:14 -05:00
|
|
|
:config
|
2017-07-02 16:48:31 +02:00
|
|
|
(defun +doom-modeline-eldoc (text)
|
|
|
|
(concat (when (display-graphic-p)
|
|
|
|
(+doom-modeline--make-xpm
|
|
|
|
(face-background 'doom-modeline-eldoc-bar nil t)
|
|
|
|
+doom-modeline-height
|
|
|
|
+doom-modeline-bar-width))
|
|
|
|
text))
|
|
|
|
|
2017-01-31 05:09:39 -05:00
|
|
|
;; Show eldoc in the mode-line with `eval-expression'
|
2017-03-02 00:43:25 -05:00
|
|
|
(defun +doom-modeline--show-eldoc (input)
|
|
|
|
"Display string STR in the mode-line next to minibuffer."
|
|
|
|
(with-current-buffer (eldoc-current-buffer)
|
|
|
|
(let* ((str (and (stringp input) input))
|
2017-07-02 16:48:31 +02:00
|
|
|
(mode-line-format (or (and str (or (+doom-modeline-eldoc str) str))
|
2017-03-02 00:43:25 -05:00
|
|
|
mode-line-format))
|
|
|
|
mode-line-in-non-selected-windows)
|
|
|
|
(force-mode-line-update)
|
|
|
|
(sit-for eldoc-show-in-mode-line-delay))))
|
|
|
|
|
2017-04-17 02:17:10 -04:00
|
|
|
(setq eldoc-in-minibuffer-show-fn #'+doom-modeline--show-eldoc)
|
2017-01-31 05:09:39 -05:00
|
|
|
(eldoc-in-minibuffer-mode +1))
|
|
|
|
|
2017-06-19 00:30:41 +02:00
|
|
|
;; anzu and evil-anzu expose current/total state that can be displayed in the
|
2017-02-03 19:44:14 -05:00
|
|
|
;; mode-line.
|
2017-02-23 00:06:12 -05:00
|
|
|
(def-package! evil-anzu
|
2017-05-19 17:21:52 +02:00
|
|
|
:when (featurep 'evil)
|
2017-02-03 19:44:14 -05:00
|
|
|
:init
|
2017-06-05 16:41:39 +02:00
|
|
|
(add-transient-hook! #'evil-ex-start-search (require 'evil-anzu))
|
2017-02-03 19:44:14 -05:00
|
|
|
:config
|
|
|
|
(setq anzu-cons-mode-line-p nil
|
|
|
|
anzu-minimum-input-length 1
|
2017-03-05 13:33:04 -05:00
|
|
|
anzu-search-threshold 250)
|
2017-03-17 22:52:02 -04:00
|
|
|
|
2017-05-13 11:40:01 +02:00
|
|
|
;; Avoid anzu conflicts across buffers
|
|
|
|
(mapc #'make-variable-buffer-local
|
|
|
|
'(anzu--total-matched anzu--current-position anzu--state
|
|
|
|
anzu--cached-count anzu--cached-positions anzu--last-command
|
|
|
|
anzu--last-isearch-string anzu--overflow-p))
|
|
|
|
|
2017-03-05 16:10:21 -05:00
|
|
|
;; Ensure anzu state is cleared when searches & iedit are done
|
2017-07-02 16:48:31 +02:00
|
|
|
(add-hook 'isearch-mode-end-hook #'anzu--reset-status t)
|
|
|
|
(add-hook '+evil-esc-hook #'anzu--reset-status t)
|
|
|
|
(add-hook 'iedit-mode-end-hook #'anzu--reset-status))
|
2017-02-03 19:44:14 -05:00
|
|
|
|
2017-01-31 05:09:39 -05:00
|
|
|
|
2017-02-13 04:52:08 -05:00
|
|
|
;; Keep `+doom-modeline-current-window' up-to-date
|
|
|
|
(defvar +doom-modeline-current-window (frame-selected-window))
|
|
|
|
(defun +doom-modeline|set-selected-window (&rest _)
|
2017-02-21 16:04:35 -05:00
|
|
|
"Sets `+doom-modeline-current-window' appropriately"
|
2017-03-05 16:10:21 -05:00
|
|
|
(let ((win (frame-selected-window)))
|
|
|
|
(unless (minibuffer-window-active-p win)
|
|
|
|
(setq +doom-modeline-current-window win))))
|
2017-02-13 04:52:08 -05:00
|
|
|
|
2017-04-17 02:17:10 -04:00
|
|
|
(add-hook 'window-configuration-change-hook #'+doom-modeline|set-selected-window)
|
|
|
|
(add-hook 'focus-in-hook #'+doom-modeline|set-selected-window)
|
|
|
|
(advice-add #'handle-switch-frame :after #'+doom-modeline|set-selected-window)
|
|
|
|
(advice-add #'select-window :after #'+doom-modeline|set-selected-window)
|
2017-02-13 04:52:08 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
2017-01-31 05:09:39 -05:00
|
|
|
;;
|
|
|
|
;; Variables
|
|
|
|
;;
|
|
|
|
|
2017-02-11 06:49:57 -05:00
|
|
|
(defvar +doom-modeline-height 29
|
2017-01-31 05:09:39 -05:00
|
|
|
"How tall the mode-line should be (only respected in GUI emacs).")
|
|
|
|
|
2017-02-11 06:49:57 -05:00
|
|
|
(defvar +doom-modeline-bar-width 3
|
2017-01-31 05:09:39 -05:00
|
|
|
"How wide the mode-line bar should be (only respected in GUI emacs).")
|
|
|
|
|
2017-02-11 06:49:57 -05:00
|
|
|
(defvar +doom-modeline-vspc
|
|
|
|
(propertize " " 'face 'variable-pitch)
|
2017-03-05 16:10:21 -05:00
|
|
|
"TODO")
|
|
|
|
|
|
|
|
;; externs
|
|
|
|
(defvar anzu--state nil)
|
|
|
|
(defvar evil-mode nil)
|
|
|
|
(defvar evil-state nil)
|
|
|
|
(defvar evil-visual-selection nil)
|
|
|
|
(defvar iedit-mode nil)
|
2017-06-08 11:47:56 +02:00
|
|
|
(defvar all-the-icons-scale-factor)
|
|
|
|
(defvar all-the-icons-default-adjust)
|
2017-02-11 06:49:57 -05:00
|
|
|
|
2017-01-31 05:09:39 -05:00
|
|
|
|
|
|
|
;;
|
|
|
|
;; Custom faces
|
|
|
|
;;
|
|
|
|
|
2017-02-13 04:52:08 -05:00
|
|
|
(defgroup +doom-modeline nil
|
|
|
|
""
|
|
|
|
:group 'doom)
|
|
|
|
|
2017-01-31 05:09:39 -05:00
|
|
|
(defface doom-modeline-buffer-path
|
2017-05-17 17:28:36 +02:00
|
|
|
'((t (:inherit mode-line-emphasis :bold t)))
|
2017-02-13 04:52:08 -05:00
|
|
|
"Face used for the dirname part of the buffer path."
|
|
|
|
:group '+doom-modeline)
|
2017-01-31 05:09:39 -05:00
|
|
|
|
2017-05-14 00:23:18 +02:00
|
|
|
(defface doom-modeline-buffer-file
|
2017-05-17 17:28:36 +02:00
|
|
|
'((t (:inherit mode-line-buffer-id)))
|
2017-02-13 04:52:08 -05:00
|
|
|
"Face used for the filename part of the mode-line buffer path."
|
|
|
|
:group '+doom-modeline)
|
2017-01-31 05:09:39 -05:00
|
|
|
|
|
|
|
(defface doom-modeline-buffer-modified
|
2017-05-17 17:28:36 +02:00
|
|
|
'((t (:inherit error :background nil :bold t)))
|
2017-02-13 04:52:08 -05:00
|
|
|
"Face used for the 'unsaved' symbol in the mode-line."
|
|
|
|
:group '+doom-modeline)
|
2017-01-31 05:09:39 -05:00
|
|
|
|
|
|
|
(defface doom-modeline-buffer-major-mode
|
2017-05-17 17:28:36 +02:00
|
|
|
'((t (:inherit mode-line-emphasis :bold t)))
|
2017-02-13 04:52:08 -05:00
|
|
|
"Face used for the major-mode segment in the mode-line."
|
|
|
|
:group '+doom-modeline)
|
2017-01-31 05:09:39 -05:00
|
|
|
|
|
|
|
(defface doom-modeline-highlight
|
2017-05-17 17:28:36 +02:00
|
|
|
'((t (:inherit mode-line-emphasis)))
|
2017-02-13 04:52:08 -05:00
|
|
|
"Face for bright segments of the mode-line."
|
|
|
|
:group '+doom-modeline)
|
2017-01-31 05:09:39 -05:00
|
|
|
|
|
|
|
(defface doom-modeline-panel
|
2017-05-17 17:28:36 +02:00
|
|
|
'((t (:inherit mode-line-highlight)))
|
2017-02-11 06:49:57 -05:00
|
|
|
"Face for 'X out of Y' segments, such as `+doom-modeline--anzu', `+doom-modeline--evil-substitute' and
|
2017-02-13 04:52:08 -05:00
|
|
|
`iedit'"
|
|
|
|
:group '+doom-modeline)
|
2017-01-31 05:09:39 -05:00
|
|
|
|
|
|
|
(defface doom-modeline-info
|
2017-05-16 11:43:11 +02:00
|
|
|
`((t (:inherit success :bold t)))
|
2017-02-13 04:52:08 -05:00
|
|
|
"Face for info-level messages in the modeline. Used by `*vc'."
|
|
|
|
:group '+doom-modeline)
|
2017-01-31 05:09:39 -05:00
|
|
|
|
|
|
|
(defface doom-modeline-warning
|
2017-05-16 11:43:11 +02:00
|
|
|
`((t (:inherit warning :bold t)))
|
2017-02-13 04:52:08 -05:00
|
|
|
"Face for warnings in the modeline. Used by `*flycheck'"
|
|
|
|
:group '+doom-modeline)
|
2017-01-31 05:09:39 -05:00
|
|
|
|
2017-05-01 14:52:29 -04:00
|
|
|
(defface doom-modeline-urgent
|
2017-05-16 11:43:11 +02:00
|
|
|
`((t (:inherit error :bold t)))
|
2017-02-13 04:52:08 -05:00
|
|
|
"Face for errors in the modeline. Used by `*flycheck'"
|
|
|
|
:group '+doom-modeline)
|
2017-01-31 05:09:39 -05:00
|
|
|
|
|
|
|
;; Bar
|
2017-05-17 17:28:36 +02:00
|
|
|
(defface doom-modeline-bar '((t (:inherit highlight)))
|
2017-02-13 04:52:08 -05:00
|
|
|
"The face used for the left-most bar on the mode-line of an active window."
|
|
|
|
:group '+doom-modeline)
|
2017-01-31 05:09:39 -05:00
|
|
|
|
2017-05-17 17:28:36 +02:00
|
|
|
(defface doom-modeline-eldoc-bar '((t (:inherit shadow)))
|
2017-01-31 05:09:39 -05:00
|
|
|
"The face used for the left-most bar on the mode-line when eldoc-eval is
|
2017-02-13 04:52:08 -05:00
|
|
|
active."
|
|
|
|
:group '+doom-modeline)
|
2017-01-31 05:09:39 -05:00
|
|
|
|
2017-05-17 17:28:36 +02:00
|
|
|
(defface doom-modeline-inactive-bar '((t (:inherit warning :inverse-video t)))
|
2017-02-13 04:52:08 -05:00
|
|
|
"The face used for the left-most bar on the mode-line of an inactive window."
|
|
|
|
:group '+doom-modeline)
|
2017-01-31 05:09:39 -05:00
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
;; Bootstrap
|
|
|
|
;;
|
|
|
|
|
|
|
|
;; Show version string for multi-version managers like rvm, rbenv, pyenv, etc.
|
|
|
|
(defvar-local +doom-modeline-env-version nil)
|
|
|
|
(defvar-local +doom-modeline-env-command nil)
|
2017-04-17 16:54:31 -04:00
|
|
|
(add-hook! '(focus-in-hook find-file-hook) #'+doom-modeline|update-env)
|
2017-01-31 05:09:39 -05:00
|
|
|
(defun +doom-modeline|update-env ()
|
|
|
|
(when +doom-modeline-env-command
|
|
|
|
(let* ((default-directory (doom-project-root))
|
2017-02-28 16:30:44 +10:30
|
|
|
(s (shell-command-to-string +doom-modeline-env-command)))
|
2017-01-31 05:09:39 -05:00
|
|
|
(setq +doom-modeline-env-version (if (string-match "[ \t\n\r]+\\'" s)
|
|
|
|
(replace-match "" t t s)
|
|
|
|
s)))))
|
|
|
|
|
|
|
|
;; Only support python and ruby for now
|
2017-04-17 02:20:07 -04:00
|
|
|
(add-hook! 'python-mode-hook (setq +doom-modeline-env-command "python --version 2>&1 | cut -d' ' -f2"))
|
2017-04-17 16:54:31 -04:00
|
|
|
(add-hook! 'ruby-mode-hook (setq +doom-modeline-env-command "ruby --version 2>&1 | cut -d' ' -f2"))
|
2017-01-31 05:09:39 -05:00
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
;; Modeline helpers
|
|
|
|
;;
|
|
|
|
|
2017-02-13 04:52:08 -05:00
|
|
|
(defsubst active ()
|
|
|
|
(eq (selected-window) +doom-modeline-current-window))
|
2017-01-31 05:09:39 -05:00
|
|
|
|
2017-03-02 00:43:25 -05:00
|
|
|
;; Inspired from `powerline's `pl/make-xpm'.
|
2017-02-23 00:06:12 -05:00
|
|
|
(def-memoized! +doom-modeline--make-xpm (color height width)
|
2017-01-31 05:09:39 -05:00
|
|
|
"Create an XPM bitmap."
|
2017-06-14 21:16:02 +02:00
|
|
|
(propertize
|
|
|
|
" " 'display
|
|
|
|
(let ((data (make-list height (make-list width 1)))
|
|
|
|
(color (or color "None")))
|
|
|
|
(create-image
|
|
|
|
(concat
|
|
|
|
(format "/* XPM */\nstatic char * percent[] = {\n\"%i %i 2 1\",\n\". c %s\",\n\" c %s\","
|
|
|
|
(length (car data))
|
|
|
|
(length data)
|
|
|
|
color
|
|
|
|
color)
|
|
|
|
(apply #'concat
|
|
|
|
(cl-loop with idx = 0
|
|
|
|
with len = (length data)
|
|
|
|
for dl in data
|
|
|
|
do (cl-incf idx)
|
|
|
|
collect
|
|
|
|
(concat "\""
|
|
|
|
(cl-loop for d in dl
|
|
|
|
if (= d 0) collect (string-to-char " ")
|
|
|
|
else collect (string-to-char "."))
|
|
|
|
(if (eq idx len) "\"};" "\",\n")))))
|
|
|
|
'xpm t :ascent 'center))))
|
2017-01-31 05:09:39 -05:00
|
|
|
|
2017-06-08 11:47:56 +02:00
|
|
|
(defsubst +doom-modeline--buffer-file ()
|
2017-05-14 09:46:48 +02:00
|
|
|
"Display the base of the current buffer's filename."
|
|
|
|
(if buffer-file-name
|
2017-05-15 13:45:14 +02:00
|
|
|
(file-name-nondirectory (or buffer-file-truename (file-truename buffer-file-name)))
|
2017-05-14 09:46:48 +02:00
|
|
|
"%b"))
|
2017-05-14 00:23:18 +02:00
|
|
|
|
2017-06-08 11:47:56 +02:00
|
|
|
(defsubst +doom-modeline--buffer-path ()
|
2017-01-31 05:09:39 -05:00
|
|
|
"Displays the buffer's full path relative to the project root (includes the
|
|
|
|
project root). Excludes the file basename. See `doom-buffer-name' for that."
|
2017-05-14 00:23:18 +02:00
|
|
|
(when buffer-file-name
|
|
|
|
(let ((buffer-path
|
2017-05-15 13:45:14 +02:00
|
|
|
(file-relative-name (file-name-directory
|
|
|
|
(or buffer-file-truename (file-truename buffer-file-name)))
|
2017-05-14 00:23:18 +02:00
|
|
|
(doom-project-root))))
|
|
|
|
(unless (equal buffer-path "./")
|
|
|
|
(let ((max-length (truncate (* (window-body-width) 0.4))))
|
|
|
|
(if (> (length buffer-path) max-length)
|
|
|
|
(let ((path (nreverse (split-string buffer-path "/" t)))
|
|
|
|
(output ""))
|
|
|
|
(when (and path (equal "" (car path)))
|
|
|
|
(setq path (cdr path)))
|
|
|
|
(while (and path (<= (length output) (- max-length 4)))
|
2017-05-14 09:49:09 +02:00
|
|
|
(setq output (concat (car path) "/" output)
|
|
|
|
path (cdr path)))
|
2017-05-14 00:23:18 +02:00
|
|
|
(when path
|
|
|
|
(setq output (concat "../" output)))
|
|
|
|
(unless (string-suffix-p "/" output)
|
|
|
|
(setq output (concat output "/")))
|
|
|
|
output)
|
|
|
|
buffer-path))))))
|
2017-01-31 05:09:39 -05:00
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
;; Segments
|
|
|
|
;;
|
|
|
|
|
2017-02-23 00:06:12 -05:00
|
|
|
(def-modeline-segment! buffer-project
|
2017-02-11 06:49:57 -05:00
|
|
|
"Displays `doom-project-root'. This is for special buffers like the scratch
|
|
|
|
buffer where knowing the current project directory is important."
|
2017-05-14 00:23:18 +02:00
|
|
|
(let ((face (if (active) 'doom-modeline-buffer-path)))
|
2017-06-14 21:16:02 +02:00
|
|
|
(concat (if (display-graphic-p) " ")
|
|
|
|
(all-the-icons-octicon
|
2017-01-31 05:09:39 -05:00
|
|
|
"file-directory"
|
|
|
|
:face face
|
|
|
|
:v-adjust -0.05
|
|
|
|
:height 1.25)
|
|
|
|
(propertize (concat " " (abbreviate-file-name (doom-project-root)))
|
|
|
|
'face face))))
|
|
|
|
|
2017-03-05 13:33:04 -05:00
|
|
|
;;
|
2017-02-23 00:06:12 -05:00
|
|
|
(def-modeline-segment! buffer-info
|
2017-01-31 05:09:39 -05:00
|
|
|
"Combined information about the current buffer, including the current working
|
|
|
|
directory, the file name, and its state (modified, read-only or non-existent)."
|
2017-05-15 13:45:14 +02:00
|
|
|
(let* ((all-the-icons-scale-factor 1.2)
|
|
|
|
(modified-p (buffer-modified-p))
|
|
|
|
(active (active))
|
|
|
|
(faces (if modified-p 'doom-modeline-buffer-modified)))
|
2017-06-14 21:16:02 +02:00
|
|
|
(concat (cond (buffer-read-only
|
|
|
|
(concat (all-the-icons-octicon
|
|
|
|
"lock"
|
|
|
|
:face 'doom-modeline-warning
|
|
|
|
:v-adjust -0.05)
|
|
|
|
" "))
|
|
|
|
(modified-p
|
|
|
|
(concat (all-the-icons-faicon
|
|
|
|
"floppy-o"
|
|
|
|
:face 'doom-modeline-buffer-modified
|
2017-06-17 22:43:59 +02:00
|
|
|
:v-adjust -0.0575)
|
2017-06-14 21:16:02 +02:00
|
|
|
" "))
|
|
|
|
((and buffer-file-name
|
|
|
|
(not (file-exists-p buffer-file-name)))
|
|
|
|
(concat (all-the-icons-octicon
|
|
|
|
"circle-slash"
|
|
|
|
:face 'doom-modeline-urgent
|
|
|
|
:v-adjust -0.05)
|
2017-06-28 17:37:43 +02:00
|
|
|
" "))
|
|
|
|
((buffer-narrowed-p)
|
|
|
|
(concat (all-the-icons-octicon
|
|
|
|
"fold"
|
|
|
|
:face 'doom-modeline-warning
|
|
|
|
:v-adjust -0.05)
|
2017-06-14 21:16:02 +02:00
|
|
|
" ")))
|
2017-05-15 13:45:14 +02:00
|
|
|
(when-let (dir-path (+doom-modeline--buffer-path))
|
|
|
|
(if-let (faces (or faces (if active 'doom-modeline-buffer-path)))
|
|
|
|
(propertize dir-path 'face `(:inherit ,faces))
|
|
|
|
dir-path))
|
|
|
|
(when-let (file-path (+doom-modeline--buffer-file))
|
|
|
|
(if-let (faces (or faces (if active 'doom-modeline-buffer-file)))
|
2017-05-14 00:23:18 +02:00
|
|
|
(propertize file-path 'face `(:inherit ,faces))
|
|
|
|
file-path)))))
|
2017-01-31 05:09:39 -05:00
|
|
|
|
2017-06-12 14:31:12 +02:00
|
|
|
;;
|
|
|
|
(def-modeline-segment! buffer-info-simple
|
|
|
|
"Return the current buffer name only, but with fontification."
|
|
|
|
(propertize "%b" 'face (if (active) 'doom-modeline-buffer-file)))
|
|
|
|
|
2017-03-05 13:33:04 -05:00
|
|
|
;;
|
2017-02-23 00:06:12 -05:00
|
|
|
(def-modeline-segment! buffer-encoding
|
2017-02-11 06:49:57 -05:00
|
|
|
"Displays the encoding and eol style of the buffer the same way Atom does."
|
2017-07-02 16:48:31 +02:00
|
|
|
(concat (pcase (coding-system-eol-type buffer-file-coding-system)
|
|
|
|
(0 "LF ")
|
|
|
|
(1 "CRLF ")
|
|
|
|
(2 "CR "))
|
|
|
|
(let ((sys (coding-system-plist buffer-file-coding-system)))
|
|
|
|
(cond ((memq (plist-get sys :category) '(coding-category-undecided coding-category-utf-8))
|
2017-01-31 05:09:39 -05:00
|
|
|
"UTF-8")
|
2017-07-02 16:48:31 +02:00
|
|
|
(t (upcase (symbol-name (plist-get sys :name))))))
|
2017-01-31 05:09:39 -05:00
|
|
|
" "))
|
|
|
|
|
2017-03-05 13:33:04 -05:00
|
|
|
;;
|
2017-02-23 00:06:12 -05:00
|
|
|
(def-modeline-segment! major-mode
|
2017-01-31 05:09:39 -05:00
|
|
|
"The major mode, including process, environment and text-scale info."
|
|
|
|
(propertize
|
|
|
|
(concat (format-mode-line mode-name)
|
2017-07-02 16:48:31 +02:00
|
|
|
(when (stringp mode-line-process)
|
|
|
|
mode-line-process)
|
|
|
|
(when +doom-modeline-env-version
|
|
|
|
(concat " " +doom-modeline-env-version))
|
2017-01-31 05:09:39 -05:00
|
|
|
(and (featurep 'face-remap)
|
|
|
|
(/= text-scale-mode-amount 0)
|
|
|
|
(format " (%+d)" text-scale-mode-amount)))
|
|
|
|
'face (if (active) 'doom-modeline-buffer-major-mode)))
|
|
|
|
|
2017-03-05 13:33:04 -05:00
|
|
|
;;
|
2017-02-23 00:06:12 -05:00
|
|
|
(def-modeline-segment! vcs
|
2017-01-31 05:09:39 -05:00
|
|
|
"Displays the current branch, colored based on its state."
|
2017-06-28 11:51:36 +02:00
|
|
|
(when (and vc-mode buffer-file-name)
|
2017-07-02 16:48:31 +02:00
|
|
|
(let* ((backend (vc-backend buffer-file-name))
|
|
|
|
(state (vc-state buffer-file-name backend)))
|
|
|
|
(let ((face 'mode-line-inactive)
|
|
|
|
(active (active))
|
|
|
|
(all-the-icons-scale-factor 1.0)
|
|
|
|
(all-the-icons-default-adjust -0.1))
|
|
|
|
(concat " "
|
|
|
|
(cond ((memq state '(edited added))
|
|
|
|
(if active (setq face 'doom-modeline-info))
|
|
|
|
(all-the-icons-octicon
|
|
|
|
"git-compare"
|
|
|
|
:face face
|
|
|
|
:height 1.2
|
|
|
|
:v-adjust -0.05))
|
|
|
|
((eq state 'needs-merge)
|
|
|
|
(if active (setq face 'doom-modeline-info))
|
|
|
|
(all-the-icons-octicon "git-merge" :face face))
|
|
|
|
((eq state 'needs-update)
|
|
|
|
(if active (setq face 'doom-modeline-warning))
|
|
|
|
(all-the-icons-octicon "arrow-down" :face face))
|
|
|
|
((memq state '(removed conflict unregistered))
|
|
|
|
(if active (setq face 'doom-modeline-urgent))
|
|
|
|
(all-the-icons-octicon "alert" :face face))
|
|
|
|
(t
|
|
|
|
(if active (setq face 'font-lock-doc-face))
|
|
|
|
(all-the-icons-octicon
|
|
|
|
"git-compare"
|
|
|
|
:face face
|
|
|
|
:height 1.2
|
|
|
|
:v-adjust -0.05)))
|
|
|
|
" "
|
|
|
|
(propertize (substring vc-mode (+ (if (eq backend 'Hg) 2 3) 2))
|
|
|
|
'face (if active face))
|
|
|
|
" ")))))
|
2017-02-11 06:49:57 -05:00
|
|
|
|
2017-03-05 13:33:04 -05:00
|
|
|
;;
|
2017-06-16 14:18:03 +02:00
|
|
|
(defun +doom-ml-icon (icon &optional text face voffset)
|
2017-02-11 06:49:57 -05:00
|
|
|
"Displays an octicon ICON with FACE, followed by TEXT. Uses
|
|
|
|
`all-the-icons-octicon' to fetch the icon."
|
2017-07-02 16:48:31 +02:00
|
|
|
(concat (if vc-mode " " " ")
|
|
|
|
(when icon
|
|
|
|
(concat
|
|
|
|
(all-the-icons-material icon :face face :height 1.1 :v-adjust (or voffset -0.2))
|
|
|
|
(if text +doom-modeline-vspc)))
|
|
|
|
(when text
|
|
|
|
(propertize text 'face face))
|
|
|
|
(if vc-mode " " " ")))
|
2017-02-11 06:49:57 -05:00
|
|
|
|
2017-02-23 00:06:12 -05:00
|
|
|
(def-modeline-segment! flycheck
|
2017-02-11 06:49:57 -05:00
|
|
|
"Displays color-coded flycheck error status in the current buffer with pretty
|
|
|
|
icons."
|
|
|
|
(when (boundp 'flycheck-last-status-change)
|
|
|
|
(pcase flycheck-last-status-change
|
2017-03-02 00:43:25 -05:00
|
|
|
('finished (if flycheck-current-errors
|
2017-02-11 06:49:57 -05:00
|
|
|
(let-alist (flycheck-count-errors flycheck-current-errors)
|
|
|
|
(let ((sum (+ (or .error 0) (or .warning 0))))
|
2017-06-16 14:18:03 +02:00
|
|
|
(+doom-ml-icon "do_not_disturb_alt"
|
2017-05-16 11:43:11 +02:00
|
|
|
(number-to-string sum)
|
2017-06-16 14:18:03 +02:00
|
|
|
(if .error 'doom-modeline-urgent 'doom-modeline-warning)
|
|
|
|
-0.25)))
|
2017-06-14 21:16:02 +02:00
|
|
|
(+doom-ml-icon "check" nil 'doom-modeline-info)))
|
2017-06-16 14:18:03 +02:00
|
|
|
('running (+doom-ml-icon "access_time" nil 'font-lock-doc-face -0.25))
|
2017-06-14 21:16:02 +02:00
|
|
|
('no-checker (+doom-ml-icon "sim_card_alert" "-" 'font-lock-doc-face))
|
|
|
|
('errored (+doom-ml-icon "sim_card_alert" "Error" 'doom-modeline-urgent))
|
|
|
|
('interrupted (+doom-ml-icon "pause" "Interrupted" 'font-lock-doc-face)))))
|
|
|
|
;; ('interrupted (+doom-ml-icon "x" "Interrupted" 'font-lock-doc-face)))))
|
2017-02-11 06:49:57 -05:00
|
|
|
|
2017-03-05 13:33:04 -05:00
|
|
|
;;
|
2017-02-11 06:49:57 -05:00
|
|
|
(defsubst doom-column (pos)
|
2017-03-03 16:53:16 -05:00
|
|
|
(save-excursion (goto-char pos)
|
|
|
|
(current-column)))
|
2017-02-11 06:49:57 -05:00
|
|
|
|
2017-02-23 00:06:12 -05:00
|
|
|
(def-modeline-segment! selection-info
|
2017-01-31 05:09:39 -05:00
|
|
|
"Information about the current selection, such as how many characters and
|
|
|
|
lines are selected, or the NxM dimensions of a block selection."
|
2017-03-03 16:53:16 -05:00
|
|
|
(when (and (active) (or mark-active (eq evil-state 'visual)))
|
|
|
|
(let ((reg-beg (region-beginning))
|
|
|
|
(reg-end (region-end)))
|
|
|
|
(propertize
|
|
|
|
(let ((lines (count-lines reg-beg (min (1+ reg-end) (point-max)))))
|
|
|
|
(cond ((or (bound-and-true-p rectangle-mark-mode)
|
|
|
|
(eq 'block evil-visual-selection))
|
|
|
|
(let ((cols (abs (- (doom-column reg-end)
|
|
|
|
(doom-column reg-beg)))))
|
|
|
|
(format "%dx%dB" lines cols)))
|
|
|
|
((eq 'line evil-visual-selection)
|
|
|
|
(format "%dL" lines))
|
|
|
|
((> lines 1)
|
|
|
|
(format "%dC %dL" (- (1+ reg-end) reg-beg) lines))
|
|
|
|
(t
|
|
|
|
(format "%dC" (- (1+ reg-end) reg-beg)))))
|
|
|
|
'face 'doom-modeline-highlight))))
|
2017-02-11 06:49:57 -05:00
|
|
|
|
|
|
|
|
2017-03-05 13:33:04 -05:00
|
|
|
;;
|
2017-02-11 06:49:57 -05:00
|
|
|
(defun +doom-modeline--macro-recording ()
|
2017-03-03 17:49:30 -05:00
|
|
|
"Display current Emacs or evil macro being recorded."
|
|
|
|
(when (and (active) (or defining-kbd-macro executing-kbd-macro))
|
2017-01-31 05:09:39 -05:00
|
|
|
(let ((sep (propertize " " 'face 'doom-modeline-panel)))
|
|
|
|
(concat sep
|
2017-03-03 17:49:30 -05:00
|
|
|
(propertize (if (bound-and-true-p evil-this-macro)
|
|
|
|
(char-to-string evil-this-macro)
|
|
|
|
"Macro")
|
2017-01-31 05:09:39 -05:00
|
|
|
'face 'doom-modeline-panel)
|
|
|
|
sep
|
|
|
|
(all-the-icons-octicon "triangle-right"
|
|
|
|
:face 'doom-modeline-panel
|
|
|
|
:v-adjust -0.05)
|
|
|
|
sep))))
|
|
|
|
|
2017-02-11 06:49:57 -05:00
|
|
|
(defsubst +doom-modeline--anzu ()
|
2017-03-05 13:33:04 -05:00
|
|
|
"Show the match index and total number thereof. Requires `anzu', also
|
|
|
|
`evil-anzu' if using `evil-mode' for compatibility with `evil-search'."
|
|
|
|
(when (and anzu--state (not iedit-mode))
|
2017-01-31 05:09:39 -05:00
|
|
|
(propertize
|
2017-03-05 13:33:04 -05:00
|
|
|
(let ((here anzu--current-position)
|
|
|
|
(total anzu--total-matched))
|
2017-05-13 11:40:01 +02:00
|
|
|
(cond ((eq anzu--state 'replace-query)
|
|
|
|
(format " %d replace " total))
|
|
|
|
((eq anzu--state 'replace)
|
|
|
|
(format " %d/%d " here total))
|
|
|
|
(anzu--overflow-p
|
|
|
|
(format " %s+ " total))
|
|
|
|
(t
|
|
|
|
(format " %s/%d " here total))))
|
2017-01-31 05:09:39 -05:00
|
|
|
'face (if (active) 'doom-modeline-panel))))
|
|
|
|
|
2017-02-11 06:49:57 -05:00
|
|
|
(defsubst +doom-modeline--evil-substitute ()
|
2017-07-02 16:48:31 +02:00
|
|
|
"Show number of matches for evil-ex substitutions and highlights in real time."
|
2017-03-05 13:33:04 -05:00
|
|
|
(when (and evil-mode
|
|
|
|
(or (assq 'evil-ex-substitute evil-ex-active-highlights-alist)
|
|
|
|
(assq 'evil-ex-global-match evil-ex-active-highlights-alist)
|
|
|
|
(assq 'evil-ex-buffer-match evil-ex-active-highlights-alist)))
|
2017-01-31 05:09:39 -05:00
|
|
|
(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
|
2017-03-05 13:33:04 -05:00
|
|
|
(format " %s matches " (how-many pattern (car range) (cdr range)))
|
2017-07-02 16:48:31 +02:00
|
|
|
" - "))
|
2017-01-31 05:09:39 -05:00
|
|
|
'face (if (active) 'doom-modeline-panel))))
|
|
|
|
|
2017-07-02 16:48:31 +02:00
|
|
|
(defun doom-themes--overlay-sort (a b)
|
|
|
|
(< (overlay-start a) (overlay-start b)))
|
|
|
|
|
2017-02-11 06:49:57 -05:00
|
|
|
(defsubst +doom-modeline--iedit ()
|
2017-01-31 05:09:39 -05:00
|
|
|
"Show the number of iedit regions matches + what match you're on."
|
2017-03-03 17:50:22 -05:00
|
|
|
(when (and iedit-mode iedit-occurrences-overlays)
|
2017-01-31 05:09:39 -05:00
|
|
|
(propertize
|
2017-03-03 17:50:22 -05:00
|
|
|
(let ((this-oc (or (let ((inhibit-message t))
|
|
|
|
(iedit-find-current-occurrence-overlay))
|
|
|
|
(progn (iedit-prev-occurrence)
|
|
|
|
(iedit-find-current-occurrence-overlay))))
|
|
|
|
(length (length iedit-occurrences-overlays)))
|
|
|
|
(format " %s/%d "
|
|
|
|
(if this-oc
|
|
|
|
(- length
|
2017-07-02 16:48:31 +02:00
|
|
|
(length (memq this-oc (sort (append iedit-occurrences-overlays nil)
|
|
|
|
#'doom-themes--overlay-sort)))
|
|
|
|
-1)
|
2017-03-03 17:50:22 -05:00
|
|
|
"-")
|
2017-02-11 06:49:57 -05:00
|
|
|
length))
|
2017-01-31 05:09:39 -05:00
|
|
|
'face (if (active) 'doom-modeline-panel))))
|
|
|
|
|
2017-02-23 00:06:12 -05:00
|
|
|
(def-modeline-segment! matches
|
2017-03-03 17:50:43 -05:00
|
|
|
"Displays: 1. the currently recording macro, 2. A current/total for the
|
|
|
|
current search term (with anzu), 3. The number of substitutions being conducted
|
|
|
|
with `evil-ex-substitute', and/or 4. The number of active `iedit' regions."
|
|
|
|
(let ((meta (concat (+doom-modeline--macro-recording)
|
|
|
|
(+doom-modeline--anzu)
|
|
|
|
(+doom-modeline--evil-substitute)
|
|
|
|
(+doom-modeline--iedit))))
|
2017-07-02 16:48:31 +02:00
|
|
|
(or (and (not (equal meta "")) meta)
|
2017-04-09 22:10:18 -04:00
|
|
|
(if buffer-file-name " %I "))))
|
2017-02-11 06:49:57 -05:00
|
|
|
|
2017-03-05 13:33:04 -05:00
|
|
|
;; TODO Include other information
|
2017-02-23 00:06:12 -05:00
|
|
|
(def-modeline-segment! media-info
|
2017-03-03 17:50:58 -05:00
|
|
|
"Metadata regarding the current file, such as dimensions for images."
|
2017-01-31 05:09:39 -05:00
|
|
|
(cond ((eq major-mode 'image-mode)
|
2017-07-02 16:48:31 +02:00
|
|
|
(cl-destructuring-bind (width . height)
|
|
|
|
(image-size (image-get-display-property) :pixels)
|
|
|
|
(format " %dx%d " width height)))))
|
2017-02-11 06:49:57 -05:00
|
|
|
|
2017-07-02 16:48:31 +02:00
|
|
|
;; The bar regulates the height of the mode-line in GUI Emacs.
|
2017-02-23 00:06:12 -05:00
|
|
|
(def-modeline-segment! bar
|
2017-07-02 16:48:31 +02:00
|
|
|
(when (display-graphic-p)
|
|
|
|
(+doom-modeline--make-xpm
|
|
|
|
(face-background (if (active)
|
|
|
|
'doom-modeline-bar
|
|
|
|
'doom-modeline-inactive-bar)
|
|
|
|
nil t)
|
|
|
|
+doom-modeline-height
|
|
|
|
+doom-modeline-bar-width)))
|
2017-02-11 06:49:57 -05:00
|
|
|
|
2017-01-31 05:09:39 -05:00
|
|
|
|
|
|
|
;;
|
|
|
|
;; Mode lines
|
|
|
|
;;
|
|
|
|
|
2017-02-23 00:06:12 -05:00
|
|
|
(def-modeline! main
|
2017-02-11 06:49:57 -05:00
|
|
|
(bar matches " " buffer-info " %l:%c %p " selection-info)
|
2017-06-14 21:16:02 +02:00
|
|
|
(buffer-encoding major-mode vcs flycheck))
|
2017-02-11 06:49:57 -05:00
|
|
|
|
2017-02-23 00:06:12 -05:00
|
|
|
(def-modeline! minimal
|
2017-02-11 06:49:57 -05:00
|
|
|
(bar matches " " buffer-info)
|
|
|
|
(media-info major-mode))
|
|
|
|
|
2017-04-10 02:54:20 -04:00
|
|
|
(def-modeline! special
|
2017-06-12 14:31:12 +02:00
|
|
|
(bar matches " " buffer-info-simple " %l:%c %p " selection-info)
|
2017-04-10 02:54:20 -04:00
|
|
|
(buffer-encoding major-mode flycheck))
|
|
|
|
|
2017-02-23 00:06:12 -05:00
|
|
|
(def-modeline! project
|
2017-06-14 21:16:02 +02:00
|
|
|
(bar buffer-project)
|
2017-02-11 06:49:57 -05:00
|
|
|
(major-mode))
|
2017-01-31 05:09:39 -05:00
|
|
|
|
2017-05-16 11:54:34 +02:00
|
|
|
(def-modeline! media
|
|
|
|
(bar " %b ")
|
|
|
|
(media-info major-mode))
|
|
|
|
|
2017-04-10 02:54:20 -04:00
|
|
|
|
|
|
|
;;
|
|
|
|
;; Hooks
|
|
|
|
;;
|
|
|
|
|
2017-06-28 16:18:22 +02:00
|
|
|
(defun +doom-modeline|init ()
|
|
|
|
"Set the default modeline."
|
|
|
|
(doom-set-modeline 'main t)
|
|
|
|
|
|
|
|
;; This scratch buffer is already created and doesn't get a modeline. For the
|
|
|
|
;; love of Emacs, someone give the man a modeline!
|
|
|
|
(with-current-buffer "*scratch*"
|
|
|
|
(doom-set-modeline 'main)))
|
|
|
|
|
2017-04-10 02:54:20 -04:00
|
|
|
(defun +doom-modeline|set-special-modeline ()
|
2017-04-25 18:25:54 -04:00
|
|
|
(doom-set-modeline 'special))
|
2017-04-10 02:54:20 -04:00
|
|
|
|
2017-05-16 11:54:34 +02:00
|
|
|
(defun +doom-modeline|set-media-modeline ()
|
|
|
|
(doom-set-modeline 'media))
|
|
|
|
|
2017-06-28 16:18:22 +02:00
|
|
|
|
|
|
|
;;
|
|
|
|
;; Bootstrap
|
|
|
|
;;
|
|
|
|
|
|
|
|
(add-hook 'doom-init-ui-hook #'+doom-modeline|init)
|
|
|
|
|
2017-04-17 02:17:10 -04:00
|
|
|
(add-hook 'org-src-mode-hook #'+doom-modeline|set-special-modeline)
|
2017-06-28 16:18:22 +02:00
|
|
|
(add-hook 'image-mode-hook #'+doom-modeline|set-media-modeline)
|
|
|
|
(add-hook 'circe-mode-hook #'+doom-modeline|set-special-modeline)
|