branch: master commit b81d078e7713722ac0688a6bdb907d46d37a0e3e Author: Oleh Krehel <ohwoeo...@gmail.com> Commit: Oleh Krehel <ohwoeo...@gmail.com>
Generate a global resetter in `defhydradio' * hydra.el (defhydradio): `NAME/reset-radios' will be generated. (hydra--quote-maybe): Don't quote nil. * hydra-test.el: Update test. --- hydra-test.el | 5 ++++- hydra.el | 27 +++++++++++++++++++-------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/hydra-test.el b/hydra-test.el index 429cf14..96f02da 100644 --- a/hydra-test.el +++ b/hydra-test.el @@ -586,7 +586,10 @@ The body can be accessed via `hydra-vi/body'." "Str") (put 'hydra-test/str 'range ["foo" "bar" "baz"]) (defun hydra-test/str () - (hydra--cycle-radio 'hydra-test/str)))))) + (hydra--cycle-radio 'hydra-test/str)) + (defun hydra-test/reset-radios () + (setq hydra-test/num 0) + (setq hydra-test/str "foo")))))) (provide 'hydra-test) diff --git a/hydra.el b/hydra.el index fcb8cde..a3024c4 100644 --- a/hydra.el +++ b/hydra.el @@ -602,11 +602,19 @@ inialize the variable. VALUE defaults to [nil t]. DOC defaults to TOGGLE-NAME split and capitalized." (declare (indent defun)) - (cons 'progn - (apply #'append - (mapcar (lambda (h) - (hydra--radio name h)) - heads)))) + `(progn + ,@(apply #'append + (mapcar (lambda (h) + (hydra--radio name h)) + heads)) + (defun ,(intern (format "%S/reset-radios" name)) () + ,@(mapcar + (lambda (h) + (let ((full-name (intern (format "%S/%S" name (car h)))) + ) + `(setq ,full-name ,(hydra--quote-maybe + (and (cadr h) (aref (cadr h) 0)))))) + heads)))) (defun hydra--radio (parent head) "Generate a hydradio with PARENT from HEAD." @@ -624,9 +632,12 @@ DOC defaults to TOGGLE-NAME split and capitalized." (defun hydra--quote-maybe (x) "Quote X if it's a symbol." - (if (symbolp x) - (list 'quote x) - x)) + (cond ((null x) + nil) + ((symbolp x) + (list 'quote x)) + (t + x))) (defun hydra--cycle-radio (sym) "Set SYM to the next value in its range."