ui/modeline: cache buffer id for +light modeline
This commit is contained in:
parent
6352524d32
commit
848cc117c4
1 changed files with 33 additions and 12 deletions
|
@ -353,20 +353,41 @@ 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.
|
||||
(add-hook! '(change-major-mode-after-body-hook
|
||||
;; In case the user saves the file to a new location
|
||||
after-save-hook
|
||||
;; ...or makes external changes then returns to Emacs
|
||||
focus-in-hook
|
||||
;; ...or when we change the current project!
|
||||
projectile-after-switch-project-hook
|
||||
;; ...when the underlying file changes
|
||||
after-revert-hook)
|
||||
(defun +modeline--generate-buffer-id-cache-h ()
|
||||
(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))
|
||||
(concat project-root "..")))))))))
|
||||
|
||||
(def-modeline-var! +modeline-buffer-identification ; slightly more informative buffer id
|
||||
'((:eval
|
||||
(let ((file-name (buffer-file-name (buffer-base-buffer))))
|
||||
(propertize
|
||||
(or (when (and file-name (not (file-remote-p file-name)))
|
||||
(when-let (project (doom-project-root file-name))
|
||||
(file-relative-name (or buffer-file-truename (file-truename file-name))
|
||||
(concat project ".."))))
|
||||
"%b")
|
||||
'face (cond ((buffer-modified-p)
|
||||
'(error bold mode-line-buffer-id))
|
||||
((+modeline-active)
|
||||
'mode-line-buffer-id))
|
||||
'help-echo file-name)))
|
||||
(propertize
|
||||
(or +modeline--buffer-id-cache "%b")
|
||||
'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