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

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

[nongnu] elpa/keycast cf475dcb5a 18/31: keycast--format: New function


From: ELPA Syncer
Subject: [nongnu] elpa/keycast cf475dcb5a 18/31: keycast--format: New function
Date: Sun, 9 Jan 2022 05:58:45 -0500 (EST)

branch: elpa/keycast
commit cf475dcb5a0517d479ee4eebfff6cc9d42b7ac0d
Author: Jonas Bernoulli <jonas@bernoul.li>
Commit: Jonas Bernoulli <jonas@bernoul.li>

    keycast--format: New function
---
 keycast.el | 53 ++++++++++++++++++++++++++++-------------------------
 1 file changed, 28 insertions(+), 25 deletions(-)

diff --git a/keycast.el b/keycast.el
index 256a6f3e8c..b348786443 100644
--- a/keycast.el
+++ b/keycast.el
@@ -178,6 +178,33 @@ instead."
   (setq keycast--this-command this-command)
   (force-mode-line-update))
 
+(defun keycast--format (format)
+  (and (not keycast--reading-passwd)
+       (let* ((key (ignore-errors
+                     (key-description keycast--this-command-keys)))
+              (cmd keycast--this-command)
+              (elt (or (assoc cmd keycast-substitute-alist)
+                       (assoc key keycast-substitute-alist))))
+         (when elt
+           (pcase-let ((`(,_ ,k ,c) elt))
+             (unless (eq k t) (setq key k))
+             (unless (eq c t) (setq cmd c))))
+         (and key cmd
+              (let ((k (let ((pad (max 2 (- 5 (length key)))))
+                         (concat (make-string (ceiling pad 2) ?\s) key
+                                 (make-string (floor   pad 2) ?\s))))
+                    (c (format " %s" cmd)))
+                (format-spec
+                 format
+                 `((?s . ,(make-string keycast-separator-width ?\s))
+                   (?k . ,(propertize k 'face 'keycast-key))
+                   (?K . ,k)
+                   (?c . ,(propertize c 'face 'keycast-command))
+                   (?C . ,c)
+                   (?r . ,(if (> keycast--command-repetitions 0)
+                              (format " x%s" (1+ keycast--command-repetitions))
+                            "")))))))))
+
 (defvar keycast--removed-tail nil)
 
 ;;;###autoload
@@ -234,31 +261,7 @@ instead."
 (defvar mode-line-keycast
   '(:eval
     (and (funcall keycast-window-predicate)
-         (not keycast--reading-passwd)
-         (let* ((key (ignore-errors
-                       (key-description keycast--this-command-keys)))
-                (cmd keycast--this-command)
-                (elt (or (assoc cmd keycast-substitute-alist)
-                         (assoc key keycast-substitute-alist))))
-           (when elt
-             (pcase-let ((`(,_ ,k ,c) elt))
-               (unless (eq k t) (setq key k))
-               (unless (eq c t) (setq cmd c))))
-           (and key cmd
-                (let ((k (let ((pad (max 2 (- 5 (length key)))))
-                           (concat (make-string (ceiling pad 2) ?\s) key
-                                   (make-string (floor   pad 2) ?\s))))
-                      (c (format " %s" cmd)))
-                  (format-spec
-                   mode-line-keycast-format
-                   `((?s . ,(make-string keycast-separator-width ?\s))
-                     (?k . ,(propertize k 'face 'keycast-key))
-                     (?K . ,k)
-                     (?c . ,(propertize c 'face 'keycast-command))
-                     (?C . ,c)
-                     (?r . ,(if (> keycast--command-repetitions 0)
-                                (format " x%s" (1+ 
keycast--command-repetitions))
-                              ""))))))))))
+         (keycast--format mode-line-keycast-format))))
 
 (put 'mode-line-keycast 'risky-local-variable t)
 (make-variable-buffer-local 'mode-line-keycast)



reply via email to

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