2016-09-08 00:15:24 +02:00
|
|
|
;;; core-modeline.el
|
|
|
|
|
|
|
|
;; This file tries to be an almost self-contained configuration of my mode-line.
|
2016-09-08 00:31:30 +02:00
|
|
|
;;
|
|
|
|
;; It depends on the following external packages:
|
|
|
|
;; + REQUIRED
|
2016-09-08 08:51:02 +02:00
|
|
|
;; + f
|
|
|
|
;; + s
|
2016-09-08 00:31:30 +02:00
|
|
|
;; + powerline
|
|
|
|
;; + projectile
|
|
|
|
;; + OPTIONAL
|
2016-09-08 08:51:02 +02:00
|
|
|
;; + evil-mode
|
|
|
|
;; + anzu + evil-anzu
|
2016-09-08 00:31:30 +02:00
|
|
|
;; + iedit and evil-multiedit
|
|
|
|
;; + flycheck
|
|
|
|
;;
|
2016-09-19 17:45:37 +02:00
|
|
|
;; Both are simple, isolated functions and, besides projectile, have no other
|
2016-09-08 00:31:30 +02:00
|
|
|
;; dependencies.
|
2016-09-08 00:15:24 +02:00
|
|
|
|
2016-09-22 21:18:48 +02:00
|
|
|
(defvar doom-modeline-height 29
|
2016-09-08 00:15:24 +02:00
|
|
|
"How tall the mode-line should be. This is only respected in GUI emacs.")
|
|
|
|
|
2016-09-28 13:54:21 +02:00
|
|
|
(defvar doom-modeline-bar-width 3
|
|
|
|
"How wide the mode-line bar should be. This is only respected in GUI emacs.")
|
|
|
|
|
2016-09-08 00:15:24 +02:00
|
|
|
;; Custom faces
|
2016-09-19 17:45:37 +02:00
|
|
|
(defface doom-modeline-alternate '((t (:inherit mode-line)))
|
|
|
|
"Secondary color for the modeline.")
|
2016-09-08 00:15:24 +02:00
|
|
|
|
2016-09-19 17:45:37 +02: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.")
|
|
|
|
|
2016-09-19 17:45:37 +02:00
|
|
|
(defface doom-modeline-count '((t (:inherit mode-line)))
|
|
|
|
"Face for 'X out of Y' segments, such as `*anzu', `*evil-substitute' and
|
|
|
|
`iedit'")
|
|
|
|
|
|
|
|
(defface doom-modeline-bar '((t (:inherit doom-modeline-highlight)))
|
|
|
|
"The face used for the left-most bar on the mode-line of an active window.")
|
|
|
|
|
|
|
|
(defface doom-modeline-eldoc-bar '((t (:inherit doom-modeline-bar)))
|
|
|
|
"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.")
|
|
|
|
|
|
|
|
(defface doom-modeline-count '((t (:inherit mode-line)))
|
2016-09-08 00:15:24 +02:00
|
|
|
"Face for anzu/evil-substitute/evil-search number-of-matches display.")
|
|
|
|
|
2016-09-19 17:45:37 +02:00
|
|
|
(defface doom-modeline-info '((t (:inherit success)))
|
|
|
|
"Face for info-level messages in the modeline. Used by `*vc'.")
|
|
|
|
(defface doom-modeline-warning '((t (:inherit warning)))
|
|
|
|
"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'")
|
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
;; Dependencies
|
|
|
|
;;
|
|
|
|
|
|
|
|
(require 'powerline)
|
2016-09-08 00:15:24 +02:00
|
|
|
|
2016-09-19 17:45:37 +02:00
|
|
|
(require 'all-the-icons)
|
|
|
|
|
|
|
|
(use-package eldoc-eval
|
|
|
|
:config
|
|
|
|
(setq eldoc-in-minibuffer-show-fn 'doom-eldoc-show-in-mode-line)
|
|
|
|
(eldoc-in-minibuffer-mode +1))
|
2016-09-08 00:15:24 +02:00
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
;; Functions
|
|
|
|
;;
|
|
|
|
|
2016-09-08 00:31:30 +02:00
|
|
|
(defun doom-ml-flycheck-count (state)
|
2016-09-08 00:15:24 +02:00
|
|
|
"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))))))
|
|
|
|
|
|
|
|
;; pyenv/rbenv version segment
|
2016-09-08 00:31:30 +02:00
|
|
|
(defvar doom-ml-env-version-hook '()
|
2016-09-08 00:15:24 +02:00
|
|
|
"Hook that runs whenever the environment version changes (e.g. rbenv/pyenv)")
|
|
|
|
|
2016-09-08 00:31:30 +02:00
|
|
|
(defun doom-ml|env-update ()
|
2016-09-28 13:54:36 +02:00
|
|
|
"Update (py|rb)env version string in `doom-ml--env-version', generated with
|
|
|
|
`doom-ml--env-command'."
|
2016-09-08 00:31:30 +02:00
|
|
|
(when doom-ml--env-command
|
2016-09-19 17:45:37 +02:00
|
|
|
(let ((default-directory (projectile-project-root)))
|
2016-09-08 00:31:30 +02:00
|
|
|
(let ((s (shell-command-to-string doom-ml--env-command)))
|
|
|
|
(setq doom-ml--env-version (if (string-match "[ \t\n\r]+\\'" s)
|
2016-09-08 00:15:24 +02:00
|
|
|
(replace-match "" t t s)
|
|
|
|
s))
|
2016-09-08 00:31:30 +02:00
|
|
|
(run-hook-with-args 'doom-ml-env-version-hook doom-ml--env-version)))))
|
2016-09-08 00:15:24 +02:00
|
|
|
|
2016-09-19 17:45:37 +02:00
|
|
|
(defmacro def-version-cmd! (mode command)
|
|
|
|
"Define a COMMAND for MODE that will set `doom-ml--env-command' when that mode
|
|
|
|
is activated, which should return the version number of the current environment.
|
|
|
|
It is used by `doom-ml|env-update' to display a version number in the modeline.
|
|
|
|
For instance:
|
2016-09-08 00:15:24 +02:00
|
|
|
|
|
|
|
(def-version-cmd! ruby-mode \"ruby --version | cut -d' ' -f2\")
|
|
|
|
|
2016-09-19 17:45:37 +02:00
|
|
|
This will display the ruby version in the modeline in ruby-mode buffers. It is
|
|
|
|
cached the first time."
|
|
|
|
(add-hook 'focus-in-hook 'doom-ml|env-update)
|
|
|
|
(add-hook 'find-file-hook 'doom-ml|env-update)
|
|
|
|
`(add-hook ',mode (lambda () (setq doom-ml--env-command ,command))))
|
2016-09-08 00:15:24 +02:00
|
|
|
|
2016-09-28 13:54:21 +02:00
|
|
|
(defun doom-make-xpm (color height width)
|
|
|
|
"Create an XPM bitmap."
|
|
|
|
(let ((data nil)
|
|
|
|
(i 0))
|
|
|
|
(setq data (make-list height (make-list width 1)))
|
|
|
|
(pl/make-xpm "percent" color color (reverse data))))
|
|
|
|
|
|
|
|
(pl/memoize 'doom-make-xpm)
|
|
|
|
|
2016-09-08 00:15:24 +02:00
|
|
|
|
|
|
|
;;
|
|
|
|
;; Initialization
|
|
|
|
;;
|
|
|
|
|
|
|
|
;; Where (py|rb)env version strings will be stored
|
2016-09-08 00:31:30 +02:00
|
|
|
(defvar-local doom-ml--env-version nil)
|
|
|
|
(defvar-local doom-ml--env-command nil)
|
2016-09-08 00:15:24 +02:00
|
|
|
|
|
|
|
;; So the mode-line can keep track of "the current window"
|
2016-09-23 16:08:52 +02:00
|
|
|
(defvar doom-ml-selected-window nil)
|
2016-09-08 00:15:24 +02:00
|
|
|
(defun doom|set-selected-window (&rest _)
|
|
|
|
(let ((window (frame-selected-window)))
|
2016-09-09 09:00:00 +02:00
|
|
|
(when (and (windowp window)
|
|
|
|
(not (minibuffer-window-active-p window)))
|
2016-09-23 16:08:52 +02:00
|
|
|
(setq doom-ml-selected-window window))))
|
2016-09-08 00:15:24 +02:00
|
|
|
(add-hook 'window-configuration-change-hook #'doom|set-selected-window)
|
|
|
|
(add-hook 'focus-in-hook #'doom|set-selected-window)
|
|
|
|
(advice-add 'select-window :after 'doom|set-selected-window)
|
|
|
|
(advice-add 'select-frame :after 'doom|set-selected-window)
|
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
;; Mode-line segments
|
|
|
|
;;
|
|
|
|
|
|
|
|
(defun *buffer-path ()
|
|
|
|
"Displays the buffer's full path relative to the project root (includes the
|
|
|
|
project root). Excludes the file basename. See `*buffer-name' for that."
|
|
|
|
(when buffer-file-name
|
|
|
|
(f-dirname
|
2016-09-19 17:45:37 +02:00
|
|
|
(let ((buffer-path (file-relative-name buffer-file-name (projectile-project-root)))
|
2016-09-08 00:15:24 +02:00
|
|
|
(max-length (truncate (/ (window-body-width) 1.75))))
|
|
|
|
(concat (projectile-project-name) "/"
|
|
|
|
(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-09-23 16:08:52 +02:00
|
|
|
buffer-path))))))
|
2016-09-08 00:15:24 +02:00
|
|
|
|
|
|
|
(defun *buffer-name ()
|
|
|
|
"The buffer's base name or id."
|
2016-09-19 17:45:37 +02:00
|
|
|
(if buffer-file-name
|
|
|
|
(f-filename buffer-file-name)
|
|
|
|
(s-trim-left (format-mode-line "%b"))))
|
2016-09-08 00:15:24 +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-09-19 17:45:37 +02:00
|
|
|
(concat
|
2016-09-23 16:08:52 +02:00
|
|
|
" "
|
2016-09-19 17:45:37 +02:00
|
|
|
(all-the-icons-octicon
|
|
|
|
"file-directory"
|
|
|
|
:face 'doom-modeline-alternate :v-adjust -0.05 :height 1.3)
|
|
|
|
(propertize (concat " " (abbreviate-file-name default-directory))
|
|
|
|
'face `(:inherit doom-modeline-alternate))))
|
2016-09-08 00:15:24 +02:00
|
|
|
|
|
|
|
(defun *buffer-state ()
|
2016-09-19 17:45:37 +02:00
|
|
|
"Displays symbols representing the buffer's state; which can be one or more
|
|
|
|
of: non-existent, modified or read-only."
|
2016-09-23 16:08:52 +02:00
|
|
|
(let ((state (list))
|
|
|
|
(base-face (if active 'doom-default 'mode-line-inactive)))
|
2016-09-19 17:45:37 +02:00
|
|
|
(when buffer-file-name
|
|
|
|
(if (file-exists-p buffer-file-name)
|
|
|
|
(when (buffer-modified-p)
|
2016-09-23 16:08:52 +02:00
|
|
|
(push (all-the-icons-octicon "primitive-dot" :face `(minibuffer-prompt ,base-face) :height 1.1 :v-adjust -0.05) state))
|
|
|
|
(push (all-the-icons-octicon "circle-slash" :face `(doom-modeline-urgent ,base-face) :height 1.1 :v-adjust -0.05) state)))
|
|
|
|
(when buffer-read-only
|
|
|
|
(push (all-the-icons-octicon "lock" :face `(doom-modeline-urgent ,base-face) :height 1.1 :v-adjust -0.05) state))
|
2016-09-19 17:45:37 +02:00
|
|
|
(when state
|
2016-09-23 16:08:52 +02:00
|
|
|
(concat (s-join (propertize " " 'face base-face) state)))))
|
|
|
|
|
|
|
|
(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)."
|
|
|
|
(let ((face (if active 'doom-default 'mode-line-inactive)))
|
|
|
|
(concat (propertize " " 'face face)
|
|
|
|
(propertize (or (*buffer-path) "") 'face `(:inherit (,face doom-modeline-alternate)))
|
|
|
|
(propertize (or (*buffer-name) "") 'face face)
|
|
|
|
(propertize " " 'face face)
|
2016-09-27 02:45:30 +02:00
|
|
|
(let ((state (*buffer-state)))
|
|
|
|
(if state (concat state (propertize " " 'face face)))))))
|
2016-09-08 00:15:24 +02:00
|
|
|
|
|
|
|
(defun *buffer-encoding-abbrev ()
|
2016-09-23 16:08:52 +02:00
|
|
|
"The line ending convention used in the buffer (if it isn't unix) and its
|
|
|
|
character encoding (if it isn't UTF-8)."
|
|
|
|
(let ((sys (symbol-name buffer-file-coding-system)))
|
|
|
|
(concat (cond ((string-suffix-p "-mac" sys)
|
|
|
|
"MAC ")
|
|
|
|
((string-suffix-p "-dos" sys)
|
|
|
|
"DOS ")
|
|
|
|
(t ""))
|
|
|
|
(if (string-match-p "u\\(tf-8\\|ndecided\\)" sys)
|
|
|
|
""
|
|
|
|
(concat (s-chop-suffixes '("-unix" "-dos" "-mac") sys) " ")))))
|
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
|
|
|
|
(concat " "
|
|
|
|
(format-mode-line mode-name)
|
|
|
|
(if (stringp mode-line-process) mode-line-process)
|
|
|
|
(if doom-ml--env-version (concat " " doom-ml--env-version))
|
|
|
|
(and (featurep 'face-remap)
|
|
|
|
(/= text-scale-mode-amount 0)
|
|
|
|
(format " (%+d)" text-scale-mode-amount))
|
|
|
|
" ")
|
|
|
|
'face (if active 'mode-line 'mode-line-inactive)))
|
2016-09-08 00:15:24 +02:00
|
|
|
|
|
|
|
(defun *vc ()
|
|
|
|
"Displays the current branch, colored based on its state."
|
|
|
|
(when vc-mode
|
2016-09-19 17:45:37 +02:00
|
|
|
(let ((backend (substring vc-mode (+ 2 (length (symbol-name (vc-backend buffer-file-name))))))
|
2016-09-08 00:15:24 +02:00
|
|
|
(face (let ((state (vc-state buffer-file-name)))
|
|
|
|
(cond ((memq state '(edited added))
|
2016-09-19 17:45:37 +02:00
|
|
|
'doom-modeline-info)
|
|
|
|
((memq state '(removed needs-merge needs-update conflict unregistered))
|
|
|
|
'doom-modeline-urgent)
|
|
|
|
(t 'doom-modeline-warning)))))
|
|
|
|
(concat
|
|
|
|
" "
|
|
|
|
(propertize (all-the-icons-octicon "git-branch")
|
|
|
|
'face `(:inherit ,(if active face 'mode-line-inactive)
|
|
|
|
:family ,(all-the-icons-octicon-family)
|
|
|
|
:height 1.25)
|
|
|
|
'display '(raise -0.1))
|
|
|
|
" "
|
2016-09-23 16:08:52 +02:00
|
|
|
(propertize backend 'face (if active face 'mode-line-inactive))
|
2016-09-19 17:45:37 +02:00
|
|
|
" "))))
|
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)))
|
|
|
|
doom--flycheck-cache)
|
|
|
|
(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)))
|
|
|
|
(concat (if fe (concat
|
|
|
|
(all-the-icons-octicon "x" :face 'doom-modeline-urgent :height 1.2 :v-adjust -0.06)
|
|
|
|
(propertize (format " %d " fe) 'face 'doom-modeline-urgent)))
|
|
|
|
(if fw (concat
|
|
|
|
(all-the-icons-octicon "x" :face 'doom-modeline-warning :height 1.2 :v-adjust -0.06)
|
|
|
|
(propertize (format " %d " fw) 'face 'doom-modeline-warning)))
|
|
|
|
(unless (or fe fw)
|
|
|
|
(when active
|
|
|
|
(all-the-icons-octicon "check" :face 'doom-modeline-info :height 1.2 :v-adjust -0.06)))
|
2016-09-19 17:45:37 +02:00
|
|
|
" ")))))
|
2016-09-23 16:08:52 +02:00
|
|
|
(concat
|
|
|
|
(all-the-icons-octicon "check" :face 'doom-modeline-info :height 1.2 :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."
|
|
|
|
(when (and active (evil-visual-state-p))
|
|
|
|
(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)))))))
|
2016-09-19 17:45:37 +02:00
|
|
|
'face 'doom-modeline-highlight)))
|
2016-09-08 00:15:24 +02:00
|
|
|
|
|
|
|
(defun *macro-recording ()
|
|
|
|
"Display current macro being recorded."
|
|
|
|
(when (and active defining-kbd-macro)
|
|
|
|
(propertize
|
2016-09-19 17:45:37 +02:00
|
|
|
(format " %s • " (char-to-string evil-this-macro))
|
|
|
|
'face 'doom-modeline-highlight)))
|
2016-09-08 00:15:24 +02:00
|
|
|
|
|
|
|
(make-variable-buffer-local 'anzu--state)
|
|
|
|
(defun *anzu ()
|
|
|
|
"Show the current match number and the total number of matches. Requires anzu
|
|
|
|
to be enabled."
|
|
|
|
(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-09-23 16:08:52 +02:00
|
|
|
'face (if active 'doom-modeline-count 'mode-line-inactive))))
|
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-09-23 16:08:52 +02:00
|
|
|
'face (if active 'doom-modeline-count 'mode-line-inactive))))
|
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-09-23 16:08:52 +02:00
|
|
|
'face (if active 'doom-modeline-count 'mode-line-inactive))))
|
2016-09-08 00:15:24 +02:00
|
|
|
|
|
|
|
(defun *buffer-position ()
|
|
|
|
"A more vim-like buffer position."
|
|
|
|
(let ((start (window-start))
|
|
|
|
(end (window-end))
|
|
|
|
(pend (point-max)))
|
2016-09-19 17:45:37 +02:00
|
|
|
(propertize
|
|
|
|
(concat
|
|
|
|
" %l:%c :"
|
|
|
|
(if (and (= start 1)
|
|
|
|
(= end pend))
|
|
|
|
"All"
|
|
|
|
(cond ((= start 1) "Top")
|
|
|
|
((= end pend) "Bot")
|
|
|
|
(t (format "%d%%%%" (/ end 0.01 pend))))))
|
2016-09-23 16:08:52 +02:00
|
|
|
'face (if active 'doom-modeline-alternate 'mode-line-inactive))))
|
2016-09-08 00:15:24 +02:00
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
2016-09-28 13:54:21 +02:00
|
|
|
(defvar doom-modeline-bar-active (face-background 'doom-modeline-bar)
|
|
|
|
"The color to use for the bar in active window mode-lines.")
|
|
|
|
|
|
|
|
(defvar doom-modeline-bar-inactive (face-background 'mode-line-inactive)
|
|
|
|
"The color to use for the bar in inactive window mode-lines.")
|
|
|
|
|
2016-09-28 13:53:47 +02:00
|
|
|
(defun doom-modeline (&optional id)
|
2016-09-08 00:15:24 +02:00
|
|
|
`(:eval
|
2016-09-23 16:08:52 +02:00
|
|
|
(let* ((active (eq (selected-window) doom-ml-selected-window))
|
2016-09-28 13:54:21 +02:00
|
|
|
(lhs (list (propertize
|
|
|
|
" " 'display (doom-make-xpm (if active
|
|
|
|
doom-modeline-bar-active
|
|
|
|
doom-modeline-bar-inactive)
|
|
|
|
doom-modeline-height
|
|
|
|
doom-modeline-bar-width))
|
2016-09-08 00:15:24 +02:00
|
|
|
(*macro-recording)
|
|
|
|
(*selection-info)
|
|
|
|
(*anzu)
|
|
|
|
(*evil-substitute)
|
|
|
|
(*iedit)
|
2016-09-19 17:45:37 +02:00
|
|
|
,(if (eq id 'scratch)
|
2016-09-23 16:08:52 +02:00
|
|
|
'(*buffer-project)
|
|
|
|
'(*buffer-info))
|
|
|
|
" "
|
2016-09-19 17:45:37 +02:00
|
|
|
(*flycheck)))
|
2016-09-08 00:15:24 +02:00
|
|
|
(rhs (list (*buffer-encoding-abbrev)
|
|
|
|
(*vc)
|
2016-09-19 17:45:37 +02:00
|
|
|
(*major-mode)
|
|
|
|
(*buffer-position)))
|
2016-09-08 00:15:24 +02:00
|
|
|
(middle (propertize
|
|
|
|
" " 'display `((space :align-to (- (+ right right-fringe right-margin)
|
|
|
|
,(1+ (string-width (format-mode-line rhs)))))))))
|
|
|
|
(list lhs middle rhs))))
|
|
|
|
|
2016-09-28 13:53:47 +02:00
|
|
|
(setq-default mode-line-format (doom-modeline))
|
2016-09-08 00:15:24 +02:00
|
|
|
|
2016-09-19 17:45:37 +02:00
|
|
|
|
|
|
|
;;
|
|
|
|
;; Eldoc-in-mode-line support (for `eval-expression')
|
|
|
|
;;
|
|
|
|
|
2016-09-28 13:54:21 +02:00
|
|
|
(defvar doom-modeline-eldoc-bar-color (face-background 'doom-modeline-eldoc-bar)
|
|
|
|
"The color to use for the bar when eldoc uses the mode-line.")
|
2016-09-23 16:08:52 +02:00
|
|
|
|
2016-09-28 13:53:47 +02:00
|
|
|
(defun doom-eldoc-modeline ()
|
2016-09-19 17:45:37 +02:00
|
|
|
`(:eval
|
2016-09-23 16:08:52 +02:00
|
|
|
(let ((active (eq (selected-window) doom-ml-selected-window)))
|
2016-09-28 13:54:21 +02:00
|
|
|
(list (list (propertize " " 'display (doom-make-xpm doom-modeline-eldoc-bar-color
|
|
|
|
doom-modeline-height
|
|
|
|
doom-modeline-bar-width))
|
2016-09-19 17:45:37 +02:00
|
|
|
(and (bound-and-true-p str) str))
|
2016-09-23 16:08:52 +02:00
|
|
|
(propertize " " 'display `((space :align-to (1- (+ right right-fringe right-margin)))))))))
|
2016-09-19 17:45:37 +02:00
|
|
|
|
2016-09-12 16:31:45 +02: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)
|
2016-09-28 13:53:47 +02:00
|
|
|
(mode-line-format (or (and str (doom-eldoc-modeline))
|
2016-09-12 16:31:45 +02:00
|
|
|
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-09-08 00:15:24 +02:00
|
|
|
(provide 'core-modeline)
|
|
|
|
;;; core-modeline.el ends here
|