branch: elpa/keycast
commit 82affc7bb85b4b7c53c849cfd216b115d9f84972
Author: Jonas Bernoulli <jo...@bernoul.li>
Commit: Jonas Bernoulli <jo...@bernoul.li>

    keycast-mode-line-mode: Handle being enabled twice
    
    A user may enable the mode twice, without disabling it in between.
    The second time, this has to be done non-interactively, because
    invoking a mode command interactively toggles the mode.  I consider
    that a user-error, but let's recover from it anyway.
    
    Closes #34.
---
 keycast.el | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/keycast.el b/keycast.el
index d2e835ae6e..a5255f44b3 100644
--- a/keycast.el
+++ b/keycast.el
@@ -538,6 +538,7 @@ t to show the actual COMMAND, or a symbol to be shown 
instead."
 (defvar keycast--mode-line-removed-tail nil)
 (defvar keycast--temporary-mode-line nil)
 (defvar keycast--mode-line-modified-buffers nil)
+(defvar keycast--mode-line-enabled nil)
 
 ;;;###autoload
 (define-minor-mode keycast-mode-line-mode
@@ -545,6 +546,9 @@ t to show the actual COMMAND, or a symbol to be shown 
instead."
   :global t
   (cond
    (keycast-mode-line-mode
+    (when keycast--mode-line-enabled
+      (keycast-mode-line-mode -1)
+      (setq keycast-mode-line-mode t))
     (let ((format (default-value 'mode-line-format)))
       (cond ((not format)
              (setq keycast--temporary-mode-line t)
@@ -565,7 +569,8 @@ t to show the actual COMMAND, or a symbol to be shown 
instead."
             (t
              (setcdr cons (cl-pushnew 'keycast-mode-line (cdr cons)))))
       (add-hook 'post-command-hook #'keycast--update t)
-      (add-hook 'minibuffer-exit-hook #'keycast--minibuffer-exit t)))
+      (add-hook 'minibuffer-exit-hook #'keycast--minibuffer-exit t))
+    (setq keycast--mode-line-enabled t))
    (t
     (let ((cons (keycast--tree-member 'keycast-mode-line
                                       (default-value 'mode-line-format))))
@@ -588,7 +593,8 @@ t to show the actual COMMAND, or a symbol to be shown 
instead."
           (keycast--tree-member 'keycast-mode-line mode-line-format 'delete))))
     (unless (keycast--mode-active-p)
       (remove-hook 'post-command-hook #'keycast--update)
-      (remove-hook 'minibuffer-exit-hook #'keycast--minibuffer-exit)))))
+      (remove-hook 'minibuffer-exit-hook #'keycast--minibuffer-exit))
+    (setq keycast--mode-line-enabled nil))))
 
 (defvar keycast-mode-line
   '(:eval

Reply via email to