emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/notmuch-indicator c25a06f313 1/2: Fix how indicator is


From: ELPA Syncer
Subject: [elpa] externals/notmuch-indicator c25a06f313 1/2: Fix how indicator is added to global-mode-string
Date: Fri, 23 Sep 2022 06:57:54 -0400 (EDT)

branch: externals/notmuch-indicator
commit c25a06f31343abb2bd45687ec51e5dc3257e0fb7
Author: Protesilaos Stavrou <info@protesilaos.com>
Commit: Protesilaos Stavrou <info@protesilaos.com>

    Fix how indicator is added to global-mode-string
    
    We want to pass it as a symbol instead of a string.  This is how other
    modes do it as well.  The result is still the same for the user, though
    this design ensures that we do not get false positives when we try to
    remove our indicator (e.g. if we target an empty string, we can delete
    something else).
    
    Thanks to Yusef Aslam for reporting a bug which revealed this problem.
    This was done in issue 1 over at the GitHub mirror:
    <https://github.com/protesilaos/notmuch-indicator/issues/1>.
---
 notmuch-indicator.el | 32 +++++++++++++++++++-------------
 1 file changed, 19 insertions(+), 13 deletions(-)

diff --git a/notmuch-indicator.el b/notmuch-indicator.el
index 3c521516e2..87529c251a 100644
--- a/notmuch-indicator.el
+++ b/notmuch-indicator.el
@@ -190,21 +190,27 @@ option `notmuch-indicator-refresh-count'."
      (notmuch-indicator--format-output props))
    notmuch-indicator-args))
 
-(defvar notmuch-indicator--last-state nil
-  "Internal variable used to store the indicator's state.")
+(defvar notmuch-indicator-string ""
+  "String showing the `notmuch-indicator' state.
+It is appended to the `global-mode-string'.")
+(put 'notmuch-indicator-string 'risky-local-variable t)
 
 (defun notmuch-indicator--indicator ()
   "Prepare new mail count mode line indicator."
-  (let* ((count (notmuch-indicator--return-count))
-         (old-indicator notmuch-indicator--last-state))
-    (when old-indicator
-      (setq global-mode-string (delete old-indicator global-mode-string)))
-    (cond
-     (count
-      (setq global-mode-string (push count global-mode-string))
-      (setq notmuch-indicator--last-state count))
-     (t
-      (setq notmuch-indicator--last-state nil))))
+  (when (not (string-empty-p notmuch-indicator-string))
+    (setq global-mode-string (delq 'notmuch-indicator-string 
global-mode-string)))
+  (if-let ((count (notmuch-indicator--return-count)))
+      (setq notmuch-indicator-string count
+            ;; FIXME 2022-09-22: This may be hacky, but I cannot remember or
+            ;; find a function that appends an element as the second in a
+            ;; list.  I don't want it to be at the very start or end...
+            global-mode-string
+            (reverse
+             (append
+              (butlast (reverse global-mode-string))
+              '(notmuch-indicator-string)
+              '(""))))
+    (setq notmuch-indicator-string ""))
   (force-mode-line-update t))
 
 (defun notmuch-indicator--running-p ()
@@ -244,7 +250,7 @@ option `notmuch-indicator-refresh-count'.."
         (dolist (fn notmuch-indicator-force-refresh-commands)
           (advice-add fn :after #'notmuch-indicator--refresh)))
     (cancel-function-timers #'notmuch-indicator--indicator)
-    (setq global-mode-string (delete notmuch-indicator--last-state 
global-mode-string))
+    (setq global-mode-string (delq 'notmuch-indicator-string 
global-mode-string))
     (dolist (fn notmuch-indicator-force-refresh-commands)
       (advice-remove fn #'notmuch-indicator--refresh))
     (force-mode-line-update t)))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]