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."
(concat (file-name-nondirectory buffer-file-name) (if buffer-file-name
(if (buffer-modified-p) (concat (file-name-nondirectory buffer-file-name)
(propertize "*" 'face 'mode-line-is-modified)) (if (buffer-modified-p)
" ") (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)) (let* ((max-length (/ (window-width) 2))
(progn (project-path (narf/project-root))
(let* ((max-length (/ (window-width) 2)) (path (file-name-directory
(project-path (narf/project-root)) (file-relative-name buffer-file-name
(path (file-name-directory (file-name-directory (if (string-match "/+\\'" project-path)
(file-relative-name buffer-file-name (replace-match "" t t project-path)
(file-name-directory (if (string-match "/+\\'" project-path) project-path)))))
(replace-match "" t t project-path) (path-len (length path)))
project-path)))))) (if (> path-len max-length)
(if (> (length path) max-length) (concat "" (replace-regexp-in-string
(concat "" (replace-regexp-in-string "^.*?/" "/"
"^.*?/" "/" (substring path (- path-len max-length) path-len)))
(let ((l (length path))) (substring path (- l max-length) l)))) 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