From 5adedd5953ff1369c138a4fae10a09e17693ae67 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Fri, 4 Jan 2019 22:29:07 +0800 Subject: [PATCH] Don't start github timer if doom-modeline-github is nil. Also watch the change of doom-modeline-github to run or cancel the timer. This only support 26 and above. Need to restart Emacs to effect in 25. See https://github.com/seagle0128/doom-modeline/issues/66#issuecomment-451397481. --- doom-modeline.el | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/doom-modeline.el b/doom-modeline.el index babc019..82d3cd1 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -1859,9 +1859,26 @@ mouse-3: Describe current input method") (setq doom-modeline--github-notifications-number (length result)))))) -(run-with-timer 30 - doom-modeline-github-interval - #'doom-modeline--github-fetch-notifications) +(defvar doom-modeline--github-timer nil) +(defun doom-modeline-github-timer () + "Start/Stop the timer for github fetching." + (if (timerp doom-modeline--github-timer) + (cancel-timer doom-modeline--github-timer)) + (setq doom-modeline--github-timer + (and doom-modeline-github + (run-with-timer 30 + doom-modeline-github-interval + #'doom-modeline--github-fetch-notifications)))) + +(when (>= emacs-major-version 26) + (add-variable-watcher + 'doom-modeline-github + (lambda (_sym val op _where) + (when (eq op 'set) + (setq doom-modeline-github val) + (doom-modeline-github-timer))))) + +(doom-modeline-github-timer) (defun doom-modeline--github-open-notifications () "Open GitHub Notifications page."