hydra.el (hydra-key-doc-function-default): Accept also sexp as doc

* hydra-test.el (hydra-column-sexp): Add test.

Fixes #304
master
Oleh Krehel 7 years ago
parent aa55bbd196
commit 9c4a4711bc
  1. 31
      hydra-test.el
  2. 32
      hydra.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"))

@ -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))

Loading…
Cancel
Save