improved modeline

This commit is contained in:
Iñaki
2016-09-19 20:27:21 +02:00
parent 6b9df2ce09
commit dbdbb76af7
4 changed files with 72 additions and 72 deletions

View File

@@ -22,7 +22,7 @@
(count-lines (count-lines
(point-min) (point-min)
(point-max)))))) (point-max))))))
(concat "%" (number-to-string w) "d")))))) (concat "%" (number-to-string w) "d "))))))
(defun linum-format-func (line) (defun linum-format-func (line)

View File

@@ -1,31 +1,38 @@
(eval-when-compile (require 'cl))
(require 'evil) (require 'evil)
(require 'magit) (require 'magit)
(require 'all-the-icons) (require 'all-the-icons)
;; (lexical-let ((default-color (cons (face-background 'mode-line) (defvar powerline-current-window nil)
;; (face-foreground 'mode-line)))) (defun update-current-window (windows)
;; (add-hook 'post-command-hook (when (not (minibuffer-window-active-p (frame-selected-window)))
;; (lambda () (setq powerline-current-window (selected-window))))
;; (let ((color (cond ((minibufferp) default-color) (add-function :before pre-redisplay-function 'update-current-window)
;; ((evil-normal-state-p)
;; '("#181818" . "ivory")) (defun evil-tag-color ()
;; ((evil-insert-state-p) (if (eq (get-buffer-window) powerline-current-window)
;; '("firebrick" . "ivory")) (cond ((evil-normal-state-p) "#86261c")
;; ((evil-visual-state-p) ((evil-visual-state-p) "DarkSlateGray")
;; '("DarkSlateGray" . "ivory")) ((evil-insert-state-p) "firebrick")
;; ((evil-emacs-state-p) ((evil-emacs-state-p) "SeaGreen")
;; '("SeaGreen" . "ivory")) ((evil-operator-state-p) "SeaGreen")
;; ((buffer-modified-p) ((evil-motion-state-p) "SeaGreen")
;; '("firebrick" . "ivory")) ((evil-replace-state-p) "firebrick"))
;; (t default-color)))) (face-background 'mode-line-inactive)))
;; (set-face-background 'mode-line (car color))
;; (set-face-font 'mode-line "Iosevka Term-10") (defun branch-tag-bg-color ()
;; (set-face-font 'mode-line-buffer-id "Iosevka Term-10") (if (eq (get-buffer-window) powerline-current-window)
;; (set-face-font 'mode-line-emphasis "Iosevka Term-10") "#424242"
;; (set-face-font 'mode-line-highlight "Iosevka Term-10") (face-background 'mode-line-inactive)))
;; (set-face-font 'mode-line-inactive "Iosevka Term-10")
;; (set-face-foreground 'mode-line (cdr color)))))) (defun time-tag-bg-color ()
(if (eq (get-buffer-window) powerline-current-window)
"ivory"
(face-background 'mode-line-inactive)))
(defun time-tag-fg-color ()
(if (eq (get-buffer-window) powerline-current-window)
"#181818"
(face-foreground 'mode-line-inactive)))
(defun fancy-mode-line-render (left center right &optional lpad rpad) (defun fancy-mode-line-render (left center right &optional lpad rpad)
"Return a string the width of the current window with "Return a string the width of the current window with
@@ -49,28 +56,23 @@ can be used to add a number of spaces to the front and back of the string."
right))) right)))
(error (format "[%s]: (%s) (%s) (%s)" err left center right)))) (error (format "[%s]: (%s) (%s) (%s)" err left center right))))
(defun evil-mode-state () (defun evil-mode-state ()
(cond ((evil-normal-state-p) (format " NORMAL " )) (let ((str (cond ((evil-normal-state-p) (format " NORMAL " ))
((evil-visual-state-p) (format " VISUAL " )) ((evil-visual-state-p) (format " VISUAL " ))
((evil-insert-state-p) (format " INSERT " )) ((evil-insert-state-p) (format " INSERT " ))
((evil-emacs-state-p) (format " EMACS " )) ((evil-emacs-state-p) (format " EMACS " ))
((evil-operator-state-p) (format " OPERATOR " )) ((evil-operator-state-p) (format " OPERATOR " ))
((evil-motion-state-p) (format " MOTION " )) ((evil-motion-state-p) (format " MOTION " ))
((evil-replace-state-p) (format " REPLACE " )))) ((evil-replace-state-p) (format " REPLACE " )))))
(propertize str 'face `(:height 1.0 :background ,(evil-tag-color) :weight bold))))
(defun vc-mode-branch-state () (defun vc-mode-branch-state ()
(let ((bufname (buffer-file-name (current-buffer)))) (let ((bufname (buffer-file-name (current-buffer))))
(when bufname (when bufname
(when (vc-working-revision bufname) (when (magit-get-current-branch)
(concat (propertize (format "  %s " (magit-get-current-branch))
(propertize (format " %s" (all-the-icons-octicon "git-branch")) 'face `(:weight bold :background ,(branch-tag-bg-color)))))))
'face `(:height 1.0 ;;(vc-state bufname)))))))
:family ,(all-the-icons-octicon-family))
'display '(raise 0.0))
(format " %s [%s]"
(propertize (magit-get-current-branch) 'face 'bold)
(vc-state bufname)))))))
(defun powerline-modified () (defun powerline-modified ()
(let* ((config-alist (let* ((config-alist
@@ -81,8 +83,9 @@ can be used to add a number of spaces to the front and back of the string."
("%" all-the-icons-octicon-family ("%" all-the-icons-octicon-family
all-the-icons-octicon "lock" :height 1.2 :v-adjust 0.1))) all-the-icons-octicon "lock" :height 1.2 :v-adjust 0.1)))
(result (cdr (assoc (format-mode-line "%*") config-alist)))) (result (cdr (assoc (format-mode-line "%*") config-alist))))
(propertize (apply (cadr result) (cddr result)) (let ((res (propertize (apply (cadr result) (cddr result))
'face `(:family ,(funcall (car result)))))) 'face `(:background ,(evil-tag-color) :family ,(funcall (car result))))))
(propertize (format " %s" res) 'face `(:background ,(evil-tag-color) :family ,(funcall (car result)))))))
(defun custom-modeline-mode-icon () (defun custom-modeline-mode-icon ()
(let ((icon (all-the-icons-icon-for-buffer))) (let ((icon (all-the-icons-icon-for-buffer)))
@@ -102,54 +105,51 @@ can be used to add a number of spaces to the front and back of the string."
'face `(:height 0.8);; :foreground ,(powerline-fg) :background ,(powerline-c1)) 'face `(:height 0.8);; :foreground ,(powerline-fg) :background ,(powerline-c1))
'display '(raise 0.1))))) 'display '(raise 0.1)))))
(defun mode-line-fill (reserve)
"Return empty space leaving RESERVE space on the right."
(unless reserve
(setq reserve 20))
(when (and window-system (eq 'right (get-scroll-bar-mode)))
(setq reserve (- reserve 3)))
(propertize " "
'display
`((space :align-to (- (+ right right-fringe right-margin)
,reserve)))))
(defun line-count-line () (defun line-count-line ()
(let* ((bg (time-tag-bg-color))
(fg (time-tag-fg-color)))
(concat (propertize (concat (propertize
(all-the-icons-faicon "rebel") (all-the-icons-faicon "rebel")
'face `(:height 0.8 :background "#86261c") 'display '(raise 0.2)) 'face `(:height 0.8 :background ,bg :foreground ,fg) 'display '(raise 0.2))
(propertize (propertize
(format " %%l/%d " (format " %%l/%d "
(count-lines (point-min) (point-max))) (count-lines (point-min) (point-max)))
'face `(:background "#86261c")))) 'face `(:background ,bg :foreground ,fg)))))
(defun powerline-time () (defun powerline-time ()
(let* ((hour (string-to-number (format-time-string "%I"))) (let* ((hour (string-to-number (format-time-string "%I")))
(icon (all-the-icons-wicon (format "time-%s" hour) :height 1.0 :v-adjust 0.0))) (icon (all-the-icons-wicon (format "time-%s" hour) :height 1.0 :v-adjust 0.0))
(bg (time-tag-bg-color))
(fg (time-tag-fg-color)))
(concat (concat
(propertize (format-time-string " %H:%M ") (propertize (format-time-string " %H:%M ")
'face `(:height 1.0 :background "#86261c")) 'face `(:height 1.0 :background ,bg :foreground ,fg))
(propertize (format "%s" icon) (propertize (format "%s" icon)
'face `(:height 1.0 :family "Weather Icons" :background "#86261c") 'face `(:height 1.0 :family "Weather Icons" :background ,bg :foreground ,fg)
'display '(raise -0.0)) 'display '(raise -0.0))
(propertize " · " 'face `(:height 1.0 :background "#86261c"))))) (propertize " · " 'face `(:height 1.0 :background ,bg :foreground ,fg)))))
(defvar separator-left (propertize "" 'face `(:height 1.1 :foreground "#86261c") 'display '(raise -0.0)))
(defvar separator-right (propertize "" 'face `(:height 1.1 :foreground "#86261c") 'display '(raise -0.0)))
(setq-default mode-line-format (setq-default mode-line-format
(list (list
mode-line-front-space
'((:eval (fancy-mode-line-render '((:eval (fancy-mode-line-render
;; left ;; left
(format-mode-line (format-mode-line
(concat (concat
(powerline-modified) (powerline-modified)
(propertize (evil-mode-state) 'face 'bold) (evil-mode-state)
(vc-mode-branch-state)
(custom-modeline-mode-icon) ;; %m (custom-modeline-mode-icon) ;; %m
" %b " " %b "))
(vc-mode-branch-state)))
;;center ;;center
" " " "
;; right ;; right
(format-mode-line (format-mode-line
(concat (concat
separator-left
;; (format-time-string "%H:%M ") ;; (format-time-string "%H:%M ")
(powerline-time) (powerline-time)
(line-count-line))) (line-count-line)))

View File

@@ -6,7 +6,7 @@
'(font . "-ypn-envypn-medium-r-normal--15-150-75-75-c-90-iso8859-1")) '(font . "-ypn-envypn-medium-r-normal--15-150-75-75-c-90-iso8859-1"))
(set-frame-font (set-frame-font
"-ypn-envypn-medium-r-normal--15-150-75-75-c-90-iso8859-1") "-ypn-envypn-medium-r-normal--15-150-75-75-c-90-iso8859-1")
(fringe-mode '(0 . 0))
;; (set-face-background 'mode-line "#181818") ;; (set-face-background 'mode-line "#181818")
;; (set-face-font 'mode-line "Iosevka Term-10") ;; (set-face-font 'mode-line "Iosevka Term-10")
;; (set-face-font 'mode-line-buffer-id "Iosevka Term-10") ;; (set-face-font 'mode-line-buffer-id "Iosevka Term-10")

View File

@@ -24,7 +24,7 @@
(if (display-graphic-p) (if (display-graphic-p)
(setq my:theme-window-loaded t) (setq my:theme-window-loaded t)
(setq my:theme-terminal-loaded t))) (setq my:theme-terminal-loaded t)))
(set-frame-parameter (selected-frame) 'internal-border-width 7)) (set-frame-parameter (selected-frame) 'internal-border-width 5))
(custom-set-faces (custom-set-faces
;; term ;; term