[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master b982fe5 14/27: Allow to add one head that disables the Hyd
From: |
Oleh Krehel |
Subject: |
[elpa] master b982fe5 14/27: Allow to add one head that disables the Hydra |
Date: |
Sat, 24 Jan 2015 20:36:33 +0000 |
branch: master
commit b982fe5811e896b19835570efb571af2e1040ea6
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
Allow to add one head that disables the Hydra
* hydra.el (hydra-last): Store the lambda to disable the Hydra.
(hydra-create): Update.
Sometimes, I have nothing particualr on my mind to do, but I want to
stop the Hydra. I could just type "C-g", but it's possible to have
something more convenient. For instance:
(hydra-create "C-z"
'(("l" forward-char)
("h" backward-char)
("j" next-line)
("k" previous-line)
("z")))
---
hydra.el | 53 +++++++++++++++++++++++++++--------------------------
1 files changed, 27 insertions(+), 26 deletions(-)
diff --git a/hydra.el b/hydra.el
index fa21e65..f1428ab 100644
--- a/hydra.el
+++ b/hydra.el
@@ -63,6 +63,9 @@
:type 'boolean
:group 'hydra)
+(defvar hydra-last nil
+ "The result of the last `set-transient-map' call.")
+
;;;###autoload
(defmacro hydra-create (body heads &optional method)
"Create a hydra with a BODY prefix and HEADS with METHOD.
@@ -89,45 +92,43 @@ When `(keymapp METHOD)`, it becomes:
heads))
(method (cond ((null method)
'global-set-key)
-
((keymapp (eval method))
- `(lambda (key command) (define-key ,method key
command)))
-
+ `(lambda (key command)
+ (define-key ,method key command)))
(t
method)))
(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)))
+ (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 ", ")
- ".")))
+ "."))
+ (doc (format
+ "Create a hydra with a \"%s\" body and the heads:\n\n%s."
+ body
+ (mapconcat
+ (lambda (x)
+ (format "\"%s\": `%S'" (car x) (cadr x)))
+ heads ",\n"))))
`(progn
(when (eq ',method 'global-set-key)
(global-set-key ,(kbd body) nil))
,@(cl-mapcar
(lambda (head name)
`(defun ,name ()
- ,(format
- "Create a hydra with a \"%s\" body and the heads:
-
-%s.
-
-Call the head: `%S'."
- body
- (mapconcat
- (lambda (x)
- (format "\"%s\": `%S'" (car x) (cadr x)))
- heads ",\n")
- (cadr head))
+ ,(format "%s\n\nCall the head: `%S'." doc (cadr head))
(interactive)
- (call-interactively #',(cadr head))
- (when hydra-is-helpful
- (message ,hint))
- (set-transient-map ',keymap t)))
+ (if (null ',(cadr head))
+ (funcall hydra-last)
+ (call-interactively #',(cadr head))
+ (when hydra-is-helpful
+ (message ,hint))
+ (setq hydra-last (set-transient-map ',keymap t)))))
heads names)
,@(cl-mapcar
(lambda (head name)
- [elpa] master 2a367fa 03/27: README.md: update doc, (continued)
- [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, 2015/01/24
- [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 <=
- [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
- [elpa] master 64e5b91 22/27: Avoid evaling METHOD., Oleh Krehel, 2015/01/24
- [elpa] master 440c41c 24/27: Bump version, Oleh Krehel, 2015/01/24
- [elpa] master cfac8bd 21/27: Prepare for the first version in GNU ELPA, Oleh Krehel, 2015/01/24