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

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

[elpa] externals/hydra 9c4a4711bc 38/46: hydra.el (hydra-key-doc-functio


From: Stefan Monnier
Subject: [elpa] externals/hydra 9c4a4711bc 38/46: hydra.el (hydra-key-doc-function-default): Accept also sexp as doc
Date: Tue, 25 Oct 2022 22:27:22 -0400 (EDT)

branch: externals/hydra
commit 9c4a4711bc78364e114acbbcf484a60669d02d78
Author: Oleh Krehel <ohwoeowho@gmail.com>
Commit: Oleh Krehel <ohwoeowho@gmail.com>

    hydra.el (hydra-key-doc-function-default): Accept also sexp as doc
    
    * hydra-test.el (hydra-column-sexp): Add test.
    
    Fixes #304
---
 hydra-test.el | 31 +++++++++++++++++++++++++++++++
 hydra.el      | 32 +++++++++++++++++---------------
 2 files changed, 48 insertions(+), 15 deletions(-)

diff --git a/hydra-test.el b/hydra-test.el
index 048f37f5b2..75de3b28e6 100644
--- a/hydra-test.el
+++ b/hydra-test.el
@@ -1671,6 +1671,37 @@ k: ↑ window |                            |               
      |
                    512 513 (face hydra-face-red)
                    578 579 (face hydra-face-blue)))))
 
+(ert-deftest hydra-column-sexp ()
+  (should (equal
+           (eval (nth 5
+                      (macroexpand
+                       '(defhydra hydra-toggle-stuff ()
+                         "Toggle"
+                         ("d" toggle-debug-on-error "debug-on-error" :column 
"Misc")
+                         ("a" abbrev-mode
+                          (format "abbrev: %s"
+                           (if (bound-and-true-p abbrev-mode)
+                               "[x]"
+                             "[ ]")))))))
+           '(concat
+             (format "Toggle:\n")
+             "Misc"
+             "\n"
+             "-----------------"
+             "\n"
+             #("d: debug-on-error"
+               0 1 (face hydra-face-red))
+             "\n"
+             (format
+              "%1s: %-15s"
+              #("a" 0 1 (face hydra-face-red))
+              (format
+               "abbrev: %s"
+               (if (bound-and-true-p abbrev-mode)
+                   "[x]"
+                 "[ ]")))
+             "\n"))))
+
 (defhydra hydra-extendable ()
   "extendable"
   ("j" next-line "down"))
diff --git a/hydra.el b/hydra.el
index 652b943a1d..0f18b13028 100644
--- a/hydra.el
+++ b/hydra.el
@@ -498,9 +498,10 @@ Remove :color key. And sort the plist alphabetically."
   "The function for formatting key-doc pairs.")
 
 (defun hydra-key-doc-function-default (key key-width doc doc-width)
-  "Doc"
   (cond
     ((equal key " ") (format (format "%%-%ds" (+ 3 key-width doc-width)) doc))
+    ((listp doc)
+     `(format ,(format "%%%ds: %%%ds" key-width (- -1 doc-width)) ,key ,doc))
     (t (format (format "%%%ds: %%%ds" key-width (- -1 doc-width)) key doc))))
 
 (defun hydra--to-string (x)
@@ -1114,20 +1115,21 @@ representing the maximum dimension of their owning 
group.
     (nreverse (cdr res))))
 
 (defun hydra--hint-row (heads body)
-  (let* ((lst (hydra-interpose
-               "| "
-               (mapcar (lambda (head)
-                         (funcall hydra-key-doc-function
-                                  (hydra-fontify-head head body)
-                                  (let ((n (hydra--head-property head 
:max-key-len)))
-                                    (+ n (cl-count ?% (car head))))
-                                  (nth 2 head) ;; doc
-                                  (hydra--head-property head :max-doc-len)))
-                       heads)))
-         (len (length lst))
-         (new-last (replace-regexp-in-string "\s+$" "" (car (last lst)))))
-    (when (= 0 (length (setf (nth (- len 1) lst) new-last)))
-      (setf (nth (- len 2) lst) "|"))
+  (let ((lst (hydra-interpose
+              "| "
+              (mapcar (lambda (head)
+                        (funcall hydra-key-doc-function
+                                 (hydra-fontify-head head body)
+                                 (let ((n (hydra--head-property head 
:max-key-len)))
+                                   (+ n (cl-count ?% (car head))))
+                                 (nth 2 head) ;; doc
+                                 (hydra--head-property head :max-doc-len)))
+                      heads))))
+    (when (stringp (car (last lst)))
+      (let ((len (length lst))
+            (new-last (replace-regexp-in-string "\s+$" "" (car (last lst)))))
+        (when (= 0 (length (setf (nth (- len 1) lst) new-last)))
+          (setf (nth (- len 2) lst) "|"))))
     lst))
 
 



reply via email to

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