55; ; Author: Oleh Krehel <ohwoeowho@gmail.com>
66; ; Maintainer: Oleh Krehel <ohwoeowho@gmail.com>
77; ; URL: https://github.com/abo-abo/hydra
8- ; ; Version: 0.10 .0
8+ ; ; Version: 0.11 .0
99; ; Keywords: bindings
1010; ; Package-Requires: ((cl-lib "0.5"))
1111
@@ -267,6 +267,7 @@ Return DEFAULT if PROP is not in H."
267267 " Return the color of a Hydra head H with BODY."
268268 (let* ((exit (hydra--head-property h :exit 'default ))
269269 (color (hydra--head-property h :color ))
270+ (foreign-keys (hydra--body-foreign-keys body))
270271 (head-color
271272 (cond ((eq exit 'default )
272273 (cl-case color
@@ -278,44 +279,55 @@ Return DEFAULT if PROP is not in H."
278279 ((null exit)
279280 (if color
280281 (error " Don't mix :color and :exit - they are aliases: %S " h)
281- 'red ))
282+ (cl-case foreign-keys
283+ (run 'pink )
284+ (warn 'amaranth )
285+ (t 'red ))))
282286 ((eq exit t )
283287 (if color
284288 (error " Don't mix :color and :exit - they are aliases: %S " h)
285289 'blue ))
286290 (t
287291 (error " Unknown :exit %S " exit)))))
288- (let ((nonheads (plist-get (cddr body) :nonheads ))
289- (body-exit (plist-get (cddr body) :exit )))
292+ (let ((body-exit (plist-get (cddr body) :exit )))
290293 (cond ((null (cadr h))
291294 (when head-color
292295 (hydra--complain
293296 " Doubly specified blue head - nil cmd is already blue: %S" h))
294297 'blue )
295298 ((null head-color)
296299 (hydra--body-color body))
297- ((null nonheads )
300+ ((null foreign-keys )
298301 head-color)
299- ((eq nonheads 'run )
302+ ((eq foreign-keys 'run )
300303 (if (eq head-color 'red )
301304 'pink
302305 'blue ))
303- ((eq nonheads 'warn )
304- (if (eq head-color 'red )
306+ ((eq foreign-keys 'warn )
307+ (if (memq head-color '( red amaranth) )
305308 'amaranth
306309 'teal ))
307310 (t
308311 (error " Unexpected %S %S " h body))))))
309312
313+ (defun hydra--body-foreign-keys (body )
314+ " Return what BODY does with a non-head binding."
315+ (or
316+ (plist-get (cddr body) :foreign-keys )
317+ (let ((color (plist-get (cddr body) :color )))
318+ (cl-case color
319+ ((amaranth teal) 'warn )
320+ (pink 'run )))))
321+
310322(defun hydra--body-color (body )
311323 " Return the color of BODY.
312324BODY is the second argument to `defhydra' "
313325 (let ((color (plist-get (cddr body) :color ))
314326 (exit (plist-get (cddr body) :exit ))
315- (nonheads (plist-get (cddr body) :nonheads )))
316- (cond ((eq nonheads 'warn )
327+ (foreign-keys (plist-get (cddr body) :foreign-keys )))
328+ (cond ((eq foreign-keys 'warn )
317329 (if exit 'teal 'amaranth ))
318- ((eq nonheads 'run ) 'pink )
330+ ((eq foreign-keys 'run ) 'pink )
319331 (exit 'blue )
320332 (color color)
321333 (t 'red ))))
@@ -585,27 +597,26 @@ NAME, BODY and HEADS are parameters to `defhydra'."
585597 (define-key keymap hydra-keyboard-quit #'hydra-keyboard-quit ))
586598 (when (memq body-color '(amaranth pink teal))
587599 (if (cl-some `(lambda (h)
588- (eq (hydra--head-color h body) 'blue ))
600+ (memq (hydra--head-color h body) '( blue teal) ))
589601 heads)
590602 (progn
591603 (define-key keymap [t]
592604 `(lambda ()
593605 (interactive )
594606 ,(cond
595- ((eq body-color 'amaranth )
607+ ((memq body-color '( amaranth teal) )
596608 '(message " An amaranth Hydra can only exit through a blue head" ))
597- ((eq body-color 'teal )
598- '(message " A teal Hydra can only exit through a blue head" ))
599609 (t
600610 '(hydra-pink-fallback)))
601611 (hydra-set-transient-map hydra-curr-map t )
602612 (when hydra-is-helpful
603613 (unless hydra-lv
604614 (sit-for 0.8 ))
605615 (,(intern (format " %S /hint" name)))))))
606- (error
607- " An %S Hydra must have at least one blue head in order to exit"
608- body-color)))))
616+ (unless (eq body-color 'teal )
617+ (error
618+ " An %S Hydra must have at least one blue head in order to exit"
619+ body-color))))))
609620
610621(defun hydra--head-name (h body-name )
611622 " Return the symbol for head H of body BODY-NAME."
0 commit comments