emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master 9b31ead 08/17: Update semantics for local heads to `:bind


From: Oleh Krehel
Subject: [elpa] master 9b31ead 08/17: Update semantics for local heads to `:bind nil'
Date: Tue, 10 Feb 2015 07:13:25 +0000

branch: master
commit 9b31ead60dab68f913358858b86b784716bbbeb9
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>

    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))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]