From 605c5615c10c4d94a495e7ac5c591f0c554a5923 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Tue, 12 Mar 2019 21:16:34 +0700 Subject: [PATCH] Simplify the variable watchers. --- doom-modeline-segments.el | 67 +++++++++++---------------------------- 1 file changed, 19 insertions(+), 48 deletions(-) diff --git a/doom-modeline-segments.el b/doom-modeline-segments.el index d5ad3ad..32200a1 100644 --- a/doom-modeline-segments.el +++ b/doom-modeline-segments.el @@ -164,6 +164,25 @@ (declare-function winum-get-number-string 'winum) +;; +;; global watchers +;; + +(when (>= emacs-major-version 26) + (add-variable-watcher + 'doom-modeline-icon + (lambda (_sym val op _where) + (when (eq op 'set) + (setq doom-modeline-icon val) + (revert-buffer t t)))) + + (add-variable-watcher + 'all-the-icons-scale-factor + (lambda (_sym val op _where) + (when (eq op 'set) + (setq all-the-icons-scale-factor val) + (revert-buffer t t))))) + ;; ;; buffer information ;; @@ -205,14 +224,6 @@ buffer where knowing the current project directory is important." (add-hook 'after-change-major-mode-hook #'doom-modeline-update-buffer-file-icon) (add-hook 'clone-indirect-buffer-hook #'doom-modeline-update-buffer-file-icon) -(when (>= emacs-major-version 26) - (add-variable-watcher - 'all-the-icons-scale-factor - (lambda (_sym val op _where) - (when (eq op 'set) - (setq all-the-icons-scale-factor val) - (doom-modeline-update-buffer-file-icon))))) - (defun doom-modeline-buffer-file-state-icon (icon &optional text face height voffset) "Displays an ICON with FACE, HEIGHT and VOFFSET. TEXT is the alternative if it is not applicable. @@ -275,20 +286,6 @@ Uses `all-the-icons-material' to fetch the icon." (lambda (_sym val op _where) (when (eq op 'set) (setq buffer-read-only val) - (doom-modeline-update-buffer-file-state-icon)))) - - (add-variable-watcher - 'doom-modeline-icon - (lambda (_sym val op _where) - (when (eq op 'set) - (setq doom-modeline-icon val) - (doom-modeline-update-buffer-file-state-icon)))) - - (add-variable-watcher - 'all-the-icons-scale-factor - (lambda (_sym val op _where) - (when (eq op 'set) - (setq all-the-icons-scale-factor val) (doom-modeline-update-buffer-file-state-icon))))) (defvar-local doom-modeline--buffer-file-name nil) @@ -532,14 +529,6 @@ Uses `all-the-icons-octicon' to fetch the icon." (add-hook 'after-save-hook #'doom-modeline--update-vcs-icon) (advice-add #'vc-refresh-state :after #'doom-modeline--update-vcs-icon) -(when (>= emacs-major-version 26) - (add-variable-watcher - 'doom-modeline-icon - (lambda (_sym val op _where) - (when (eq op 'set) - (setq doom-modeline-icon val) - (doom-modeline--update-vcs-icon))))) - (defvar-local doom-modeline--vcs-text nil) (defun doom-modeline-update-vcs-text (&rest _) "Update text of vsc state in mode-line." @@ -654,15 +643,6 @@ mouse-2: Show help for minor mode") (add-hook 'flycheck-status-changed-functions #'doom-modeline-update-flycheck-icon) (add-hook 'flycheck-mode-hook #'doom-modeline-update-flycheck-icon) -(when (>= emacs-major-version 26) - (add-variable-watcher - 'doom-modeline-icon - (lambda (_sym val op _where) - (when (eq op 'set) - (setq doom-modeline-icon val) - (when (bound-and-true-p flycheck-mode) - (flycheck-buffer)))))) - (defvar-local doom-modeline--flycheck-text nil) (defun doom-modeline-update-flycheck-text (&optional status) "Update flycheck text via STATUS." @@ -789,15 +769,6 @@ mouse-2: Show help for minor mode" map)))))) (advice-add #'flymake--handle-report :after #'doom-modeline-update-flymake-icon) -(when (>= emacs-major-version 26) - (add-variable-watcher - 'doom-modeline-icon - (lambda (_sym val op _where) - (when (eq op 'set) - (setq doom-modeline-icon val) - (when (bound-and-true-p flymake-mode) - (flymake-start)))))) - (defvar-local doom-modeline--flymake-text nil) (defun doom-modeline-update-flymake-text (&rest _) "Update flymake text."