From 54004d21a276ba3d1b88f5f6182f7badb778f91e Mon Sep 17 00:00:00 2001 From: Oleh Krehel Date: Mon, 23 Feb 2015 16:45:45 +0100 Subject: [PATCH] hydra.el (hydra-verbose): New defcustom * hydra.el (hydra--head-color): Switch from `error' to `hydra--complain' in one case. (hydra--complain): New defun. Fixes #47. --- hydra.el | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/hydra.el b/hydra.el index e9fdc5c..afe59b7 100644 --- a/hydra.el +++ b/hydra.el @@ -117,6 +117,10 @@ It's possible to set this to nil.") "When non-nil, `lv-message' (not `message') will be used to display hints." :type 'boolean) +(defcustom hydra-verbose nil + "When non-nil, hydra will issue some non-essential style warnings." + :type 'boolean) + (defface hydra-face-red '((t (:foreground "#FF0000" :bold t))) "Red Hydra heads will persist indefinitely." @@ -284,9 +288,10 @@ Return DEFAULT if PROP is not in H." (let ((nonheads (plist-get (cddr body) :nonheads)) (body-exit (plist-get (cddr body) :exit))) (cond ((null (cadr h)) - (if head-color - (error "Extra properties for head with nil body: %S" h) - 'blue)) + (when head-color + (hydra--complain + "Doubly specified blue head - nil cmd is already blue: %S" h)) + 'blue) ((null head-color) (hydra--body-color body)) ((null nonheads) @@ -477,6 +482,11 @@ NAME, BODY, DOCSTRING, and HEADS are parameters of `defhydra'." (lv-message ,format-expr) (message ,format-expr)))) +(defun hydra--complain (format-string &rest args) + "Forward to (`message' FORMAT-STRING ARGS) unless `hydra-verbose' is nil." + (when hydra-verbose + (apply #'warn format-string args))) + (defun hydra--doc (body-key body-name heads) "Generate a part of Hydra docstring. BODY-KEY is the body key binding.