2017-01-16 23:15:48 -05:00
|
|
|
;;; core-modeline.el --- make mode-lines sexy again
|
2016-09-08 00:15:24 +02:00
|
|
|
|
2017-01-16 23:15:48 -05:00
|
|
|
;; This file tries to be a self-contained configuration of my mode-line.
|
2016-10-04 22:53:25 +02:00
|
|
|
|
|
|
|
;;; These are the invisible dependencies
|
|
|
|
;; Required
|
|
|
|
;;(require 'f)
|
|
|
|
;;(require 's)
|
|
|
|
;;(require 'evil)
|
|
|
|
;;(require 'projectile)
|
|
|
|
;;(require 'all-the-icons)
|
|
|
|
|
|
|
|
;; Optional
|
|
|
|
;;(require 'flycheck)
|
|
|
|
;;(require 'anzu)
|
|
|
|
;;(require 'evil-anzu)
|
|
|
|
;;(require 'iedit)
|
|
|
|
;;(require 'evil-multiedit)
|
|
|
|
|
2017-01-16 23:15:48 -05:00
|
|
|
(package! powerline)
|
|
|
|
|
|
|
|
(package! all-the-icons :demand t)
|
|
|
|
|
|
|
|
(package! eldoc-eval :demand t
|
|
|
|
:config
|
|
|
|
(setq eldoc-in-minibuffer-show-fn 'doom-eldoc-show-in-mode-line)
|
|
|
|
(eldoc-in-minibuffer-mode +1))
|
|
|
|
|
2016-10-06 17:27:47 +02:00
|
|
|
|
|
|
|
|
2016-10-04 22:53:25 +02:00
|
|
|
|
2016-09-08 00:31:30 +02:00
|
|
|
;;
|
2016-10-04 22:53:25 +02:00
|
|
|
;; Variables
|
2016-09-08 00:31:30 +02:00
|
|
|
;;
|
2016-09-08 00:15:24 +02:00
|
|
|
|
2017-01-16 23:15:48 -05:00
|
|
|
(defvar doom-modeline-formats '()
|
|
|
|
"")
|
|
|
|
|
2016-10-07 22:21:40 +02:00
|
|
|
(defvar doom-modeline-height 29
|
2016-10-04 22:53:25 +02:00
|
|
|
"How tall the mode-line should be (only respected in GUI emacs).")
|
2016-09-08 00:15:24 +02:00
|
|
|
|
2016-10-07 22:21:40 +02:00
|
|
|
(defvar doom-modeline-bar-width 3
|
2016-10-04 22:53:25 +02:00
|
|
|
"How wide the mode-line bar should be (only respected in GUI emacs).")
|
2016-09-28 13:54:21 +02:00
|
|
|
|
2016-10-04 22:53:25 +02:00
|
|
|
|
|
|
|
;;
|
2016-09-08 00:15:24 +02:00
|
|
|
;; Custom faces
|
2016-10-04 22:53:25 +02:00
|
|
|
;;
|
|
|
|
|
2017-01-16 23:15:48 -05:00
|
|
|
(defface doom-modeline-buffer-path
|
|
|
|
'((t (:inherit mode-line :bold t)))
|
2016-10-04 22:53:25 +02:00
|
|
|
"Face used for the dirname part of the buffer path.")
|
|
|
|
|
|
|
|
(defface doom-modeline-buffer-project
|
|
|
|
'((t (:inherit doom-modeline-buffer-path :bold nil)))
|
|
|
|
"Face used for the filename part of the mode-line buffer path.")
|
|
|
|
|
2017-01-16 23:15:48 -05:00
|
|
|
(defface doom-modeline-buffer-modified
|
|
|
|
'((t (:inherit highlight :background nil)))
|
2016-10-04 22:53:25 +02:00
|
|
|
"Face used for the 'unsaved' symbol in the mode-line.")
|
|
|
|
|
2017-01-16 23:15:48 -05:00
|
|
|
(defface doom-modeline-buffer-major-mode
|
|
|
|
'((t (:inherit mode-line :bold t)))
|
2016-10-04 22:53:25 +02:00
|
|
|
"Face used for the major-mode segment in the mode-line.")
|
|
|
|
|
2017-01-16 23:15:48 -05:00
|
|
|
(defface doom-modeline-highlight
|
|
|
|
'((t (:inherit mode-line)))
|
2016-09-08 00:15:24 +02:00
|
|
|
"Face for bright segments of the mode-line.")
|
|
|
|
|
2017-01-16 23:15:48 -05:00
|
|
|
(defface doom-modeline-panel
|
|
|
|
'((t (:inherit mode-line)))
|
2016-09-19 17:45:37 +02:00
|
|
|
"Face for 'X out of Y' segments, such as `*anzu', `*evil-substitute' and
|
|
|
|
`iedit'")
|
|
|
|
|
2017-01-16 23:15:48 -05:00
|
|
|
(defface doom-modeline-info
|
|
|
|
`((t (:inherit success)))
|
2016-10-04 22:53:25 +02:00
|
|
|
"Face for info-level messages in the modeline. Used by `*vc'.")
|
|
|
|
|
2017-01-16 23:15:48 -05:00
|
|
|
(defface doom-modeline-warning
|
|
|
|
`((t (:inherit warning)))
|
2016-10-04 22:53:25 +02:00
|
|
|
"Face for warnings in the modeline. Used by `*flycheck'")
|
|
|
|
|
|
|
|
(defface doom-modeline-urgent `((t (:inherit error)))
|
|
|
|
"Face for errors in the modeline. Used by `*flycheck'")
|
|
|
|
|
|
|
|
;; Bar
|
|
|
|
(defface doom-modeline-bar '((t (:inherit highlight :foreground nil)))
|
2016-09-19 17:45:37 +02:00
|
|
|
"The face used for the left-most bar on the mode-line of an active window.")
|
|
|
|
|
2016-10-04 22:53:25 +02:00
|
|
|
(defface doom-modeline-eldoc-bar '((t (:inherit shadow :foreground nil)))
|
2016-09-19 17:45:37 +02:00
|
|
|
"The face used for the left-most bar on the mode-line when eldoc-eval is
|
|
|
|
active.")
|
|
|
|
|
|
|
|
(defface doom-modeline-inactive-bar '((t (:inherit mode-line-inactive)))
|
|
|
|
"The face used for the left-most bar on the mode-line of an inactive window.")
|
|
|
|
|
2016-09-08 00:15:24 +02:00
|
|
|
|
|
|
|
;;
|
2017-01-16 23:15:48 -05:00
|
|
|
;; Bootstrap
|
2016-09-08 00:15:24 +02:00
|
|
|
;;
|
|
|
|
|
2017-01-16 23:15:48 -05:00
|
|
|
;; all-the-icons doesn't work in the terminal, so we "disable" it.
|
|
|
|
(unless window-system
|
|
|
|
(defun all-the-icons-octicon (&rest _) "" "")
|
|
|
|
(defun all-the-icons-faicon (&rest _) "" "")
|
|
|
|
(defun all-the-icons-fileicon (&rest _) "" "")
|
|
|
|
(defun all-the-icons-wicon (&rest _) "" "")
|
|
|
|
(defun all-the-icons-alltheicon (&rest _) "" ""))
|
2016-09-08 00:15:24 +02:00
|
|
|
|
2017-01-16 23:15:48 -05:00
|
|
|
(defmacro modeline! (name &rest def)
|
|
|
|
(declare (indent defun))) ;; TODO
|
2016-09-08 00:15:24 +02:00
|
|
|
|
2017-01-16 23:15:48 -05:00
|
|
|
(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))
|
2016-10-04 22:53:25 +02:00
|
|
|
(s (shell-command-to-string doom-ml--env-command)))
|
2017-01-16 23:15:48 -05:00
|
|
|
(setq doom-modeline-env-version (if (string-match "[ \t\n\r]+\\'" s)
|
|
|
|
(replace-match "" t t s)
|
|
|
|
s)))))
|
2016-09-08 00:15:24 +02:00
|
|
|
|
2017-01-16 23:15:48 -05:00
|
|
|
(doom-define-setting 'env
|
|
|
|
"Command used to set the interpreter version in the current buffer."
|
|
|
|
:type '(stringp functionp)
|
|
|
|
:hook (lambda (command) (setq doom-modeline-env-command x)))
|
2016-09-08 00:15:24 +02:00
|
|
|
|
2017-01-16 23:15:48 -05:00
|
|
|
;; (set! python-mode :env "python --version 2>&1 | cut -d' ' -f2")
|
|
|
|
;; (set! ruby-mode :env "ruby --version 2>&1 | cut -d' ' -f2")
|
2016-09-08 00:15:24 +02:00
|
|
|
|
2017-01-16 23:15:48 -05:00
|
|
|
(defsubst active() (eq (selected-window) powerline-selected-window))
|
2016-09-08 00:15:24 +02:00
|
|
|
|
2016-10-04 22:53:25 +02:00
|
|
|
(defun doom-ml-flycheck-count (state)
|
|
|
|
"Return flycheck information for the given error type STATE."
|
|
|
|
(when (flycheck-has-current-errors-p state)
|
|
|
|
(if (eq 'running flycheck-last-status-change)
|
|
|
|
"?"
|
|
|
|
(cdr-safe (assq state (flycheck-count-errors flycheck-current-errors))))))
|
|
|
|
|
2016-09-28 13:54:21 +02:00
|
|
|
(defun doom-make-xpm (color height width)
|
|
|
|
"Create an XPM bitmap."
|
2017-01-16 23:15:48 -05:00
|
|
|
(unless (featurep 'powerline)
|
|
|
|
(require 'powerline)
|
|
|
|
(pl/memoize 'doom-make-xpm))
|
2016-10-06 14:16:28 +02:00
|
|
|
(when window-system
|
|
|
|
(propertize
|
|
|
|
" " 'display
|
|
|
|
(let ((data nil)
|
|
|
|
(i 0))
|
|
|
|
(setq data (make-list height (make-list width 1)))
|
|
|
|
(pl/make-xpm "percent" color color (reverse data))))))
|
2016-09-28 13:54:21 +02:00
|
|
|
|
2016-10-04 22:53:25 +02:00
|
|
|
(defun doom-buffer-path ()
|
2016-09-08 00:15:24 +02:00
|
|
|
"Displays the buffer's full path relative to the project root (includes the
|
2016-10-04 22:53:25 +02:00
|
|
|
project root). Excludes the file basename. See `doom-buffer-name' for that."
|
2016-10-05 12:50:36 +02:00
|
|
|
(if buffer-file-name
|
2016-10-04 23:40:46 +02:00
|
|
|
(let* ((default-directory (f-dirname buffer-file-name))
|
2017-01-16 23:15:48 -05:00
|
|
|
(buffer-path (f-relative buffer-file-name (doom-project-root)))
|
2016-10-04 23:40:46 +02:00
|
|
|
(max-length (truncate (* (window-body-width) 0.4))))
|
2016-10-04 22:53:25 +02:00
|
|
|
(when (and buffer-path (not (equal buffer-path ".")))
|
2016-10-04 23:40:46 +02:00
|
|
|
(if (> (length buffer-path) max-length)
|
|
|
|
(let ((path (reverse (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)
|
2016-10-05 12:50:36 +02:00
|
|
|
buffer-path)))
|
|
|
|
"%b"))
|
2016-09-08 00:15:24 +02:00
|
|
|
|
2017-01-16 23:15:48 -05:00
|
|
|
(defun doom-eldoc-show-in-mode-line (input)
|
|
|
|
"Display string STR in the mode-line next to minibuffer."
|
|
|
|
(with-current-buffer (eldoc-current-buffer)
|
|
|
|
(let* ((max (window-width (selected-window)))
|
|
|
|
(str (and (stringp input) (concat " " input)))
|
|
|
|
(len (length str))
|
|
|
|
(tmp-str str)
|
|
|
|
(mode-line-format (or (and str (doom-eldoc-modeline))
|
|
|
|
mode-line-format))
|
|
|
|
roll mode-line-in-non-selected-windows)
|
|
|
|
(catch 'break
|
|
|
|
(if (and (> len max) eldoc-mode-line-rolling-flag)
|
|
|
|
(progn
|
|
|
|
(while (setq roll (sit-for 0.3))
|
|
|
|
(setq tmp-str (substring tmp-str 2)
|
|
|
|
mode-line-format (concat tmp-str " [<]" str))
|
|
|
|
(force-mode-line-update)
|
|
|
|
(when (< (length tmp-str) 2) (setq tmp-str str)))
|
|
|
|
(unless roll
|
|
|
|
(when eldoc-mode-line-stop-rolling-on-input
|
|
|
|
(setq eldoc-mode-line-rolling-flag nil))
|
|
|
|
(throw 'break nil)))
|
|
|
|
(force-mode-line-update)
|
|
|
|
(sit-for eldoc-show-in-mode-line-delay))))
|
|
|
|
(force-mode-line-update)))
|
2016-10-06 14:16:28 +02:00
|
|
|
|
2016-10-04 22:53:25 +02:00
|
|
|
|
|
|
|
;;
|
2017-01-16 23:15:48 -05:00
|
|
|
;; Segments
|
2016-10-04 22:53:25 +02:00
|
|
|
;;
|
|
|
|
|
2016-09-23 16:08:52 +02:00
|
|
|
(defun *buffer-project ()
|
2016-09-08 00:15:24 +02:00
|
|
|
"Displays `default-directory', for special buffers like the scratch buffer."
|
2016-10-06 14:16:28 +02: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)
|
2017-01-16 23:15:48 -05:00
|
|
|
(propertize (concat " " (abbreviate-file-name (doom-project-root)))
|
2016-10-06 14:16:28 +02:00
|
|
|
'face face))))
|
2016-09-23 16:08:52 +02:00
|
|
|
|
|
|
|
(defun *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)."
|
2016-10-04 22:53:25 +02:00
|
|
|
(let ((all-the-icons-scale-factor 1.2)
|
2016-10-05 12:51:09 +02:00
|
|
|
(modified-p (buffer-modified-p))
|
|
|
|
faces)
|
2016-10-06 14:16:28 +02:00
|
|
|
(if (active) (push 'doom-modeline-buffer-path faces))
|
2016-10-05 12:51:09 +02:00
|
|
|
(if modified-p (push 'doom-modeline-buffer-modified faces))
|
2016-10-04 22:53:25 +02:00
|
|
|
(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)
|
|
|
|
" "))
|
2016-10-04 23:40:46 +02:00
|
|
|
(propertize (doom-buffer-path)
|
2016-10-06 14:16:28 +02:00
|
|
|
'face (if faces `(:inherit ,faces))))))
|
2016-10-04 22:53:25 +02:00
|
|
|
|
|
|
|
(defun *buffer-encoding ()
|
|
|
|
"The encoding and eol style of the buffer."
|
|
|
|
(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 ")))
|
2016-12-31 03:04:06 -05:00
|
|
|
(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)))))
|
2016-10-04 22:53:25 +02:00
|
|
|
" "))
|
2016-09-08 00:15:24 +02:00
|
|
|
|
|
|
|
(defun *major-mode ()
|
|
|
|
"The major mode, including process, environment and text-scale info."
|
2016-09-23 16:08:52 +02:00
|
|
|
(propertize
|
2016-10-04 22:53:25 +02:00
|
|
|
(concat (format-mode-line mode-name)
|
2016-09-23 16:08:52 +02:00
|
|
|
(if (stringp mode-line-process) mode-line-process)
|
2017-01-16 23:15:48 -05:00
|
|
|
(if doom-modeline-env-version (concat " " doom-modeline-env-version))
|
2016-09-23 16:08:52 +02:00
|
|
|
(and (featurep 'face-remap)
|
|
|
|
(/= text-scale-mode-amount 0)
|
2016-10-04 22:53:25 +02:00
|
|
|
(format " (%+d)" text-scale-mode-amount)))
|
2016-11-04 03:30:32 +01:00
|
|
|
'face (if (active) 'doom-modeline-buffer-major-mode)))
|
2016-09-08 00:15:24 +02:00
|
|
|
|
|
|
|
(defun *vc ()
|
|
|
|
"Displays the current branch, colored based on its state."
|
2017-01-07 02:53:02 -05:00
|
|
|
(when (and vc-mode buffer-file-name)
|
2016-10-06 14:16:28 +02:00
|
|
|
(let ((backend (vc-backend buffer-file-name))
|
|
|
|
(state (vc-state buffer-file-name))
|
2016-10-04 22:53:25 +02:00
|
|
|
(face 'mode-line-inactive)
|
2016-10-06 14:16:28 +02:00
|
|
|
(active (active))
|
2016-10-04 23:48:10 +02:00
|
|
|
(all-the-icons-scale-factor 1.0)
|
2016-10-04 22:53:25 +02:00
|
|
|
(all-the-icons-default-adjust -0.1))
|
|
|
|
(concat (propertize " " 'face 'variable-pitch)
|
|
|
|
(cond ((memq state '(edited added))
|
|
|
|
(if active (setq face 'doom-modeline-info))
|
|
|
|
(all-the-icons-octicon
|
|
|
|
"git-branch"
|
|
|
|
:face face
|
2016-10-04 23:48:10 +02:00
|
|
|
:height 1.2
|
2016-10-04 22:53:25 +02:00
|
|
|
:v-adjust -0.05))
|
|
|
|
((eq state 'needs-merge)
|
|
|
|
(if active (setq face 'doom-modeline-info))
|
2016-10-04 23:48:10 +02:00
|
|
|
(all-the-icons-octicon "git-merge" :face face))
|
2016-10-04 22:53:25 +02:00
|
|
|
((eq state 'needs-update)
|
|
|
|
(if active (setq face 'doom-modeline-warning))
|
2016-10-04 23:48:10 +02:00
|
|
|
(all-the-icons-octicon "arrow-down" :face face))
|
2016-10-04 22:53:25 +02:00
|
|
|
((memq state '(removed conflict unregistered))
|
|
|
|
(if active (setq face 'doom-modeline-urgent))
|
2016-10-04 23:48:10 +02:00
|
|
|
(all-the-icons-octicon "alert" :face face))
|
2016-10-04 22:53:25 +02:00
|
|
|
(t
|
|
|
|
(if active (setq face 'mode-line))
|
|
|
|
(all-the-icons-octicon
|
|
|
|
"git-branch"
|
2016-10-04 23:48:10 +02:00
|
|
|
:face face
|
|
|
|
:height 1.2
|
|
|
|
:v-adjust -0.05)))
|
2016-10-06 14:16:28 +02:00
|
|
|
" "
|
|
|
|
(propertize (substring vc-mode (+ (if (eq backend 'Hg) 2 3) 2))
|
|
|
|
'face (if active face))
|
2016-10-24 02:47:14 +02:00
|
|
|
" "
|
|
|
|
(propertize " " 'face 'variable-pitch)))))
|
2016-09-08 00:15:24 +02:00
|
|
|
|
|
|
|
(defvar-local doom--flycheck-err-cache nil "")
|
|
|
|
(defvar-local doom--flycheck-cache nil "")
|
|
|
|
(defun *flycheck ()
|
|
|
|
"Persistent and cached flycheck indicators in the mode-line."
|
2016-09-19 17:45:37 +02:00
|
|
|
(when (and (featurep 'flycheck) flycheck-mode)
|
|
|
|
(if (or flycheck-current-errors
|
|
|
|
(eq 'running flycheck-last-status-change))
|
|
|
|
(or (and (or (eq doom--flycheck-err-cache doom--flycheck-cache)
|
|
|
|
(memq flycheck-last-status-change '(running not-checked)))
|
2016-10-04 22:53:25 +02:00
|
|
|
(if (eq flycheck-last-status-change 'running)
|
2016-10-06 17:28:08 +02:00
|
|
|
(concat " "
|
|
|
|
(all-the-icons-octicon
|
|
|
|
"ellipsis"
|
|
|
|
:face 'font-lock-doc-face
|
|
|
|
:height 1.1
|
|
|
|
:v-adjust 0)
|
|
|
|
" ")
|
2016-10-04 22:53:25 +02:00
|
|
|
doom--flycheck-cache))
|
2016-09-19 17:45:37 +02:00
|
|
|
(and (setq doom--flycheck-err-cache flycheck-current-errors)
|
|
|
|
(setq doom--flycheck-cache
|
2016-09-23 16:08:52 +02:00
|
|
|
(let ((fw (doom-ml-flycheck-count 'warning))
|
|
|
|
(fe (doom-ml-flycheck-count 'error)))
|
2017-01-03 22:51:10 -05:00
|
|
|
(concat (if (or fe fw) " ")
|
2016-11-04 03:30:45 +01:00
|
|
|
(if fe (concat
|
2016-10-06 17:28:08 +02:00
|
|
|
(all-the-icons-octicon "circle-slash" :face 'doom-modeline-urgent :height 1.0 :v-adjust 0)
|
|
|
|
(propertize " " 'face 'variable-pitch)
|
2016-11-04 03:30:45 +01:00
|
|
|
(propertize (format "%d" fe) 'face 'doom-modeline-urgent)
|
2016-10-06 17:28:08 +02:00
|
|
|
" "
|
2016-11-04 03:30:45 +01:00
|
|
|
))
|
|
|
|
(if fw (concat
|
2016-10-06 17:28:08 +02:00
|
|
|
(all-the-icons-octicon "alert" :face 'doom-modeline-warning :height 0.9 :v-adjust 0)
|
|
|
|
(propertize " " 'face 'variable-pitch)
|
|
|
|
(propertize (format "%d" fw) 'face 'doom-modeline-warning)
|
2016-11-04 03:30:45 +01:00
|
|
|
" "
|
2016-10-06 17:28:08 +02:00
|
|
|
))
|
2016-11-04 03:30:45 +01:00
|
|
|
(if (or fe fw)
|
2017-01-03 22:51:10 -05:00
|
|
|
" "
|
2016-10-06 14:16:28 +02:00
|
|
|
(when (active)
|
2016-10-04 22:53:25 +02:00
|
|
|
(all-the-icons-octicon "check" :height 1.2 :v-adjust -0.06))))))))
|
2016-09-23 16:08:52 +02:00
|
|
|
(concat
|
2017-01-03 22:51:10 -05:00
|
|
|
" "
|
2016-10-04 22:53:25 +02:00
|
|
|
(all-the-icons-octicon "check"
|
2016-10-06 14:16:28 +02:00
|
|
|
:face (if (active) 'doom-modeline-info)
|
2016-10-04 22:53:25 +02:00
|
|
|
:height 1.2
|
2016-10-06 17:28:08 +02:00
|
|
|
:v-adjust -0.06)
|
|
|
|
" "))))
|
2016-09-08 00:15:24 +02:00
|
|
|
|
|
|
|
(defun *selection-info ()
|
|
|
|
"Information about the current selection, such as how many characters and
|
|
|
|
lines are selected, or the NxM dimensions of a block selection."
|
2016-10-06 14:16:28 +02:00
|
|
|
(when (and (active) (evil-visual-state-p))
|
2016-10-04 22:53:25 +02:00
|
|
|
(concat
|
|
|
|
" "
|
|
|
|
(propertize
|
|
|
|
(let ((reg-beg (region-beginning))
|
|
|
|
(reg-end (region-end))
|
|
|
|
(evil (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 (- (evil-column reg-end)
|
|
|
|
(evil-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))))
|
2016-09-08 00:15:24 +02:00
|
|
|
|
|
|
|
(defun *macro-recording ()
|
|
|
|
"Display current macro being recorded."
|
2016-10-06 14:16:28 +02:00
|
|
|
(when (and (active) defining-kbd-macro)
|
2016-10-04 22:53:25 +02: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))))
|
2016-09-08 00:15:24 +02:00
|
|
|
|
|
|
|
(make-variable-buffer-local 'anzu--state)
|
|
|
|
(defun *anzu ()
|
2016-10-04 22:53:25 +02:00
|
|
|
"Show the match index and total number thereof. Requires `evil-anzu'."
|
2016-09-08 00:15:24 +02:00
|
|
|
(when (and (featurep 'evil-anzu) (evil-ex-hl-active-p 'evil-ex-search))
|
|
|
|
(propertize
|
|
|
|
(format " %s/%d%s "
|
|
|
|
anzu--current-position anzu--total-matched
|
|
|
|
(if anzu--overflow-p "+" ""))
|
2016-10-06 14:16:28 +02:00
|
|
|
'face (if (active) 'doom-modeline-panel))))
|
2016-09-08 00:15:24 +02:00
|
|
|
|
|
|
|
(defun *evil-substitute ()
|
|
|
|
"Show number of :s matches in real time."
|
|
|
|
(when (and (evil-ex-p) (evil-ex-hl-active-p 'evil-ex-substitute))
|
|
|
|
(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 "
|
|
|
|
(count-matches pattern (car range) (cdr range))
|
|
|
|
evil-ex-argument)
|
|
|
|
" ... "))
|
2016-10-06 14:16:28 +02:00
|
|
|
'face (if (active) 'doom-modeline-panel))))
|
2016-09-08 00:15:24 +02:00
|
|
|
|
|
|
|
(defun *iedit ()
|
|
|
|
"Show the number of iedit regions matches + what match you're on."
|
|
|
|
(when (and (boundp 'iedit-mode) iedit-mode)
|
|
|
|
(propertize
|
|
|
|
(let ((this-oc (let (message-log-max) (iedit-find-current-occurrence-overlay)))
|
|
|
|
(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))
|
2016-10-06 14:16:28 +02:00
|
|
|
'face (if (active) 'doom-modeline-panel))))
|
2016-09-08 00:15:24 +02:00
|
|
|
|
2016-10-05 09:23:39 +02:00
|
|
|
(defun *media-info ()
|
|
|
|
(cond ((eq major-mode 'image-mode)
|
|
|
|
(let ((size (image-size (image-get-display-property) :pixels)))
|
|
|
|
(format " %dx%d " (car size) (cdr size))))))
|
|
|
|
|
2016-09-19 17:45:37 +02:00
|
|
|
|
|
|
|
;;
|
2017-01-16 23:15:48 -05:00
|
|
|
;; Mode lines
|
2016-09-19 17:45:37 +02:00
|
|
|
;;
|
|
|
|
|
2017-01-16 23:15:48 -05:00
|
|
|
(doom-modeline-define 'main
|
|
|
|
`(let* ((meta (concat (*macro-recording)
|
|
|
|
(*anzu)
|
|
|
|
(*evil-substitute)
|
|
|
|
(*iedit)))
|
|
|
|
(lhs (list (doom-make-xpm (face-background (if (active)
|
|
|
|
'doom-modeline-bar
|
|
|
|
'doom-modeline-inactive-bar))
|
|
|
|
doom-modeline-height
|
|
|
|
doom-modeline-bar-width)
|
|
|
|
(if (= (length meta) 0) " %I " meta)
|
|
|
|
" "
|
|
|
|
(*buffer-info)
|
|
|
|
" %l:%c %p "
|
|
|
|
(*selection-info)))
|
|
|
|
(rhs (list (*buffer-encoding)
|
|
|
|
(*vc)
|
|
|
|
(*major-mode)
|
|
|
|
(*flycheck)))
|
|
|
|
(mid (propertize
|
|
|
|
" " 'display `((space :align-to (- (+ right right-fringe right-margin)
|
|
|
|
,(+ 1 (string-width (format-mode-line rhs)))))))))
|
|
|
|
(list lhs mid rhs)))
|
|
|
|
|
|
|
|
(doom-modeline-define 'eldoc
|
|
|
|
`(list (list ,(when window-system
|
|
|
|
`(doom-make-xpm (face-background 'doom-modeline-eldoc-bar)
|
|
|
|
doom-modeline-height
|
|
|
|
doom-modeline-bar-width))
|
|
|
|
(and (bound-and-true-p str) str))
|
|
|
|
(propertize " " 'display `((space :align-to (1- (+ right right-fringe right-margin)))))))
|
|
|
|
|
|
|
|
(doom-modeline-define 'minimal
|
|
|
|
`(let* ((lhs (list (doom-make-xpm (face-background (if (active)
|
|
|
|
'doom-modeline-bar
|
|
|
|
'doom-modeline-inactive-bar))
|
|
|
|
doom-modeline-height
|
|
|
|
doom-modeline-bar-width)
|
|
|
|
" "
|
|
|
|
(*buffer-project)))
|
|
|
|
(rhs (list (*major-mode)))
|
|
|
|
(mid (propertize
|
|
|
|
" " 'display `((space :align-to (- (+ right right-fringe right-margin)
|
|
|
|
,(+ 1 (string-width (format-mode-line rhs)))))))))
|
|
|
|
(list lhs mid rhs)))
|
2016-09-19 17:45:37 +02:00
|
|
|
|
2017-01-16 23:15:48 -05:00
|
|
|
;;
|
|
|
|
(setq-default mode-line-format (assq 'main doom-modeline-formats))
|
2016-10-04 22:53:25 +02:00
|
|
|
|
2016-09-08 00:15:24 +02:00
|
|
|
(provide 'core-modeline)
|
|
|
|
;;; core-modeline.el ends here
|