Remove spaceline dependency; rewrite mode-line config

This commit is contained in:
Henrik Lissner
2016-06-17 15:38:14 -04:00
parent 0a4cf3911c
commit 78ab53d171
4 changed files with 241 additions and 261 deletions

2
Cask
View File

@ -37,7 +37,7 @@
(depends-on "nlinum") (depends-on "nlinum")
(depends-on "rainbow-delimiters") (depends-on "rainbow-delimiters")
(depends-on "rainbow-mode") (depends-on "rainbow-mode")
(depends-on "spaceline") (depends-on "powerline")
(depends-on "visual-fill-column") (depends-on "visual-fill-column")
;; Evil --- core/core-evil.el ;; Evil --- core/core-evil.el

View File

@ -296,7 +296,8 @@ Examples:
(not inhibit-doom)) (not inhibit-doom))
(doom-mode-init t)) (doom-mode-init t))
(setq default-directory dir) (setq default-directory dir)
(setq mode-line-format '(:eval (spaceline-ml-scratch)))))) (setq mode-line-format (doom-mode-line 'scratch))
)))
;; ;;

View File

@ -178,282 +178,263 @@
;; Mode-line ;; Mode-line
;; ;;
(use-package spaceline (defvar mode-line-height 30)
:init (defvar-local doom--env-version nil)
(defvar-local doom--env-version nil) (defvar-local doom--env-command nil)
(defvar-local doom--env-command nil)
(defvar powerline-height 30)
(defvar powerline-default-separator nil)
:config (eval-when-compile (require 'powerline))
(defface mode-line-is-modified nil "Face for mode-line modified symbol") (defvar mode-line-bar (! (pl/percent-xpm mode-line-height 100 0 100 0 3 "#00B3EF" nil)))
(defface mode-line-buffer-file nil "Face for mode-line buffer file name") (defvar mode-line-eldoc-bar (! (pl/percent-xpm mode-line-height 100 0 100 0 3 "#B3EF00" nil)))
(defface mode-line-buffer-path nil "Face for mode-line buffer file path") (defvar mode-line-inactive-bar (! (pl/percent-xpm mode-line-height 100 0 100 0 3 nil nil)))
;; Make certain unicode glyphs bigger for UI purposes (defface mode-line-is-modified nil "Face for mode-line modified symbol")
(doom-fix-unicode '("DejaVu Sans Mono" 15) ?✱) (defface mode-line-buffer-path nil "Face for mode-line buffer file path")
(let ((font "DejaVu Sans Mono for Powerline")) (defface mode-line-highlight nil "")
(doom-fix-unicode (list font 10) ?) (defface mode-line-2 nil "")
(doom-fix-unicode (list font 16) ?∄)
(doom-fix-unicode (list font 15) ?))
;; Custom modeline segments ;; Make certain unicode glyphs bigger for UI purposes
(spaceline-define-segment *buffer-path (doom-fix-unicode '("DejaVu Sans Mono" 15) ?✱)
(concat (let ((font "DejaVu Sans Mono for Powerline"))
(when buffer-file-name (doom-fix-unicode (list font 12) ?)
(powerline-raw (doom-fix-unicode (list font 16) ?∄)
(f-dirname (doom-fix-unicode (list font 15) ?))
(let ((buffer-path (f-relative buffer-file-name (doom/project-root)))
(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)
buffer-path))))
(if active 'mode-line-buffer-path)))
(powerline-raw "%b" (if active 'mode-line-buffer-file))
" "
(when buffer-file-name
(powerline-raw
(concat
(if (not (file-exists-p buffer-file-name)) ""
(if (buffer-modified-p) ""))
(if buffer-read-only ""))
'mode-line-is-modified)))
:tight-right t
:skip-alternate t)
(spaceline-define-segment *buffer-position (defvar mode-line-selected-window nil)
"A more vim-like buffer position." (defun doom|set-selected-window (&rest _)
(concat "(%l,%c) " (let ((window (frame-selected-window)))
(let ((start (window-start)) (unless (minibuffer-window-active-p window)
(end (window-end)) (setq mode-line-selected-window window))))
(pend (point-max))) (add-hook 'window-configuration-change-hook #'doom|set-selected-window)
(if (and (= start 1) (add-hook 'focus-in-hook #'doom|set-selected-window)
(= end pend))
":All"
(let ((perc (/ end 0.01 pend)))
(cond ((= start 1) ":Top")
((>= perc 100) ":Bot")
(t (format ":%d%%%%" perc))))))))
(defface mode-line-vcs-info nil '((t (:inherit warning)))) (advice-add 'select-window :after 'doom|set-selected-window)
(defface mode-line-vcs-warning nil '((t (:inherit warning)))) (advice-add 'select-frame :after 'doom|set-selected-window)
(spaceline-define-segment *vc
"Version control info"
(when vc-mode
(propertize
(concat ""
(substring vc-mode (+ 2 (length (symbol-name (vc-backend buffer-file-name))))))
'face (when active
(let ((state (vc-state buffer-file-name)))
(cond ((memq state '(edited added))
'mode-line-vcs-info)
((memq state '(removed needs-merge needs-update conflict removed unregistered))
'mode-line-vcs-warning)))))))
;; search indicators
(defface mode-line-count-face nil "")
(make-variable-buffer-local 'anzu--state)
(spaceline-define-segment *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))
(powerline-raw
(let ((here anzu--current-position)
(total anzu--total-matched))
(format " %s/%d%s "
here total
(if anzu--overflow-p "+" "")))
(if active 'mode-line-count-face 'mode-line-inactive)))
:tight t)
(spaceline-define-segment *iedit ;;
"Show the number of iedit regions matches + what match you're on." ;; Mode-line segments
(when (bound-and-true-p 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))
'face (if active 'mode-line-count-face 'mode-line-inactive)))
:tight t)
(spaceline-define-segment *evil-substitute (defun *buffer-path ()
"Show number of :s matches in real time." (when buffer-file-name
(when (and (evil-ex-p) (evil-ex-hl-active-p 'evil-ex-substitute)) (propertize
(powerline-raw (f-dirname
(let ((range (if evil-ex-range (let ((buffer-path (file-relative-name buffer-file-name (doom/project-root)))
(cons (car evil-ex-range) (cadr evil-ex-range)) (max-length (truncate (/ (window-body-width) 1.75))))
(cons (line-beginning-position) (line-end-position)))) (concat (projectile-project-name) "/"
(pattern (car-safe (evil-delimited-arguments evil-ex-argument 2)))) (if (> (length buffer-path) max-length)
(if pattern (let ((path (reverse (split-string buffer-path "/" t)))
(format " %s matches " (output ""))
(count-matches pattern (car range) (cdr range)) (when (and path (equal "" (car path)))
evil-ex-argument) (setq path (cdr path)))
" ... ")) (while (and path (<= (length output) (- max-length 4)))
(if active 'mode-line-count-face 'mode-line-inactive))) (setq output (concat (car path) "/" output))
:tight t) (setq path (cdr path)))
(when path
(setq output (concat "../" output)))
(when (string-suffix-p "/" output)
(setq output (substring output 0 -1)))
output)
buffer-path))))
'face (if active 'mode-line-buffer-path))))
(spaceline-define-segment *macro-recording (defun *buffer-state ()
"Show when recording macro." (when buffer-file-name
(when (and active defining-kbd-macro) (propertize
(powerline-raw (concat (if (not (file-exists-p buffer-file-name))
(format " %s ▶ " (char-to-string evil-this-macro)) ""
highlight-face)) (if (buffer-modified-p) ""))
:tight t) (if buffer-read-only ""))
'face 'mode-line-is-modified)))
(spaceline-define-segment *buffer-encoding-abbrev (defun *buffer-name ()
"The line ending convention used in the buffer." "The buffer's name."
(unless (string-match-p "\\(utf-8\\|undecided\\)" (s-trim-left (format-mode-line "%b")))
(symbol-name buffer-file-coding-system))
(format "%s" buffer-file-coding-system)))
(spaceline-define-segment *major-mode (defun *buffer-pwd ()
"The major mode, including process, environment and text-scale info." "Displays `default-directory'."
(concat (format "%s" mode-name) (propertize
(if (stringp mode-line-process) mode-line-process) (concat "[" (abbreviate-file-name default-directory) "]")
(if doom--env-version (concat " " doom--env-version)) 'face 'mode-line-2))
(and (featurep 'face-remap)
(/= text-scale-mode-amount 0)
(format " (%+d)" text-scale-mode-amount))))
(spaceline-define-segment *selection-info (defun *major-mode ()
"Information about the current selection." "The major mode, including process, environment and text-scale info."
(when (and active (evil-visual-state-p)) (concat (format-mode-line mode-name)
(powerline-raw (if (stringp mode-line-process) mode-line-process)
(let ((reg-beg (region-beginning)) (if doom--env-version (concat " " doom--env-version))
(reg-end (region-end)) (and (featurep 'face-remap)
(evil (eq 'visual evil-state))) (/= text-scale-mode-amount 0)
(let ((lines (count-lines reg-beg (min (1+ reg-end) (point-max)))) (format " (%+d)" text-scale-mode-amount))))
(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)))))))
highlight-face))
:tight t)
;; flycheck (defun *buffer-encoding-abbrev ()
(defface doom-flycheck-error '((t (:inherit error))) "The line ending convention used in the buffer."
"Face for flycheck error feedback in the modeline.") (if (memq buffer-file-coding-system '(utf-8 utf-8-unix))
(defface doom-flycheck-warning '((t (:inherit warning))) ""
"Face for flycheck warning feedback in the modeline.") (symbol-name buffer-file-coding-system)))
(defvar-local doom--flycheck-err-cache nil "") (defface mode-line-vcs-info nil '((t (:inherit warning))))
(defvar-local doom--flycheck-cache nil "") (defface mode-line-vcs-warning nil '((t (:inherit warning))))
(spaceline-define-segment *flycheck (defun *vc ()
"Persistent and cached flycheck indicators in the mode-line." "Displays the current branch, colored based on its state."
(when (and (bound-and-true-p flycheck-mode) (when vc-mode
(or flycheck-current-errors (let ((backend (concat "" (substring vc-mode (+ 2 (length (symbol-name (vc-backend buffer-file-name)))))))
(eq 'running flycheck-last-status-change))) (face (let ((state (vc-state buffer-file-name)))
(or (and (or (eq doom--flycheck-err-cache doom--flycheck-cache) (cond ((memq state '(edited added))
(memq flycheck-last-status-change '(running not-checked))) 'mode-line-vcs-info)
doom--flycheck-cache) ((memq state '(removed needs-merge needs-update conflict removed unregistered))
(and (setq doom--flycheck-err-cache flycheck-current-errors) 'mode-line-vcs-warning)))))
(setq doom--flycheck-cache (if active
(let ((fe (doom/-flycheck-count 'error)) (propertize backend 'face face)
(fw (doom/-flycheck-count 'warning))) backend))))
(concat
(if fe (propertize (format " •%s " fe)
'face (if active
'doom-flycheck-error
'mode-line)))
(if fw (propertize (format " •%s " fw)
'face (if active
'doom-flycheck-warning
'mode-line))))))))))
(defvar *pad-active (pl/percent-xpm powerline-height 100 0 100 0 3 "#00B3EF" nil)) (defface doom-flycheck-error '((t (:inherit error)))
(defvar *pad-inactive (pl/percent-xpm powerline-height 100 0 100 0 3 nil nil)) "Face for flycheck error feedback in the modeline.")
(spaceline-define-segment *pad (defface doom-flycheck-warning '((t (:inherit warning)))
"Padding, to ensure the mode-line is `powerline-height' pixels tall" "Face for flycheck warning feedback in the modeline.")
(if active *pad-active *pad-inactive) (defvar-local doom--flycheck-err-cache nil "")
:tight t) (defvar-local doom--flycheck-cache nil "")
(defun *flycheck ()
"Persistent and cached flycheck indicators in the mode-line."
(when (and (featurep 'flycheck)
flycheck-mode
(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
(let ((fe (doom/-flycheck-count 'error))
(fw (doom/-flycheck-count 'warning)))
(concat
(if fe (propertize (format " •%d " fe)
'face (if active
'doom-flycheck-error
'mode-line)))
(if fw (propertize (format " •%d " fw)
'face (if active
'doom-flycheck-warning
'mode-line))))))))))
(spaceline-compile (defun *selection-info ()
'main "Information about the current selection."
'(*pad (when (and active (evil-visual-state-p))
((*macro-recording *anzu *iedit (propertize
*evil-substitute *selection-info *flycheck) (let ((reg-beg (region-beginning))
:skip-alternate t (reg-end (region-end))
:tight t) (evil (eq 'visual evil-state)))
*buffer-path) (let ((lines (count-lines reg-beg (min (1+ reg-end) (point-max))))
'(*vc (chars (- (1+ reg-end) reg-beg))
*major-mode (cols (1+ (abs (- (evil-column reg-end)
*env-version (evil-column reg-beg))))))
*buffer-encoding-abbrev (cond
(global :when active) ;; rectangle selection
*buffer-position ((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 'mode-line-highlight)))
;; (defun *macro-recording ()
(spaceline-define-segment *default-dir "Show when recording macro."
"Shows default-directory" (when (and active defining-kbd-macro)
(concat "[" (abbreviate-file-name default-directory) "]") (propertize
:face other-face) (format " %s ▶ " (char-to-string evil-this-macro))
'face 'mode-line-highlight)))
(spaceline-compile (defface mode-line-count-face nil "")
'scratch (make-variable-buffer-local 'anzu--state)
'(*pad (defun *anzu ()
((*macro-recording *anzu *iedit *evil-substitute *flycheck *selection-info) "Show the current match number and the total number of matches. Requires anzu
:skip-alternate t to be enabled."
:tight t) (when (and (featurep 'evil-anzu) (evil-ex-hl-active-p 'evil-ex-search))
*buffer-path (propertize
*default-dir) (format " %s/%d%s "
'(*major-mode anzu--current-position anzu--total-matched
*env-version (if anzu--overflow-p "+" ""))
*buffer-encoding-abbrev 'face (if active 'mode-line-count-face))))
(global :when active)
*buffer-position))
;; (defun *evil-substitute ()
(spaceline-define-segment *eldoc "Show number of :s matches in real time."
(and (bound-and-true-p str) str) (when (and (evil-ex-p) (evil-ex-hl-active-p 'evil-ex-substitute))
:tight t (propertize
:face 'mode-line) (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)
" ... "))
'face (if active 'mode-line-count-face))))
(defvar *eldoc-pad-xpm (pl/percent-xpm powerline-height 100 0 100 0 3 "#B3EF00" nil)) (defun *iedit ()
(spaceline-define-segment *eldoc-pad "Show the number of iedit regions matches + what match you're on."
"Padding, to ensure the mode-line is `powerline-height' pixels tall" (when (and (boundp 'iedit-mode) iedit-mode)
*eldoc-pad-xpm (propertize
:tight t (let ((this-oc (let (message-log-max) (iedit-find-current-occurrence-overlay)))
:face 'mode-line) (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))
'face (if active 'mode-line-count-face))))
(spaceline-compile (defun *buffer-position ()
'eldoc '(*eldoc-pad *eldoc) '()) "A more vim-like buffer position."
(let ((start (window-start))
(end (window-end))
(pend (point-max)))
(if (and (= start 1)
(= end pend))
":All"
(cond ((= start 1) ":Top")
((= end pend) ":Bot")
(t (format ":%d%%%%" (/ end 0.01 pend)))))))
;; Initialize modeline ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq-default mode-line-format '("%e" (:eval (spaceline-ml-main)))))
(defun doom-mode-line (&optional id)
`(:eval
(let* ((active (eq (selected-window) mode-line-selected-window))
(lhs (list (propertize " " 'display (if active mode-line-bar mode-line-inactive-bar))
(*flycheck)
(*macro-recording)
(*selection-info)
(*anzu)
(*evil-substitute)
(*iedit)
" "
(*buffer-path)
(*buffer-name)
" "
(*buffer-state)
,(if (eq id 'scratch) '(*buffer-pwd))))
(rhs (list (*buffer-encoding-abbrev)
(*vc)
" " (*major-mode) " "
(propertize
(concat "(%l,%c) " (*buffer-position))
'face (if active 'mode-line-2))))
(middle (propertize
" " 'display `((space :align-to (- (+ right right-fringe right-margin)
,(1+ (string-width (format-mode-line rhs)))))))))
(list lhs middle rhs))))
(setq-default mode-line-format (doom-mode-line))
(provide 'core-ui) (provide 'core-ui)
;;; core-ui.el ends here ;;; core-ui.el ends here

View File

@ -1,7 +1,5 @@
;;; custom-demo.el --- -*- no-byte-compile: t; -*- ;;; custom-demo.el --- -*- no-byte-compile: t; -*-
(defvar powerline-height)
;; This library offers: ;; This library offers:
;; + impatient-mode: for broadcasting my emacs session ;; + impatient-mode: for broadcasting my emacs session
;; + big-mode: for enlarged text while screencasting ;; + big-mode: for enlarged text while screencasting
@ -19,7 +17,7 @@
:config (httpd-start)) :config (httpd-start))
(defvar big-mode--old-line-spacing line-spacing) (defvar big-mode--old-line-spacing line-spacing)
(defvar big-mode--old-modeline-height powerline-height) (defvar big-mode--old-modeline-height mode-line-height)
(define-minor-mode big-mode (define-minor-mode big-mode
:init-value nil :init-value nil
:lighter " BIG" :lighter " BIG"
@ -28,10 +26,10 @@
(doom/load-font (if big-mode big-mode-font doom-default-font))) (doom/load-font (if big-mode big-mode-font doom-default-font)))
(if big-mode (if big-mode
(setq-default (setq-default
powerline-height big-mode-modeline-height mode-line-height big-mode-modeline-height
line-spacing big-mode-line-spacing) line-spacing big-mode-line-spacing)
(setq-default (setq-default
powerline-height big-mode--old-modeline-height mode-line-height big-mode--old-modeline-height
line-spacing big-mode--old-line-spacing))) line-spacing big-mode--old-line-spacing)))
(evil-define-command doom:big (&optional size) (evil-define-command doom:big (&optional size)