@@ -330,24 +330,6 @@ one of the properties on the list."
330330Return DEFAULT if PROP is not in H."
331331 (hydra-plist-get-default (cl-cdddr h) prop default ))
332332
333- (defun hydra--head-color (h body )
334- " Return the color of a Hydra head H with BODY."
335- (let* ((foreign-keys (hydra--body-foreign-keys body))
336- (head-exit (hydra--head-property h :exit ))
337- (head-color
338- (if head-exit
339- (if (eq foreign-keys 'warn )
340- 'teal
341- 'blue )
342- (cl-case foreign-keys
343- (warn 'amaranth )
344- (run 'pink )
345- (t 'red )))))
346- (when (and (null (cadr h))
347- (not (eq head-color 'blue )))
348- (hydra--complain " nil cmd can only be blue" ))
349- head-color))
350-
351333(defun hydra--body-foreign-keys (body )
352334 " Return what BODY does with a non-head binding."
353335 (or
@@ -423,23 +405,36 @@ BODY, and HEADS are parameters to `defhydra'."
423405(defun hydra-fontify-head-default (head body )
424406 " Produce a pretty string from HEAD and BODY.
425407HEAD's binding is returned as a string with a colored face."
426- (propertize (car head) 'face
427- (cl-case (hydra--head-color head body)
428- (blue 'hydra-face-blue )
429- (red 'hydra-face-red )
430- (amaranth 'hydra-face-amaranth )
431- (pink 'hydra-face-pink )
432- (teal 'hydra-face-teal )
433- (t (error " Unknown color for %S " head)))))
408+ (let* ((foreign-keys (hydra--body-foreign-keys body))
409+ (head-exit (hydra--head-property head :exit ))
410+ (head-color
411+ (if head-exit
412+ (if (eq foreign-keys 'warn )
413+ 'teal
414+ 'blue )
415+ (cl-case foreign-keys
416+ (warn 'amaranth )
417+ (run 'pink )
418+ (t 'red )))))
419+ (when (and (null (cadr head))
420+ (not (eq head-color 'blue )))
421+ (hydra--complain " nil cmd can only be blue" ))
422+ (propertize (car head) 'face
423+ (cl-case head-color
424+ (blue 'hydra-face-blue )
425+ (red 'hydra-face-red )
426+ (amaranth 'hydra-face-amaranth )
427+ (pink 'hydra-face-pink )
428+ (teal 'hydra-face-teal )
429+ (t (error " Unknown color for %S " head))))))
434430
435431(defun hydra-fontify-head-greyscale (head body )
436432 " Produce a pretty string from HEAD and BODY.
437433HEAD's binding is returned as a string wrapped with [] or {}."
438- (let ((color (hydra--head-color head body)))
439- (format
440- (if (eq color 'blue )
441- " [%s]"
442- " {%s}" ) (car head))))
434+ (format
435+ (if (hydra--head-property head :exit )
436+ " [%s]"
437+ " {%s}" ) (car head)))
443438
444439(defun hydra-fontify-head (head body )
445440 " Produce a pretty string from HEAD and BODY."
@@ -533,8 +528,6 @@ BODY-AFTER-EXIT is added to the end of the wrapper."
533528 (cmd (when (car head)
534529 (hydra--make-callable
535530 (cadr head))))
536- (color (when (car head)
537- (hydra--head-color head body)))
538531 (doc (if (car head)
539532 (format " %s \n\n Call the head: `%S' ." doc (cadr head))
540533 doc))
@@ -546,7 +539,7 @@ BODY-AFTER-EXIT is added to the end of the wrapper."
546539 (interactive )
547540 (hydra-default-pre)
548541 ,@(when body-pre (list body-pre))
549- ,@(if (memq color '(blue teal) )
542+ ,@(if (hydra--head-property head :exit )
550543 `((hydra-keyboard-quit)
551544 ,(if body-after-exit
552545 `(unwind-protect
@@ -586,23 +579,23 @@ BODY-AFTER-EXIT is added to the end of the wrapper."
586579 (if (symbolp (cadr h))
587580 (cadr h)
588581 (concat " lambda-" (car h))))))
589- (when (and (memq ( hydra--head-color h body) '(blue teal) )
582+ (when (and (hydra--head-property h :exit )
590583 (not (memq (cadr h) '(body nil ))))
591584 (setq str (concat str " -and-exit" )))
592585 (intern str)))
593586
594587(defun hydra--delete-duplicates (heads )
595588 " Return HEADS without entries that have the same CMD part.
596589In duplicate HEADS, :cmd-name is modified to whatever they duplicate."
597- (let ((ali '(((hydra-repeat . red ) . hydra-repeat)))
590+ (let ((ali '(((hydra-repeat . nil ) . hydra-repeat)))
598591 res entry)
599592 (dolist (h heads)
600593 (if (setq entry (assoc (cons (cadr h)
601- (hydra--head-color h '( nil nil ) ))
594+ (hydra--head-property h :exit ))
602595 ali))
603596 (setf (cl-cdddr h) (plist-put (cl-cdddr h) :cmd-name (cdr entry)))
604597 (push (cons (cons (cadr h)
605- (hydra--head-color h '( nil nil ) ))
598+ (hydra--head-property h :exit ))
606599 (plist-get (cl-cdddr h) :cmd-name ))
607600 ali)
608601 (push h res)))
@@ -837,7 +830,7 @@ result of `defhydra'."
837830 (when (memq body-foreign-keys '(run warn))
838831 (unless (cl-some
839832 (lambda (h )
840- (memq ( hydra--head-color h body) '(blue teal) ))
833+ (hydra--head-property h :exit ))
841834 heads)
842835 (error
843836 " An %S Hydra must have at least one blue head in order to exit"
0 commit comments