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

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

[elpa] externals/hydra 3846e2728f 32/46: hydra.el (hydra-interpose): Ext


From: Stefan Monnier
Subject: [elpa] externals/hydra 3846e2728f 32/46: hydra.el (hydra-interpose): Extract
Date: Tue, 25 Oct 2022 22:27:22 -0400 (EDT)

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

    hydra.el (hydra-interpose): Extract
---
 hydra.el | 31 +++++++++++++++++++++----------
 1 file changed, 21 insertions(+), 10 deletions(-)

diff --git a/hydra.el b/hydra.el
index b1d4bd52b9..61f92ec2f4 100644
--- a/hydra.el
+++ b/hydra.el
@@ -1103,17 +1103,28 @@ representing the maximum dimension of their owning 
group.
                         decorated-heads) res)))
       (nreverse res))))
 
+(defun hydra-interpose (x lst)
+  "Insert X in between each element of LST."
+  (let (res y)
+    (while (setq y (pop lst))
+      (push y res)
+      (push x res))
+    (nreverse (cdr res))))
+
 (defun hydra--hint-row (heads body)
-  (replace-regexp-in-string
-   "\s+$" ""
-   (mapconcat (lambda (head)
-                (funcall hydra-key-doc-function
-                         (hydra-fontify-head head body) ;; key
-                         (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 "| ")))
+  (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))))
+    (replace-regexp-in-string
+     "\s+$" ""
+     (apply #'concat lst))))
 
 (defun hydra--hint-from-matrix (body heads-matrix)
   "Generate a formated table-style docstring according to BODY and 
HEADS-MATRIX.



reply via email to

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