Modeline: optimize narf-buffer-dir; fix narf-buffer-path

This commit is contained in:
Henrik Lissner 2015-10-03 04:21:24 -04:00
parent 9b0859e2c8
commit e7e0f983f1

View file

@ -118,10 +118,12 @@
;; Custom modeline segments ;; Custom modeline segments
(spaceline-define-segment narf-buffer-path (spaceline-define-segment narf-buffer-path
"Base filename of buffer." "Base filename of buffer."
(if buffer-file-name
(concat (file-name-nondirectory buffer-file-name) (concat (file-name-nondirectory buffer-file-name)
(if (buffer-modified-p) (if (buffer-modified-p)
(propertize "*" 'face 'mode-line-is-modified)) (propertize "*" 'face 'mode-line-is-modified))
" ") " ")
(powerline-buffer-id))
:tight t) :tight t)
(spaceline-define-segment narf-buffer-dir (spaceline-define-segment narf-buffer-dir
@ -129,24 +131,23 @@
(propertize (propertize
(or narf--spaceline-file-path (or narf--spaceline-file-path
(setq narf--spaceline-file-path (setq narf--spaceline-file-path
(if (and buffer-file-name (file-exists-p buffer-file-name))
(progn
(let* ((max-length (/ (window-width) 2)) (let* ((max-length (/ (window-width) 2))
(project-path (narf/project-root)) (project-path (narf/project-root))
(path (file-name-directory (path (file-name-directory
(file-relative-name buffer-file-name (file-relative-name buffer-file-name
(file-name-directory (if (string-match "/+\\'" project-path) (file-name-directory (if (string-match "/+\\'" project-path)
(replace-match "" t t project-path) (replace-match "" t t project-path)
project-path)))))) project-path)))))
(if (> (length path) max-length) (path-len (length path)))
(if (> path-len max-length)
(concat "" (replace-regexp-in-string (concat "" (replace-regexp-in-string
"^.*?/" "/" "^.*?/" "/"
(let ((l (length path))) (substring path (- l max-length) l)))) (substring path (- path-len max-length) path-len)))
path))) path))))
(powerline-buffer-id))))
'face (if (powerline-selected-window-active) 'face (if (powerline-selected-window-active)
'mode-line-buffer-path 'mode-line-buffer-path
'mode-line-inactive)) 'mode-line-inactive))
:when buffer-file-name
:tight-right t) :tight-right t)
(spaceline-define-segment narf-buffer-encoding-abbrev (spaceline-define-segment narf-buffer-encoding-abbrev