Refactor and redesign mode-line for new narf-one theme

This commit is contained in:
Henrik Lissner 2016-05-20 16:44:57 -04:00
parent b444277d86
commit 7b52ce1cab

View file

@ -195,7 +195,7 @@
:init :init
(defvar-local narf--env-version nil) (defvar-local narf--env-version nil)
(defvar-local narf--env-command nil) (defvar-local narf--env-command nil)
(defvar powerline-height 23) (defvar powerline-height 26)
(defvar powerline-default-separator nil) (defvar powerline-default-separator nil)
:config :config
@ -227,24 +227,21 @@
output) output)
buffer-path)))) buffer-path))))
(if active 'mode-line-buffer-path))) (if active 'mode-line-buffer-path)))
(powerline-raw "%b" (if active 'mode-line-buffer-file))) (powerline-raw "%b" (if active 'mode-line-buffer-file))
:tight-right t) (when buffer-file-name
(spaceline-define-segment *buffer-modified
(unless (string-prefix-p "*" (buffer-name))
(powerline-raw (powerline-raw
(concat (when buffer-file-name (concat (when buffer-file-name
(concat (concat
(if (buffer-modified-p) "[+]") (if (buffer-modified-p) "")
(if (not (file-exists-p buffer-file-name)) "[!]"))) (if (not (file-exists-p buffer-file-name)) "[!]")))
(if buffer-read-only "[RO]")) (if buffer-read-only "[RO]"))
'mode-line-is-modified)) 'mode-line-is-modified)))
:skip-alternate t :tight-right t
:tight t) :skip-alternate t)
(spaceline-define-segment *buffer-position (spaceline-define-segment *buffer-position
"A more vim-like buffer position." "A more vim-like buffer position."
(concat "%l/%c " (concat "(%l,%c) "
(let ((start (window-start)) (let ((start (window-start))
(end (window-end)) (end (window-end))
(pend (point-max))) (pend (point-max)))
@ -254,17 +251,13 @@
(let ((perc (/ end 0.01 pend))) (let ((perc (/ end 0.01 pend)))
(cond ((= start 1) ":Top") (cond ((= start 1) ":Top")
((>= perc 100) ":Bot") ((>= perc 100) ":Bot")
(t (format ":%d%%%%" perc))))))) (t (format ":%d%%%%" perc))))))
:tight-left t) " "))
(spaceline-define-segment *vc (spaceline-define-segment *vc
"Version control info" "Version control info"
(when (and active vc-mode) (when vc-mode
(powerline-raw (concat "" (substring vc-mode (+ 2 (length (symbol-name (vc-backend buffer-file-name))))))))
(substring
vc-mode (1+ (length (symbol-name (vc-backend buffer-file-name)))))
other-face))
:tight-right t)
;; search indicators ;; search indicators
(defface mode-line-count-face nil "") (defface mode-line-count-face nil "")
@ -283,8 +276,7 @@ anzu to be enabled."
:tight t) :tight t)
(spaceline-define-segment *iedit (spaceline-define-segment *iedit
"Show the number of matches and what match you're on (or after). Requires "Show the number of iedit regions matches + what match you're on."
iedit."
(when (bound-and-true-p iedit-mode) (when (bound-and-true-p iedit-mode)
(propertize (propertize
(let ((this-oc (iedit-find-current-occurrence-overlay)) (let ((this-oc (iedit-find-current-occurrence-overlay))
@ -320,7 +312,7 @@ iedit."
:tight t) :tight t)
(spaceline-define-segment *macro-recording (spaceline-define-segment *macro-recording
"Show when recording macro" "Show when recording macro."
(when (and active defining-kbd-macro) (when (and active defining-kbd-macro)
(powerline-raw (powerline-raw
(format " %s ▶ " (char-to-string evil-this-macro)) (format " %s ▶ " (char-to-string evil-this-macro))
@ -340,8 +332,7 @@ iedit."
(if narf--env-version (concat " " narf--env-version)) (if narf--env-version (concat " " narf--env-version))
(and (featurep 'face-remap) (and (featurep 'face-remap)
(/= text-scale-mode-amount 0) (/= text-scale-mode-amount 0)
(format " (%+d)" text-scale-mode-amount))) (format " (%+d)" text-scale-mode-amount))))
:tight-right t)
(spaceline-define-segment *selection-info (spaceline-define-segment *selection-info
"Information about the current selection." "Information about the current selection."
@ -365,7 +356,8 @@ iedit."
(format "%dL" lines) (format "%dL" lines)
(format " %dC %dL " chars lines))) (format " %dC %dL " chars lines)))
(t (format " %dC " (if evil chars (1- chars))))))) (t (format " %dC " (if evil chars (1- chars)))))))
highlight-face))) highlight-face))
:tight t)
;; flycheck ;; flycheck
(defface spaceline-flycheck-error (defface spaceline-flycheck-error
@ -403,31 +395,44 @@ iedit."
'mode-line))))))))) 'mode-line)))))))))
:tight t) :tight t)
(defvar narf--mode-line-padding
(pl/percent-xpm powerline-height 100 0 100 0 1 nil nil))
(spaceline-define-segment *pad (spaceline-define-segment *pad
"Padding, to ensure the mode-line is `powerline-height' pixels tall" "Padding, to ensure the mode-line is `powerline-height' pixels tall"
narf--mode-line-padding (pl/percent-xpm powerline-height 100 0 100 0 3 (if active "#00B3EF") nil)
:tight t) :tight t)
(spaceline-compile (spaceline-compile
'main 'main
;; Left side '(*pad
'(((*macro-recording *anzu *iedit *evil-substitute *flycheck) ((*macro-recording *anzu *iedit *evil-substitute *flycheck *selection-info)
:skip-alternate t :skip-alternate t
:tight t) :tight t)
*buffer-path *buffer-path)
*buffer-modified '(*vc
*vc)
;; Right side
'(*selection-info
*major-mode *major-mode
*env-version *env-version
*buffer-encoding-abbrev *buffer-encoding-abbrev
(global :when active) (global :when active)
*buffer-position *buffer-position))
*pad
)) ;;
(spaceline-define-segment *default-dir
"Shows default-directory"
(concat "[" (abbreviate-file-name default-directory) "]")
:face other-face)
(spaceline-compile
'scratch
'(*pad
((*macro-recording *anzu *iedit *evil-substitute *flycheck *selection-info)
:skip-alternate t
:tight t)
*buffer-path
*default-dir)
'(*major-mode
*env-version
*buffer-encoding-abbrev
(global :when active)
*buffer-position))
;; Initialize modeline ;; Initialize modeline
(setq-default mode-line-format '("%e" (:eval (spaceline-ml-main))))) (setq-default mode-line-format '("%e" (:eval (spaceline-ml-main)))))