]> code.delx.au - gnu-emacs-elpa/commitdiff
Generate a global resetter in `defhydradio'
authorOleh Krehel <ohwoeowho@gmail.com>
Thu, 19 Feb 2015 17:45:46 +0000 (18:45 +0100)
committerOleh Krehel <ohwoeowho@gmail.com>
Thu, 19 Feb 2015 17:45:46 +0000 (18:45 +0100)
* hydra.el (defhydradio): `NAME/reset-radios' will be generated.
(hydra--quote-maybe): Don't quote nil.

* hydra-test.el: Update test.

hydra-test.el
hydra.el

index 429cf14fc507170c213acef276ba21acb23fd5d0..96f02da80dafc4facd0cc5ece96c508ca1a0b850 100644 (file)
@@ -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)
 
index fcb8cdeaff249e4dd8632df680c4f42960441500..a3024c470b89c0d682b74c1e760e8dac1e55cd0f 100644 (file)
--- 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."