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

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

[elpa] master 5318fc3 08/27: Update `hydra-create' format


From: Oleh Krehel
Subject: [elpa] master 5318fc3 08/27: Update `hydra-create' format
Date: Sat, 24 Jan 2015 20:36:31 +0000

branch: master
commit 5318fc353a51394cbd87506d1b645ac7fab00dd6
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>

    Update `hydra-create' format
    
    * hydra.el (hydra-create): Expects a lists of lists for HEADS, instead
      of list of cons cells. The optional thrid element of each list is the
      hint.
    
    * hydra-examples.el: Update the examples.
    
    * README.md: Update.
    
    Re #2
---
 README.md         |   39 +++++++++++++++++++++++++++++----------
 hydra-examples.el |   12 ++++++------
 hydra.el          |   27 ++++++++++++++++++---------
 3 files changed, 53 insertions(+), 25 deletions(-)

diff --git a/README.md b/README.md
index 928983f..8a2ac8a 100644
--- a/README.md
+++ b/README.md
@@ -20,8 +20,8 @@ Here's how I use the examples bundled with Hydra:
 You can expand the examples in-place, it still looks elegant:
 
     (hydra-create "<f2>"
-      '(("g" . text-scale-increase)
-        ("l" . text-scale-decrease)))
+      '(("g" text-scale-increase)
+        ("l" text-scale-decrease)))
 
 See the [introductory blog 
post](http://oremacs.com/2015/01/20/introducing-hydra/) for more information.
 
@@ -34,10 +34,10 @@ Here's an example:
 
 ```cl
 (hydra-create "z"
-  '(("l" . forward-char)
-    ("h" . backward-char)
-    ("j" . next-line)
-    ("k" . previous-line))
+  '(("l" forward-char)
+    ("h" backward-char)
+    ("j" next-line)
+    ("k" previous-line))
   (lambda (key command)
     (define-key lispy-mode-map key command)))
 ```
@@ -47,11 +47,30 @@ the lambda will be generated for you:
 
 ```cl
 (hydra-create "z"
-  '(("l" . forward-char)
-    ("h" . backward-char)
-    ("j" . next-line)
-    ("k" . previous-line))
+  '(("l" forward-char)
+    ("h" backward-char)
+    ("j" next-line)
+    ("k" previous-line))
     lispy-mode-map)
 ```
 
+## Can Hydras can be helpful?
 
+They can, if
+
+```cl
+(setq hydra-is-helpful t)
+```
+
+In that case, you'll get a hint in the echo area consisting of current Hydra's 
heads.
+You can even add comments to the heads like this:
+
+```
+(defvar hydra-example-text-scale
+  '(("g" text-scale-increase "zoom in")
+    ("l" text-scale-decrease "zoom out"))
+  "A two-headed hydra for text scale manipulation.")
+```
+
+With this, you'll see `hydra: [g]: zoom in, [l]: zoom out.` in your
+echo area, once the zoom Hydra becomes active.
diff --git a/hydra-examples.el b/hydra-examples.el
index 99cb451..bb01b36 100644
--- a/hydra-examples.el
+++ b/hydra-examples.el
@@ -27,8 +27,8 @@
 (require 'hydra)
 
 (defvar hydra-example-text-scale
-  '(("g" . text-scale-increase)
-    ("l" . text-scale-decrease))
+  '(("g" text-scale-increase "zoom in")
+    ("l" text-scale-decrease "zoom out"))
   "A two-headed hydra for text scale manipulation.")
 
 (require 'windmove)
@@ -62,10 +62,10 @@
     (enlarge-window 1)))
 
 (defvar hydra-example-move-window-splitter
-  '(("h" . hydra-move-splitter-left)
-    ("j" . hydra-move-splitter-down)
-    ("k" . hydra-move-splitter-up)
-    ("l" . hydra-move-splitter-right)))
+  '(("h" hydra-move-splitter-left)
+    ("j" hydra-move-splitter-down)
+    ("k" hydra-move-splitter-up)
+    ("l" hydra-move-splitter-right)))
 
 (provide 'hydra-examples)
 
diff --git a/hydra.el b/hydra.el
index 37c2cba..2bb4538 100644
--- a/hydra.el
+++ b/hydra.el
@@ -4,7 +4,7 @@
 
 ;; Author: Oleh Krehel <address@hidden>
 ;; URL: https://github.com/abo-abo/hydra
-;; Version: 0.1.0
+;; Version: 0.2.0
 ;; Package-Requires: ((cl-lib "0.5"))
 ;; Keywords: bindings
 
@@ -44,8 +44,8 @@
 ;; You can expand the examples in-place, it still looks elegant:
 ;;
 ;;     (hydra-create "<f2>"
-;;       '(("g" . text-scale-increase)
-;;         ("l" . text-scale-decrease)))
+;;       '(("g" text-scale-increase)
+;;         ("l" text-scale-decrease)))
 
 ;;; Code:
 (require 'cl-lib)
@@ -65,7 +65,7 @@
   "Create a hydra with a BODY prefix and HEADS with METHOD.
 This will result in `global-set-key' statements with the keys
 being the concatenation of BODY and each head in HEADS.  HEADS is
-an alist of (KEY . FUNCTION).
+an list of (KEY FUNCTION &optional HINT).
 
 After one of the HEADS is called via BODY+KEY, it and the other
 HEADS can be called with only KEY (no need for BODY).  This state
@@ -82,7 +82,7 @@ When `(keymapp METHOD)`, it becomes:
          (names (mapcar
                  (lambda (x)
                    (define-key keymap (car x)
-                     (intern (format "hydra-%s-%S" body (cdr x)))))
+                     (intern (format "hydra-%s-%S" body (cadr x)))))
                  heads))
          (method (cond ((null method)
                         'global-set-key)
@@ -92,7 +92,16 @@ When `(keymapp METHOD)`, it becomes:
 
                        (t
                         method)))
-         (hint (concat "hydra: " (mapconcat #'car heads " "))))
+         (hint (concat "hydra: "
+                       (mapconcat
+                        (lambda (h) (if (caddr h)
+                                   (format "[%s]: %s"
+                                           (propertize (car h)
+                                                       'face 
'font-lock-keyword-face)
+                                           (caddr h))
+                                 (propertize (car h) 'face 
'font-lock-keyword-face)))
+                        heads ", ")
+                       ".")))
     `(progn
        (,method ,(kbd body) nil)
        ,@(cl-mapcar
@@ -107,11 +116,11 @@ Call the head: `%S'."
                  body
                  (mapconcat
                   (lambda (x)
-                    (format "\"%s\":    `%S'" (car x) (cdr x)))
+                    (format "\"%s\":    `%S'" (car x) (cadr x)))
                   heads ",\n")
-                 (cdr head))
+                 (cadr head))
                (interactive)
-               (call-interactively #',(cdr head))
+               (call-interactively #',(cadr head))
                (when hydra-is-helpful
                  (message ,hint))
                (set-transient-map ',keymap t)))



reply via email to

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