mode-line: optimize buffer path

This commit is contained in:
Henrik Lissner 2016-04-26 02:03:42 -04:00
parent 61cdc94463
commit fb25f716f9

View file

@ -240,33 +240,42 @@
(format-mode-line "%l")))))) (format-mode-line "%l"))))))
;; Mode-line ;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;
;; Mode-line
;;
(use-package spaceline (use-package spaceline
:init :init
(defvar narf--env-version nil) (defvar-local narf--env-version nil)
(defvar narf--env-command nil) (defvar-local narf--env-command nil)
(make-variable-buffer-local 'narf--env-version) (defvar powerline-height 23)
(make-variable-buffer-local 'narf--env-command)
:config
(setq-default (setq-default
powerline-default-separator nil powerline-default-separator nil
powerline-height 25
spaceline-highlight-face-func 'spaceline-highlight-face-evil-state) spaceline-highlight-face-func 'spaceline-highlight-face-evil-state)
:config
(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-file nil "Face for mode-line buffer file path") (defface mode-line-buffer-file nil "Face for mode-line buffer file path")
;; Custom modeline segments ;; Custom modeline segments
(spaceline-define-segment *buffer-path (spaceline-define-segment *buffer-path
(if buffer-file-name (if buffer-file-name
(let* ((project-path (let (projectile-require-project-root) (projectile-project-root))) (let* ((project-path (narf/project-root))
(buffer-path (f-relative buffer-file-name project-path)) (buffer-path (f-relative buffer-file-name project-path))
(max-length (truncate (/ (window-width) 2))) (max-length 40))
(path-len (length buffer-path))) (concat (projectile-project-name) "/"
(if (> path-len max-length) (if (> (length buffer-path) max-length)
(f-filename buffer-path) (let ((path (reverse (split-string buffer-path "/")))
(concat (f-filename project-path) "/" buffer-path))) (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)))
output)
buffer-path)))
"%b") "%b")
:face (if active 'mode-line-buffer-file 'mode-line-inactive) :face (if active 'mode-line-buffer-file 'mode-line-inactive)
:skip-alternate t :skip-alternate t