[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)))
- [elpa] master 916a130 05/27: Depend on cl-lib v0.5 for `cl-mapcar', (continued)
- [elpa] master 916a130 05/27: Depend on cl-lib v0.5 for `cl-mapcar', Oleh Krehel, 2015/01/24
- [elpa] master a179f31 04/27: Unbind hydra's body unconditionally to avoid error, Oleh Krehel, 2015/01/24
- [elpa] master abef4bf 02/27: Split away the examples, Oleh Krehel, 2015/01/24
- [elpa] master 2a367fa 03/27: README.md: update doc, Oleh Krehel, 2015/01/24
- [elpa] master f55c1ff 07/27: Add `hydra-is-helpful' custom var, Oleh Krehel, 2015/01/24
- [elpa] master 9b86656 01/27: Initial import, Oleh Krehel, 2015/01/24
- [elpa] master 6966e14 11/27: Fix the bugged `global-set-key' version, Oleh Krehel, 2015/01/24
- [elpa] master 11323ec 06/27: Allow to use minor-mode-maps and more, Oleh Krehel, 2015/01/24
- [elpa] master dbd77f0 09/27: Don't unbind hydra's body, unless using global-set-key, Oleh Krehel, 2015/01/24
- [elpa] master 998b533 10/27: Make sure `windmove-wrap-around' is nil during tests, Oleh Krehel, 2015/01/24
- [elpa] master 5318fc3 08/27: Update `hydra-create' format,
Oleh Krehel <=
- [elpa] master e156bf2 12/27: Require cl at compile time, Oleh Krehel, 2015/01/24
- [elpa] master 69bb4a4 13/27: Fix `kbd' interpretting "<tab>" char-by-char, Oleh Krehel, 2015/01/24
- [elpa] master b982fe5 14/27: Allow to add one head that disables the Hydra, Oleh Krehel, 2015/01/24
- [elpa] master c3ce0a9 15/27: `hydra-create' will also define `hydra-...-body', Oleh Krehel, 2015/01/24
- [elpa] master 8884698 17/27: Don't undefine BODY's map binding when it's a prefix, Oleh Krehel, 2015/01/24
- [elpa] master dfe1273 19/27: Simplify and improve the generated defuns, Oleh Krehel, 2015/01/24
- [elpa] master 301b500 16/27: Don't undefine BODY's global binding when it's a prefix, Oleh Krehel, 2015/01/24
- [elpa] master 42538fa 18/27: Add a `next-error'/`previous-error'/`first-error' example, Oleh Krehel, 2015/01/24
- [elpa] master dc0246e 20/27: hydra-examples.el (hydra-example-goto-error): add doc, Oleh Krehel, 2015/01/24
- [elpa] master ddd96d1 23/27: hydra-examples.el: add a `windmove' Hydra, Oleh Krehel, 2015/01/24