2017-02-03 19:44:14 -05:00
|
|
|
;;; ui/doom-modeline/config.el
|
2017-02-11 06:49:57 -05:00
|
|
|
|
2017-02-21 00:47:34 -05:00
|
|
|
(line-number-mode -1)
|
|
|
|
|
2017-01-31 05:09:39 -05:00
|
|
|
;; all-the-icons doesn't work in the terminal, so we "disable" it.
|
|
|
|
(unless (display-graphic-p)
|
2017-02-13 04:52:08 -05:00
|
|
|
(defalias 'all-the-icons-octicon 'ignore)
|
|
|
|
(defalias 'all-the-icons-faicon 'ignore)
|
|
|
|
(defalias 'all-the-icons-fileicon 'ignore)
|
|
|
|
(defalias 'all-the-icons-wicon 'ignore)
|
|
|
|
(defalias 'all-the-icons-alltheicon 'ignore))
|
2017-01-31 05:09:39 -05:00
|
|
|
|
2017-02-23 00:06:12 -05:00
|
|
|
(def-package! all-the-icons :demand t
|
2017-02-03 19:44:14 -05:00
|
|
|
:when (display-graphic-p))
|
|
|
|
|
2017-02-23 00:06:12 -05:00
|
|
|
(def-package! eldoc-eval :demand t
|
2017-02-03 19:44:14 -05:00
|
|
|
:config
|
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))
|
|
|
|
(mode-line-format (or (and str (doom-modeline 'eldoc))
|
|
|
|
mode-line-format))
|
|
|
|
mode-line-in-non-selected-windows)
|
|
|
|
(force-mode-line-update)
|
|
|
|
(sit-for eldoc-show-in-mode-line-delay))))
|
|
|
|
|
2017-01-31 05:09:39 -05:00
|
|
|
(setq eldoc-in-minibuffer-show-fn '+doom-modeline--show-eldoc)
|
|
|
|
(eldoc-in-minibuffer-mode +1))
|
|
|
|
|
2017-02-03 19:44:14 -05:00
|
|
|
;; anzu and evil-anzu make it possible to display current/total in the
|
|
|
|
;; mode-line.
|
2017-02-23 00:06:12 -05:00
|
|
|
(def-package! evil-anzu
|
2017-02-03 19:44:14 -05:00
|
|
|
:init
|
2017-03-02 01:43:00 -05: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
|
|
|
|
anzu-search-threshold 250))
|
|
|
|
|
2017-01-31 05:09:39 -05:00
|
|
|
|
|
|
|
;;; Flash the mode-line on error
|
|
|
|
;; TODO More flexible colors (only suits dark themes)
|
|
|
|
;; FIXME fast key-repeat can make the mode-line bg get stuck (rare)
|
2017-02-21 16:04:35 -05:00
|
|
|
(defvar doom--visual-bell-old-bg nil)
|
2017-01-31 05:09:39 -05:00
|
|
|
(setq ring-bell-function 'doom-visual-bell
|
|
|
|
visible-bell nil)
|
|
|
|
(defun doom-visual-bell ()
|
|
|
|
"Blink the mode-line red briefly."
|
2017-02-21 16:04:35 -05:00
|
|
|
(unless doom--visual-bell-old-bg
|
|
|
|
(setq doom--visual-bell-old-bg (face-attribute 'mode-line :background)))
|
2017-01-31 05:09:39 -05:00
|
|
|
(set-face-attribute 'mode-line nil :background "#54252C")
|
|
|
|
(run-with-timer
|
|
|
|
0.1 nil
|
2017-02-21 16:04:35 -05:00
|
|
|
(lambda () (set-face-attribute 'mode-line nil :background doom--visual-bell-old-bg))))
|
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"
|
|
|
|
(unless (minibuffer-window-active-p (frame-selected-window))
|
2017-02-13 04:52:08 -05:00
|
|
|
(setq +doom-modeline-current-window (frame-selected-window))))
|
|
|
|
|
|
|
|
(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-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)
|
|
|
|
"docstring")
|
|
|
|
|
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
|
|
|
|
'((t (:inherit mode-line :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
|
|
|
|
|
|
|
(defface doom-modeline-buffer-project
|
|
|
|
'((t (:inherit doom-modeline-buffer-path :bold nil)))
|
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
|
|
|
|
'((t (:inherit highlight :background nil)))
|
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
|
|
|
|
'((t (:inherit mode-line :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
|
|
|
|
'((t (:inherit mode-line)))
|
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
|
|
|
|
'((t (:inherit mode-line)))
|
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
|
|
|
|
`((t (:inherit success)))
|
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
|
|
|
|
`((t (:inherit warning)))
|
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
|
|
|
|
|
|
|
(defface doom-modeline-urgent `((t (:inherit error)))
|
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
|
|
|
|
(defface doom-modeline-bar '((t (:inherit highlight :foreground nil)))
|
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
|
|
|
|
|
|
|
(defface doom-modeline-eldoc-bar '((t (:inherit shadow :foreground nil)))
|
|
|
|
"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
|
|
|
|
|
|
|
(defface doom-modeline-inactive-bar '((t (:inherit mode-line-inactive)))
|
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)
|
|
|
|
(add-hook 'focus-in-hook '+doom-modeline|update-env)
|
|
|
|
(add-hook 'find-file-hook '+doom-modeline|update-env)
|
|
|
|
(defun +doom-modeline|update-env ()
|
|
|
|
(when +doom-modeline-env-command
|
|
|
|
(let* ((default-directory (doom-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-02-23 00:06:12 -05:00
|
|
|
(add-hook! python-mode (setq +doom-modeline-env-command "python --version 2>&1 | cut -d' ' -f2"))
|
|
|
|
(add-hook! ruby-mode (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."
|
|
|
|
(when (display-graphic-p)
|
|
|
|
(propertize
|
|
|
|
" " 'display
|
2017-02-13 04:52:08 -05:00
|
|
|
(let ((data (make-list height (make-list width 1)))
|
|
|
|
(i 0)
|
|
|
|
(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)
|
|
|
|
(let ((len (length data))
|
|
|
|
(idx 0))
|
|
|
|
(apply 'concat
|
|
|
|
(mapcar #'(lambda (dl)
|
|
|
|
(setq idx (+ idx 1))
|
|
|
|
(concat
|
|
|
|
"\""
|
|
|
|
(concat
|
|
|
|
(mapcar #'(lambda (d)
|
|
|
|
(if (eq d 0)
|
|
|
|
(string-to-char " ")
|
|
|
|
(string-to-char ".")))
|
|
|
|
dl))
|
2017-02-19 18:45:34 -05:00
|
|
|
(if (eq idx len) "\"};" "\",\n")))
|
2017-02-13 04:52:08 -05:00
|
|
|
data))))
|
|
|
|
'xpm t :ascent 'center)))))
|
2017-01-31 05:09:39 -05:00
|
|
|
|
|
|
|
(defun +doom-modeline--buffer-path ()
|
|
|
|
"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."
|
|
|
|
(if buffer-file-name
|
2017-03-02 00:43:25 -05:00
|
|
|
(let* ((default-directory (file-name-directory buffer-file-name))
|
|
|
|
(buffer-path (file-relative-name buffer-file-name (doom-project-root))))
|
|
|
|
(when (and buffer-path (not (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)))
|
|
|
|
(setq output (concat (car path) "/" output))
|
|
|
|
(setq path (cdr path)))
|
|
|
|
(when path
|
|
|
|
(setq output (concat "../" output)))
|
|
|
|
(when (string-suffix-p "/" output)
|
|
|
|
(setq output (substring output 0 -1)))
|
|
|
|
output)
|
|
|
|
buffer-path))))
|
2017-01-31 05:09:39 -05:00
|
|
|
"%b"))
|
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
;; 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-01-31 05:09:39 -05:00
|
|
|
(let ((face (if (active) 'doom-modeline-buffer-project)))
|
|
|
|
(concat (all-the-icons-octicon
|
|
|
|
"file-directory"
|
|
|
|
:face face
|
|
|
|
:v-adjust -0.05
|
|
|
|
:height 1.25)
|
|
|
|
(propertize (concat " " (abbreviate-file-name (doom-project-root)))
|
|
|
|
'face face))))
|
|
|
|
|
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)."
|
|
|
|
(let ((all-the-icons-scale-factor 1.2)
|
|
|
|
(modified-p (buffer-modified-p))
|
|
|
|
faces)
|
|
|
|
(if (active) (push 'doom-modeline-buffer-path faces))
|
|
|
|
(if modified-p (push 'doom-modeline-buffer-modified faces))
|
|
|
|
(concat (if buffer-read-only
|
|
|
|
(concat (all-the-icons-octicon
|
|
|
|
"lock"
|
|
|
|
:face 'doom-modeline-warning
|
|
|
|
:v-adjust -0.05)
|
|
|
|
" ")
|
|
|
|
(when modified-p
|
|
|
|
(concat
|
|
|
|
(all-the-icons-faicon "floppy-o"
|
|
|
|
:face 'doom-modeline-buffer-modified
|
|
|
|
:v-adjust -0.1)
|
|
|
|
" ")))
|
|
|
|
(when (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)
|
|
|
|
" "))
|
|
|
|
(propertize (+doom-modeline--buffer-path)
|
|
|
|
'face (if faces `(:inherit ,faces))))))
|
|
|
|
|
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-01-31 05:09:39 -05:00
|
|
|
(concat (let ((eol-type (coding-system-eol-type buffer-file-coding-system)))
|
|
|
|
(cond ((eq eol-type 0) "LF ")
|
|
|
|
((eq eol-type 1) "CRLF ")
|
|
|
|
((eq eol-type 2) "CR ")))
|
|
|
|
(let* ((sys (coding-system-plist buffer-file-coding-system))
|
|
|
|
(sys-name (plist-get sys :name))
|
|
|
|
(sys-cat (plist-get sys :category)))
|
|
|
|
(cond ((memq sys-cat '(coding-category-undecided coding-category-utf-8))
|
|
|
|
"UTF-8")
|
|
|
|
(t (upcase (symbol-name sys-name)))))
|
|
|
|
" "))
|
|
|
|
|
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)
|
|
|
|
(if (stringp mode-line-process) mode-line-process)
|
|
|
|
(if +doom-modeline-env-version (concat " " +doom-modeline-env-version))
|
|
|
|
(and (featurep 'face-remap)
|
|
|
|
(/= text-scale-mode-amount 0)
|
|
|
|
(format " (%+d)" text-scale-mode-amount)))
|
|
|
|
'face (if (active) 'doom-modeline-buffer-major-mode)))
|
|
|
|
|
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-03-02 00:43:25 -05:00
|
|
|
(when vc-mode
|
2017-01-31 05:09:39 -05:00
|
|
|
(let ((backend (vc-backend buffer-file-name))
|
|
|
|
(state (vc-state buffer-file-name))
|
|
|
|
(face 'mode-line-inactive)
|
|
|
|
(active (active))
|
|
|
|
(all-the-icons-scale-factor 1.0)
|
|
|
|
(all-the-icons-default-adjust -0.1))
|
2017-02-11 06:49:57 -05:00
|
|
|
(concat +doom-modeline-vspc
|
2017-01-31 05:09:39 -05:00
|
|
|
(cond ((memq state '(edited added))
|
|
|
|
(if active (setq face 'doom-modeline-info))
|
|
|
|
(all-the-icons-octicon
|
|
|
|
"git-branch"
|
|
|
|
: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 'mode-line))
|
|
|
|
(all-the-icons-octicon
|
|
|
|
"git-branch"
|
|
|
|
: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
|
|
|
+doom-modeline-vspc))))
|
|
|
|
|
|
|
|
(defun +doom-ml-icon (icon &optional text face)
|
|
|
|
"Displays an octicon ICON with FACE, followed by TEXT. Uses
|
|
|
|
`all-the-icons-octicon' to fetch the icon."
|
|
|
|
(concat
|
|
|
|
" "
|
|
|
|
(when icon
|
|
|
|
(concat
|
|
|
|
(all-the-icons-octicon icon :face face :height 1.0 :v-adjust 0)
|
|
|
|
(when text
|
|
|
|
(propertize " " 'face 'variable-pitch))))
|
|
|
|
(when text
|
|
|
|
(propertize text 'face face))))
|
|
|
|
|
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))))
|
|
|
|
(+doom-ml-icon "circle-slash" (format "%s issue%s" sum (if (eq 1 sum) "" "s"))
|
|
|
|
(if .error 'doom-modeline-urgent 'doom-modeline-warning))))
|
|
|
|
(concat
|
|
|
|
(+doom-ml-icon "check" nil 'doom-modeline-info) " ")))
|
2017-03-02 00:43:25 -05:00
|
|
|
('running (+doom-ml-icon "ellipsis" "Running" 'font-lock-doc-face))
|
|
|
|
('no-checker (+doom-ml-icon "alert" "-" 'font-lock-doc-face))
|
|
|
|
('errored (+doom-ml-icon "alert" "Error" 'doom-modeline-urgent))
|
|
|
|
('interrupted (+doom-ml-icon "x" "Interrupted" 'font-lock-doc-face))
|
|
|
|
;; ('suspicious "")
|
2017-02-11 06:49:57 -05:00
|
|
|
)))
|
|
|
|
|
|
|
|
(defsubst doom-column (pos)
|
|
|
|
(save-excursion
|
|
|
|
(when pos (goto-char pos))
|
|
|
|
(current-column)))
|
|
|
|
|
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-02-11 06:49:57 -05:00
|
|
|
(when mark-active
|
|
|
|
(let ((evil-p (featurep 'evil)))
|
|
|
|
(concat
|
|
|
|
" "
|
|
|
|
(propertize
|
|
|
|
(let ((reg-beg (region-beginning))
|
|
|
|
(reg-end (region-end))
|
|
|
|
(evil (and evil-p (eq 'visual evil-state))))
|
|
|
|
(let ((lines (count-lines reg-beg (min (1+ reg-end) (point-max))))
|
|
|
|
(chars (- (1+ reg-end) reg-beg))
|
|
|
|
(cols (1+ (abs (- (doom-column reg-end)
|
|
|
|
(doom-column reg-beg))))))
|
|
|
|
(cond
|
|
|
|
;; rectangle selection
|
|
|
|
((or (bound-and-true-p rectangle-mark-mode)
|
|
|
|
(and evil (eq 'block evil-visual-selection)))
|
|
|
|
(format " %dx%dB " lines (if evil cols (1- cols))))
|
|
|
|
;; line selection
|
|
|
|
((or (> lines 1) (eq 'line evil-visual-selection))
|
|
|
|
(if (and (eq evil-state 'visual) (eq evil-this-type 'line))
|
|
|
|
(format " %dL " lines)
|
|
|
|
(format " %dC %dL " chars lines)))
|
|
|
|
(t (format " %dC " (if evil chars (1- chars)))))))
|
|
|
|
'face 'doom-modeline-highlight)))))
|
|
|
|
|
|
|
|
|
|
|
|
(defun +doom-modeline--macro-recording ()
|
2017-01-31 05:09:39 -05:00
|
|
|
"Display current macro being recorded."
|
2017-02-19 18:45:34 -05:00
|
|
|
(when (and (active) (bound-and-true-p evil-this-macro))
|
2017-01-31 05:09:39 -05:00
|
|
|
(let ((sep (propertize " " 'face 'doom-modeline-panel)))
|
|
|
|
(concat sep
|
|
|
|
(propertize (char-to-string evil-this-macro)
|
|
|
|
'face 'doom-modeline-panel)
|
|
|
|
sep
|
|
|
|
(all-the-icons-octicon "triangle-right"
|
|
|
|
:face 'doom-modeline-panel
|
|
|
|
:v-adjust -0.05)
|
|
|
|
sep))))
|
|
|
|
|
|
|
|
(make-variable-buffer-local 'anzu--state)
|
2017-02-11 06:49:57 -05:00
|
|
|
(defsubst +doom-modeline--anzu ()
|
2017-01-31 05:09:39 -05:00
|
|
|
"Show the match index and total number thereof. Requires `evil-anzu'."
|
2017-02-19 18:45:34 -05:00
|
|
|
(when (and (bound-and-true-p anzu--current-position)
|
|
|
|
(evil-ex-hl-active-p 'evil-ex-search))
|
2017-01-31 05:09:39 -05:00
|
|
|
(propertize
|
|
|
|
(format " %s/%d%s "
|
|
|
|
anzu--current-position anzu--total-matched
|
|
|
|
(if anzu--overflow-p "+" ""))
|
|
|
|
'face (if (active) 'doom-modeline-panel))))
|
|
|
|
|
2017-02-11 06:49:57 -05:00
|
|
|
(defsubst +doom-modeline--evil-substitute ()
|
2017-01-31 05:09:39 -05:00
|
|
|
"Show number of :s matches in real time."
|
2017-02-19 18:45:34 -05:00
|
|
|
(when (and (featurep 'evil)
|
|
|
|
(evil-ex-p) (or (evil-ex-hl-active-p 'evil-ex-substitute)
|
2017-02-11 06:49:57 -05:00
|
|
|
(evil-ex-hl-active-p 'evil-ex-global-match)
|
|
|
|
(evil-ex-hl-active-p 'evil-ex-buffer-match)))
|
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
|
|
|
|
(format " %s matches "
|
2017-02-13 04:52:08 -05:00
|
|
|
(count-matches pattern (car range) (cdr range)))
|
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--iedit ()
|
2017-01-31 05:09:39 -05:00
|
|
|
"Show the number of iedit regions matches + what match you're on."
|
2017-02-19 18:45:34 -05:00
|
|
|
(when (and (featurep 'iedit) iedit-mode)
|
2017-01-31 05:09:39 -05:00
|
|
|
(propertize
|
|
|
|
(let ((this-oc (let (message-log-max) (iedit-find-current-occurrence-overlay)))
|
2017-02-11 06:49:57 -05:00
|
|
|
(length (or (ignore-errors (length iedit-occurrences-overlays)) 0)))
|
|
|
|
(format " %s/%s "
|
|
|
|
(save-excursion
|
|
|
|
(unless this-oc
|
|
|
|
(iedit-prev-occurrence)
|
|
|
|
(setq this-oc (iedit-find-current-occurrence-overlay)))
|
|
|
|
(if this-oc
|
|
|
|
;; NOTE: Not terribly reliable
|
|
|
|
(- length (-elem-index this-oc iedit-occurrences-overlays))
|
|
|
|
"-"))
|
|
|
|
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-02-11 06:49:57 -05:00
|
|
|
"TODO"
|
2017-02-19 18:45:34 -05:00
|
|
|
(or (concat (+doom-modeline--macro-recording)
|
|
|
|
(+doom-modeline--anzu)
|
|
|
|
(+doom-modeline--evil-substitute)
|
|
|
|
(+doom-modeline--iedit))
|
2017-02-11 06:49:57 -05:00
|
|
|
" %I "))
|
|
|
|
|
2017-02-23 00:06:12 -05:00
|
|
|
(def-modeline-segment! media-info
|
2017-02-03 19:44:14 -05:00
|
|
|
"TODO"
|
2017-01-31 05:09:39 -05:00
|
|
|
(cond ((eq major-mode 'image-mode)
|
|
|
|
(let ((size (image-size (image-get-display-property) :pixels)))
|
|
|
|
(format " %dx%d " (car size) (cdr size))))))
|
|
|
|
|
2017-02-23 00:06:12 -05:00
|
|
|
(def-modeline-segment! eldoc
|
2017-02-11 06:49:57 -05:00
|
|
|
"TODO"
|
|
|
|
(and (boundp 'str) str))
|
|
|
|
|
2017-02-13 04:52:08 -05:00
|
|
|
;;
|
2017-02-23 00:06:12 -05:00
|
|
|
(def-modeline-segment! bar
|
2017-02-11 06:49:57 -05:00
|
|
|
(+doom-modeline--make-xpm
|
|
|
|
(face-background (if (active)
|
|
|
|
'doom-modeline-bar
|
|
|
|
'doom-modeline-inactive-bar))
|
|
|
|
+doom-modeline-height
|
|
|
|
+doom-modeline-bar-width))
|
|
|
|
|
2017-02-23 00:06:12 -05:00
|
|
|
(def-modeline-segment! eldoc-bar
|
2017-02-11 06:49:57 -05:00
|
|
|
(+doom-modeline--make-xpm
|
|
|
|
(face-background 'doom-modeline-eldoc-bar)
|
|
|
|
+doom-modeline-height
|
|
|
|
+doom-modeline-bar-width))
|
|
|
|
|
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)
|
|
|
|
(buffer-encoding vcs major-mode flycheck))
|
|
|
|
|
2017-02-23 00:06:12 -05:00
|
|
|
(def-modeline! eldoc
|
2017-02-11 06:49:57 -05:00
|
|
|
(eldoc-bar " " eldoc)
|
|
|
|
(media-info major-mode))
|
|
|
|
|
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-02-23 00:06:12 -05:00
|
|
|
(def-modeline! project
|
2017-02-20 16:33:28 -05:00
|
|
|
(bar " " buffer-project)
|
2017-02-11 06:49:57 -05:00
|
|
|
(major-mode))
|
2017-01-31 05:09:39 -05:00
|
|
|
|
|
|
|
;;
|
2017-02-11 06:49:57 -05:00
|
|
|
(setq-default mode-line-format (doom-modeline 'main))
|
|
|
|
|
|
|
|
;; 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*"
|
|
|
|
(setq mode-line-format (doom-modeline 'main)))
|
|
|
|
|
|
|
|
|
2017-01-31 05:09:39 -05:00
|
|
|
|