Refactor: rename the variables and funcations for font width.

This commit is contained in:
Vincent Zhang 2020-02-12 22:55:01 +08:00
parent f87b868bb9
commit 209ec76f56

View file

@ -627,22 +627,22 @@ It requires `circe' or `erc' package."
((error "%s is not a valid segment" seg)))) ((error "%s is not a valid segment" seg))))
(nreverse forms))) (nreverse forms)))
(defvar doom-modeline--width-cache nil) (defvar doom-modeline--font-width nil)
(defun doom-modeline--window-font-width () (defun doom-modeline--font-width ()
"Cache the font width." "Cache the font width."
(let ((attributes (face-all-attributes 'mode-line))) (let ((attributes (face-all-attributes 'mode-line)))
(or (cdr (assoc attributes doom-modeline--width-cache)) (or (cdr (assoc attributes doom-modeline--font-width))
(let ((width (window-font-width nil 'mode-line))) (let ((width (window-font-width nil 'mode-line)))
(push (cons attributes width) doom-modeline--width-cache) (push (cons attributes width) doom-modeline--font-width)
width)))) width))))
;; Refresh the font width after setting frame parameters ;; Refresh the font width after setting frame parameters
;; to ensure the font width is correct. ;; to ensure the font width is correct.
(defun doom-modeline--refresh-width-cache () (defun doom-modeline--refresh-font-width ()
"Refresh the font width cache." "Refresh the font width cache."
(setq doom-modeline--width-cache nil) (setq doom-modeline--font-width nil)
(doom-modeline--window-font-width)) (doom-modeline--font-width))
(add-hook 'window-setup-hook #'doom-modeline--refresh-width-cache) (add-hook 'window-setup-hook #'doom-modeline--refresh-font-width)
(defun doom-modeline-def-modeline (name lhs &optional rhs) (defun doom-modeline-def-modeline (name lhs &optional rhs)
"Defines a modeline format and byte-compiles it. "Defines a modeline format and byte-compiles it.
@ -664,7 +664,7 @@ It requires `circe' or `erc' package."
(propertize (propertize
(doom-modeline-spc) (doom-modeline-spc)
'display `((space :align-to (- (+ right right-fringe right-margin) 'display `((space :align-to (- (+ right right-fringe right-margin)
,(* (/ (doom-modeline--window-font-width) ,(* (/ (doom-modeline--font-width)
(frame-char-width) 1.0) (frame-char-width) 1.0)
(string-width (string-width
(format-mode-line (format-mode-line