Polish mode-line

This commit is contained in:
Henrik Lissner 2015-10-13 00:46:17 -04:00
parent 8e651cd1ae
commit be03e48ffe

View file

@ -2,7 +2,7 @@
;; see lib/ui-defuns.el ;; see lib/ui-defuns.el
(when window-system (when window-system
(fringe-mode '(3 . 2)) (fringe-mode '(2 . 3))
(set-frame-font narf-default-font) (set-frame-font narf-default-font)
(setq frame-title-format '(buffer-file-name "%f" ("%b")))) (setq frame-title-format '(buffer-file-name "%f" ("%b"))))
@ -44,7 +44,9 @@
("*scratch*" :position bottom :height 20 :stick t :dedicated t) ("*scratch*" :position bottom :height 20 :stick t :dedicated t)
("*helm-ag-edit*" :position bottom :height 20 :stick t) ("*helm-ag-edit*" :position bottom :height 20 :stick t)
("^\\*[Hh]elm.*?\\*\\'" :regexp t :position bottom :height 15) ("^\\*[Hh]elm.*?\\*\\'" :regexp t :position bottom :height 15)
("*eshell*" :position left :width 80 :stick t :dedicated t))) ("*eshell*" :position left :width 80 :stick t :dedicated t)
("*Apropos*" :position bottom :height 40 :stick t :dedicated t)
("*Backtrace*" :position bottom :height 15 :stick t)))
(popwin-mode 1)) (popwin-mode 1))
(use-package yascroll (use-package yascroll
@ -159,43 +161,49 @@
(add-hook! focus-in (setq narf--spaceline-file-path nil)) (add-hook! focus-in (setq narf--spaceline-file-path nil))
(defface mode-line-is-modified nil "Face for mode-line modified symbol") (defface mode-line-is-modified nil "Face for mode-line modified symbol")
(defface mode-line-buffer-path nil "Face for mode-line buffer directory") (defface mode-line-buffer-file nil "Face for mode-line buffer file path")
(defface mode-line-buffer-dir nil "Face for mode-line buffer dirname")
;; Custom modeline segments ;; Custom modeline segments
(spaceline-define-segment narf-buffer-path (spaceline-define-segment narf-buffer-path
"Base filename of buffer." "Buffer file path."
(if buffer-file-name (let ((buffer (propertize "%b" 'face
(concat (file-name-nondirectory buffer-file-name) (if (powerline-selected-window-active)
(if (buffer-modified-p) 'mode-line-buffer-file
(propertize "*" 'face 'mode-line-is-modified)) 'mode-line-inactive))))
" ") (concat (if buffer-file-name
(format " %s " (powerline-buffer-id))) (concat (propertize
:tight t) (let* ((max-length (/ (window-width) 2))
(project-path (let ((p (narf/project-root)))
(spaceline-define-segment narf-buffer-dir (if (string-match "/+\\'" p)
"Buffer file directory." (replace-match "" t t p)
(propertize p)))
(or narf--spaceline-file-path (path (f-dirname (f-relative buffer-file-truename (f-dirname project-path))))
(setq narf--spaceline-file-path (path-len (length path)))
(let* ((max-length (/ (window-width) 2)) (if (> path-len max-length)
(project-path (narf/project-root)) (concat "" (replace-regexp-in-string
(path (file-name-directory "^.*?/" "/"
(file-relative-name buffer-file-name (substring path (- path-len max-length) path-len)))
(file-name-directory (if (string-match "/+\\'" project-path) path))
(replace-match "" t t project-path) 'face (if (powerline-selected-window-active)
project-path))))) 'mode-line-buffer-dir
(path-len (length path))) 'mode-line-inactive)
(if (> path-len max-length) )
(concat "" (replace-regexp-in-string buffer
"^.*?/" "/" (if (and buffer-file-name (buffer-modified-p))
(substring path (- path-len max-length) path-len))) (propertize "%+" 'face 'mode-line-is-modified)))
path)))) buffer)
'face (if (powerline-selected-window-active) " "))
'mode-line-buffer-path ;; Causes right side of this segment to be square
'mode-line-inactive)) :face line-face
:when buffer-file-name
:tight-right t) :tight-right t)
(spaceline-define-segment narf-buffer-project-name
"The project name."
(file-name-nondirectory (f-expand (narf/project-root)))
:when (and (not (derived-mode-p 'special-mode))
(string-match-p "^ ?\\*" (buffer-name))))
(spaceline-define-segment narf-buffer-encoding-abbrev (spaceline-define-segment narf-buffer-encoding-abbrev
"The line ending convention used in the buffer." "The line ending convention used in the buffer."
(let ((buf-coding (symbol-name buffer-file-coding-system))) (let ((buf-coding (symbol-name buffer-file-coding-system)))
@ -218,6 +226,7 @@
(format " %s %s%s " (char-to-string #xe0a0) vc (format " %s %s%s " (char-to-string #xe0a0) vc
(case (vc-state buffer-file-name) ('edited "+") ('conflict "!!!") (t ""))))) (case (vc-state buffer-file-name) ('edited "+") ('conflict "!!!") (t "")))))
:when (and active vc-mode) :when (and active vc-mode)
:face other-face
:tight t) :tight t)
;; Display version string ;; Display version string
@ -240,23 +249,28 @@
(spaceline-define-segment narf-line-column (spaceline-define-segment narf-line-column
"The current line and column numbers." "The current line and column numbers."
"%l/%c" "%l/%c")
:when active)
(spaceline-define-segment narf-evil-state
"The current evil state. Requires `evil-mode' to be enabled."
(concat (substring (evil-state-property evil-state :tag t) 2 3) " ")
:when (and active (bound-and-true-p evil-local-mode))
:tight-right t)
;; Initialize modeline ;; Initialize modeline
(spaceline-install (spaceline-install
;; Left side ;; Left side
'((narf-buffer-dir :face other-face) '((narf-buffer-path remote-host)
(narf-buffer-path remote-host)
narf-vc narf-vc
narf-buffer-project-name
((flycheck-error flycheck-warning flycheck-info) :when active)) ((flycheck-error flycheck-warning flycheck-info) :when active))
;; Right side ;; Right side
'(selection-info '(selection-info
anzu
narf-env-version narf-env-version
narf-buffer-encoding-abbrev narf-buffer-encoding-abbrev
((" " :tight t) ((" " :tight t)
major-mode major-mode (minor-modes :separator " ")
(minor-modes :separator " ")
process :when active) process :when active)
(global :when active) (global :when active)
(narf-line-column narf-buffer-position) (narf-line-column narf-buffer-position)