branch: master
commit 9b31ead60dab68f913358858b86b784716bbbeb9
Author: Oleh Krehel <[email protected]>
Commit: Oleh Krehel <[email protected]>
Update semantics for local heads to `:bind nil'
* hydra.el (hydra--head-property): Accept an optional DEFAULT arg.
(defhydra): A head will not be bound in the body map when it has `:bind
nil' in its plist.
Example:
(defhydra hydra-next-error (c++-mode-map "C-x")
"next-error"
("`" next-error "next")
("j" next-error "next" :bind nil)
("k" previous-error "previous" :bind nil))
Here, only "C-x `" will be bound in `c++-mode-map', "C-x j" and "C-x k"
will not be bound. However, e.g. "C-x `jjk" will be possible.
---
hydra.el | 33 +++++++++++++++++++++------------
1 files changed, 21 insertions(+), 12 deletions(-)
diff --git a/hydra.el b/hydra.el
index ccc6279..b8eef4a 100644
--- a/hydra.el
+++ b/hydra.el
@@ -163,12 +163,15 @@ It's possible to set this to nil.")
(and (consp x)
(memq (car x) '(function quote)))))
-(defun hydra--head-property (h prop)
- "Return the value of property PROP for Hydra head H."
+(defun hydra--head-property (h prop &optional default)
+ "Return the value of property PROP for Hydra head H.
+Return DEFAULT if PROP is not in H."
(let ((plist (if (stringp (cl-caddr h))
(cl-cdddr h)
(cddr h))))
- (plist-get plist prop)))
+ (if (memq prop h)
+ (plist-get plist prop)
+ default)))
(defun hydra--color (h body-color)
"Return the color of a Hydra head H with BODY-COLOR."
@@ -398,15 +401,21 @@ in turn can be either red or blue."
(cl-mapcar
(lambda (head name)
(unless (or (null body-key)
- (null method)
- (hydra--head-property head :local))
- (list
- (if (hydra--callablep method)
- 'funcall
- 'define-key)
- method
- (vconcat (kbd body-key) (kbd (car head)))
- (list 'function name))))
+ (null method))
+ (let ((bind (hydra--head-property head :bind 'default)))
+ (cond ((null bind) nil)
+
+ ((eq bind 'default)
+ (list
+ (if (hydra--callablep method)
+ 'funcall
+ 'define-key)
+ method
+ (vconcat (kbd body-key) (kbd (car head)))
+ (list 'function name)))
+
+ (t
+ (error "Invalid :bind property %S" head))))))
heads names))
,(hydra--make-defun body-name nil nil doc hint keymap
body-color body-pre body-post))))