ui/modeline: refactor buffer-id segment
This commit is contained in:
parent
b3006ecabb
commit
2e2f72a2de
1 changed files with 22 additions and 26 deletions
|
@ -157,9 +157,8 @@ LHS and RHS will accept."
|
|||
(push docstring plist)
|
||||
(setq docstring nil))
|
||||
`(progn
|
||||
(defvar ,name nil ,docstring)
|
||||
(defconst ,name ,body ,docstring)
|
||||
,@(if (plist-get plist :local) `((make-variable-buffer-local ',name)))
|
||||
(setq-default ,name ,body)
|
||||
(put ',name 'risky-local-variable t)))
|
||||
|
||||
|
||||
|
@ -355,7 +354,6 @@ Requires `anzu', also `evil-anzu' if using `evil-mode' for compatibility with
|
|||
;;; `+modeline-buffer-identification'
|
||||
(defvar-local +modeline--buffer-id-cache nil)
|
||||
|
||||
(add-transient-hook! 'doom-first-buffer-hook
|
||||
;; REVIEW Generating the buffer's file name can be relatively expensive.
|
||||
;; Compounded with how often the modeline updates this can add up, so
|
||||
;; we cache it ahead of time.
|
||||
|
@ -371,24 +369,22 @@ Requires `anzu', also `evil-anzu' if using `evil-mode' for compatibility with
|
|||
;; ...when the underlying file changes
|
||||
after-revert-hook)
|
||||
(defun +modeline--generate-buffer-id-cache-h ()
|
||||
(when after-init-time
|
||||
(setq +modeline--buffer-id-cache
|
||||
(let ((file-name (buffer-file-name (buffer-base-buffer))))
|
||||
(unless (or (null default-directory)
|
||||
(null file-name)
|
||||
(file-remote-p file-name))
|
||||
(when-let ((project-root (doom-project-root)))
|
||||
(file-relative-name
|
||||
(or buffer-file-truename (file-truename file-name))
|
||||
(when-let (project-root (doom-project-root))
|
||||
(file-relative-name (or buffer-file-truename (file-truename file-name))
|
||||
(concat project-root "..")))))))))
|
||||
|
||||
(def-modeline-var! +modeline-buffer-identification ; slightly more informative buffer id
|
||||
'((:eval
|
||||
(propertize
|
||||
(or +modeline--buffer-id-cache "%b")
|
||||
'face (cond ((buffer-modified-p)
|
||||
'(error bold mode-line-buffer-id))
|
||||
((+modeline-active)
|
||||
'mode-line-buffer-id))
|
||||
'face (cond ((buffer-modified-p) '(error bold mode-line-buffer-id))
|
||||
((+modeline-active) 'mode-line-buffer-id))
|
||||
'help-echo (or +modeline--buffer-id-cache (buffer-name))))
|
||||
(buffer-read-only (:propertize " RO" face warning))))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue