[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master ad771a4 03/17: Move defun-creating code into a defun
From: |
Oleh Krehel |
Subject: |
[elpa] master ad771a4 03/17: Move defun-creating code into a defun |
Date: |
Tue, 10 Feb 2015 07:13:23 +0000 |
branch: master
commit ad771a42945be630ca2faa246b597cd9b2acc550
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
Move defun-creating code into a defun
* hydra.el (hydra--doc): New function.
(defhydra): Simplify.
* hydra-test.el: Update tests.
---
hydra-test.el | 567 +++++++++++++++++++++++++++++----------------------------
hydra.el | 78 ++++----
2 files changed, 331 insertions(+), 314 deletions(-)
diff --git a/hydra-test.el b/hydra-test.el
index 7ae5fd0..57409fd 100644
--- a/hydra-test.el
+++ b/hydra-test.el
@@ -52,39 +52,40 @@ Call the head: `first-error'."
((debug error)
(message "%S" err)
(sit-for 0.8)
- nil))
- (when hydra-is-helpful (message #("error: [h]: first, [j]:
next, [k]: prev." 8 9 (face hydra-face-red)
- 20 21 (face hydra-face-red)
- 31 32 (face hydra-face-red))))
- (setq hydra-last
- (hydra-set-transient-map
- (setq hydra-curr-map '(keymap (107 .
hydra-error/previous-error)
- (106 . hydra-error/next-error)
- (104 . hydra-error/first-error)
- (kp-subtract .
hydra--negative-argument)
- (kp-9 . hydra--digit-argument)
- (kp-8 . hydra--digit-argument)
- (kp-7 . hydra--digit-argument)
- (kp-6 . hydra--digit-argument)
- (kp-5 . hydra--digit-argument)
- (kp-4 . hydra--digit-argument)
- (kp-3 . hydra--digit-argument)
- (kp-2 . hydra--digit-argument)
- (kp-1 . hydra--digit-argument)
- (kp-0 . hydra--digit-argument)
- (57 . hydra--digit-argument)
- (56 . hydra--digit-argument)
- (55 . hydra--digit-argument)
- (54 . hydra--digit-argument)
- (53 . hydra--digit-argument)
- (52 . hydra--digit-argument)
- (51 . hydra--digit-argument)
- (50 . hydra--digit-argument)
- (49 . hydra--digit-argument)
- (48 . hydra--digit-argument)
- (45 . hydra--negative-argument)
- (21 . hydra--universal-argument)))
- t))))
+ nil)))
+ (when hydra-is-helpful (message #("error: [h]: first, [j]: next,
[k]: prev." 8 9 (face hydra-face-red)
+ 20 21 (face hydra-face-red)
+ 31 32 (face hydra-face-red))))
+ (setq hydra-last
+ (hydra-set-transient-map
+ (setq hydra-curr-map
+ (quote (keymap (107 . hydra-error/previous-error)
+ (106 . hydra-error/next-error)
+ (104 . hydra-error/first-error)
+ (kp-subtract .
hydra--negative-argument)
+ (kp-9 . hydra--digit-argument)
+ (kp-8 . hydra--digit-argument)
+ (kp-7 . hydra--digit-argument)
+ (kp-6 . hydra--digit-argument)
+ (kp-5 . hydra--digit-argument)
+ (kp-4 . hydra--digit-argument)
+ (kp-3 . hydra--digit-argument)
+ (kp-2 . hydra--digit-argument)
+ (kp-1 . hydra--digit-argument)
+ (kp-0 . hydra--digit-argument)
+ (57 . hydra--digit-argument)
+ (56 . hydra--digit-argument)
+ (55 . hydra--digit-argument)
+ (54 . hydra--digit-argument)
+ (53 . hydra--digit-argument)
+ (52 . hydra--digit-argument)
+ (51 . hydra--digit-argument)
+ (50 . hydra--digit-argument)
+ (49 . hydra--digit-argument)
+ (48 . hydra--digit-argument)
+ (45 . hydra--negative-argument)
+ (21 . hydra--universal-argument))))
+ t)))
(defun hydra-error/next-error nil "Create a hydra with a \"M-g\" body
and the heads:
\"h\": `first-error',
@@ -101,39 +102,40 @@ Call the head: `next-error'."
((debug error)
(message "%S" err)
(sit-for 0.8)
- nil))
- (when hydra-is-helpful (message #("error: [h]: first, [j]:
next, [k]: prev." 8 9 (face hydra-face-red)
- 20 21 (face hydra-face-red)
- 31 32 (face hydra-face-red))))
- (setq hydra-last
- (hydra-set-transient-map
- (setq hydra-curr-map '(keymap (107 .
hydra-error/previous-error)
- (106 . hydra-error/next-error)
- (104 . hydra-error/first-error)
- (kp-subtract .
hydra--negative-argument)
- (kp-9 . hydra--digit-argument)
- (kp-8 . hydra--digit-argument)
- (kp-7 . hydra--digit-argument)
- (kp-6 . hydra--digit-argument)
- (kp-5 . hydra--digit-argument)
- (kp-4 . hydra--digit-argument)
- (kp-3 . hydra--digit-argument)
- (kp-2 . hydra--digit-argument)
- (kp-1 . hydra--digit-argument)
- (kp-0 . hydra--digit-argument)
- (57 . hydra--digit-argument)
- (56 . hydra--digit-argument)
- (55 . hydra--digit-argument)
- (54 . hydra--digit-argument)
- (53 . hydra--digit-argument)
- (52 . hydra--digit-argument)
- (51 . hydra--digit-argument)
- (50 . hydra--digit-argument)
- (49 . hydra--digit-argument)
- (48 . hydra--digit-argument)
- (45 . hydra--negative-argument)
- (21 . hydra--universal-argument)))
- t))))
+ nil)))
+ (when hydra-is-helpful (message #("error: [h]: first, [j]: next,
[k]: prev." 8 9 (face hydra-face-red)
+ 20 21 (face hydra-face-red)
+ 31 32 (face hydra-face-red))))
+ (setq hydra-last
+ (hydra-set-transient-map
+ (setq hydra-curr-map
+ (quote (keymap (107 . hydra-error/previous-error)
+ (106 . hydra-error/next-error)
+ (104 . hydra-error/first-error)
+ (kp-subtract .
hydra--negative-argument)
+ (kp-9 . hydra--digit-argument)
+ (kp-8 . hydra--digit-argument)
+ (kp-7 . hydra--digit-argument)
+ (kp-6 . hydra--digit-argument)
+ (kp-5 . hydra--digit-argument)
+ (kp-4 . hydra--digit-argument)
+ (kp-3 . hydra--digit-argument)
+ (kp-2 . hydra--digit-argument)
+ (kp-1 . hydra--digit-argument)
+ (kp-0 . hydra--digit-argument)
+ (57 . hydra--digit-argument)
+ (56 . hydra--digit-argument)
+ (55 . hydra--digit-argument)
+ (54 . hydra--digit-argument)
+ (53 . hydra--digit-argument)
+ (52 . hydra--digit-argument)
+ (51 . hydra--digit-argument)
+ (50 . hydra--digit-argument)
+ (49 . hydra--digit-argument)
+ (48 . hydra--digit-argument)
+ (45 . hydra--negative-argument)
+ (21 . hydra--universal-argument))))
+ t)))
(defun hydra-error/previous-error nil "Create a hydra with a \"M-g\"
body and the heads:
\"h\": `first-error',
@@ -150,39 +152,40 @@ Call the head: `previous-error'."
((debug error)
(message "%S" err)
(sit-for 0.8)
- nil))
- (when hydra-is-helpful (message #("error: [h]: first, [j]:
next, [k]: prev." 8 9 (face hydra-face-red)
- 20 21 (face hydra-face-red)
- 31 32 (face hydra-face-red))))
- (setq hydra-last
- (hydra-set-transient-map
- (setq hydra-curr-map '(keymap (107 .
hydra-error/previous-error)
- (106 . hydra-error/next-error)
- (104 . hydra-error/first-error)
- (kp-subtract .
hydra--negative-argument)
- (kp-9 . hydra--digit-argument)
- (kp-8 . hydra--digit-argument)
- (kp-7 . hydra--digit-argument)
- (kp-6 . hydra--digit-argument)
- (kp-5 . hydra--digit-argument)
- (kp-4 . hydra--digit-argument)
- (kp-3 . hydra--digit-argument)
- (kp-2 . hydra--digit-argument)
- (kp-1 . hydra--digit-argument)
- (kp-0 . hydra--digit-argument)
- (57 . hydra--digit-argument)
- (56 . hydra--digit-argument)
- (55 . hydra--digit-argument)
- (54 . hydra--digit-argument)
- (53 . hydra--digit-argument)
- (52 . hydra--digit-argument)
- (51 . hydra--digit-argument)
- (50 . hydra--digit-argument)
- (49 . hydra--digit-argument)
- (48 . hydra--digit-argument)
- (45 . hydra--negative-argument)
- (21 . hydra--universal-argument)))
- t))))
+ nil)))
+ (when hydra-is-helpful (message #("error: [h]: first, [j]: next,
[k]: prev." 8 9 (face hydra-face-red)
+ 20 21 (face hydra-face-red)
+ 31 32 (face hydra-face-red))))
+ (setq hydra-last
+ (hydra-set-transient-map
+ (setq hydra-curr-map
+ (quote (keymap (107 . hydra-error/previous-error)
+ (106 . hydra-error/next-error)
+ (104 . hydra-error/first-error)
+ (kp-subtract .
hydra--negative-argument)
+ (kp-9 . hydra--digit-argument)
+ (kp-8 . hydra--digit-argument)
+ (kp-7 . hydra--digit-argument)
+ (kp-6 . hydra--digit-argument)
+ (kp-5 . hydra--digit-argument)
+ (kp-4 . hydra--digit-argument)
+ (kp-3 . hydra--digit-argument)
+ (kp-2 . hydra--digit-argument)
+ (kp-1 . hydra--digit-argument)
+ (kp-0 . hydra--digit-argument)
+ (57 . hydra--digit-argument)
+ (56 . hydra--digit-argument)
+ (55 . hydra--digit-argument)
+ (54 . hydra--digit-argument)
+ (53 . hydra--digit-argument)
+ (52 . hydra--digit-argument)
+ (51 . hydra--digit-argument)
+ (50 . hydra--digit-argument)
+ (49 . hydra--digit-argument)
+ (48 . hydra--digit-argument)
+ (45 . hydra--negative-argument)
+ (21 . hydra--universal-argument))))
+ t)))
(unless (keymapp (lookup-key global-map (kbd "M-g")))
(define-key global-map (kbd "M-g")
nil))
@@ -205,32 +208,33 @@ The body can be accessed via `hydra-error/body'."
31 32 (face hydra-face-red))))
(setq hydra-last
(hydra-set-transient-map
- '(keymap (107 . hydra-error/previous-error)
- (106 . hydra-error/next-error)
- (104 . hydra-error/first-error)
- (kp-subtract . hydra--negative-argument)
- (kp-9 . hydra--digit-argument)
- (kp-8 . hydra--digit-argument)
- (kp-7 . hydra--digit-argument)
- (kp-6 . hydra--digit-argument)
- (kp-5 . hydra--digit-argument)
- (kp-4 . hydra--digit-argument)
- (kp-3 . hydra--digit-argument)
- (kp-2 . hydra--digit-argument)
- (kp-1 . hydra--digit-argument)
- (kp-0 . hydra--digit-argument)
- (57 . hydra--digit-argument)
- (56 . hydra--digit-argument)
- (55 . hydra--digit-argument)
- (54 . hydra--digit-argument)
- (53 . hydra--digit-argument)
- (52 . hydra--digit-argument)
- (51 . hydra--digit-argument)
- (50 . hydra--digit-argument)
- (49 . hydra--digit-argument)
- (48 . hydra--digit-argument)
- (45 . hydra--negative-argument)
- (21 . hydra--universal-argument))
+ (setq hydra-curr-map
+ (quote (keymap (107 . hydra-error/previous-error)
+ (106 . hydra-error/next-error)
+ (104 . hydra-error/first-error)
+ (kp-subtract .
hydra--negative-argument)
+ (kp-9 . hydra--digit-argument)
+ (kp-8 . hydra--digit-argument)
+ (kp-7 . hydra--digit-argument)
+ (kp-6 . hydra--digit-argument)
+ (kp-5 . hydra--digit-argument)
+ (kp-4 . hydra--digit-argument)
+ (kp-3 . hydra--digit-argument)
+ (kp-2 . hydra--digit-argument)
+ (kp-1 . hydra--digit-argument)
+ (kp-0 . hydra--digit-argument)
+ (57 . hydra--digit-argument)
+ (56 . hydra--digit-argument)
+ (55 . hydra--digit-argument)
+ (54 . hydra--digit-argument)
+ (53 . hydra--digit-argument)
+ (52 . hydra--digit-argument)
+ (51 . hydra--digit-argument)
+ (50 . hydra--digit-argument)
+ (49 . hydra--digit-argument)
+ (48 . hydra--digit-argument)
+ (45 . hydra--negative-argument)
+ (21 . hydra--universal-argument))))
t)))))))
(ert-deftest hydra-blue-toggle ()
@@ -310,49 +314,54 @@ The body can be accessed via `toggle/body'."
48 49 (face hydra-face-blue))))
(setq hydra-last
(hydra-set-transient-map
- '(keymap (113 . toggle/nil)
- (97 . toggle/abbrev-mode)
- (102 . toggle/auto-fill-mode)
- (116 . toggle/toggle-truncate-lines)
- (kp-subtract . hydra--negative-argument)
- (kp-9 . hydra--digit-argument)
- (kp-8 . hydra--digit-argument)
- (kp-7 . hydra--digit-argument)
- (kp-6 . hydra--digit-argument)
- (kp-5 . hydra--digit-argument)
- (kp-4 . hydra--digit-argument)
- (kp-3 . hydra--digit-argument)
- (kp-2 . hydra--digit-argument)
- (kp-1 . hydra--digit-argument)
- (kp-0 . hydra--digit-argument)
- (57 . hydra--digit-argument)
- (56 . hydra--digit-argument)
- (55 . hydra--digit-argument)
- (54 . hydra--digit-argument)
- (53 . hydra--digit-argument)
- (52 . hydra--digit-argument)
- (51 . hydra--digit-argument)
- (50 . hydra--digit-argument)
- (49 . hydra--digit-argument)
- (48 . hydra--digit-argument)
- (45 . hydra--negative-argument)
- (21 . hydra--universal-argument))
+ (setq hydra-curr-map
+ '(keymap (113 . toggle/nil)
+ (97 . toggle/abbrev-mode)
+ (102 . toggle/auto-fill-mode)
+ (116 . toggle/toggle-truncate-lines)
+ (kp-subtract . hydra--negative-argument)
+ (kp-9 . hydra--digit-argument)
+ (kp-8 . hydra--digit-argument)
+ (kp-7 . hydra--digit-argument)
+ (kp-6 . hydra--digit-argument)
+ (kp-5 . hydra--digit-argument)
+ (kp-4 . hydra--digit-argument)
+ (kp-3 . hydra--digit-argument)
+ (kp-2 . hydra--digit-argument)
+ (kp-1 . hydra--digit-argument)
+ (kp-0 . hydra--digit-argument)
+ (57 . hydra--digit-argument)
+ (56 . hydra--digit-argument)
+ (55 . hydra--digit-argument)
+ (54 . hydra--digit-argument)
+ (53 . hydra--digit-argument)
+ (52 . hydra--digit-argument)
+ (51 . hydra--digit-argument)
+ (50 . hydra--digit-argument)
+ (49 . hydra--digit-argument)
+ (48 . hydra--digit-argument)
+ (45 . hydra--negative-argument)
+ (21 . hydra--universal-argument)))
t)))))))
(ert-deftest hydra-amaranth-vi ()
- (should
- (equal
- (macroexpand
- '(defhydra hydra-vi
- (:color amaranth)
- "vi"
- ("l" forward-char)
- ("h" backward-char)
- ("j" next-line)
- ("k" previous-line)
- ("q" nil "quit")))
- '(progn
- (defun hydra-vi/forward-char nil "Create a hydra with no body and the
heads:
+ (unless (version< emacs-version "24.4")
+ (should
+ (equal
+ (macroexpand
+ '(defhydra hydra-vi
+ (:pre
+ (set-cursor-color "#e52b50")
+ :post
+ (set-cursor-color "#ffffff")
+ :color amaranth)
+ "vi"
+ ("l" forward-char)
+ ("h" backward-char)
+ ("j" next-line)
+ ("k" previous-line)
+ ("q" nil "quit")))
+ '(progn (defun hydra-vi/forward-char nil "Create a hydra with no body
and the heads:
\"l\": `forward-char',
\"h\": `backward-char',
@@ -363,14 +372,81 @@ The body can be accessed via `toggle/body'."
The body can be accessed via `hydra-vi/body'.
Call the head: `forward-char'."
- (interactive)
- (catch (quote hydra-disable)
- (hydra-disable)
- (condition-case err (prog1 t (call-interactively (function
forward-char)))
- ((debug error)
- (message "%S" err)
- (sit-for 0.8)
- nil))
+ (interactive)
+ (set-cursor-color "#e52b50")
+ (catch (quote hydra-disable)
+ (hydra-disable)
+ (condition-case err (prog1 t (call-interactively
(function forward-char)))
+ ((debug error)
+ (message "%S" err)
+ (sit-for 0.8)
+ nil)))
+ (when hydra-is-helpful (message #("vi: l, h, j, k, [q]:
quit." 4 5 (face hydra-face-amaranth)
+ 7 8 (face
hydra-face-amaranth)
+ 10 11 (face
hydra-face-amaranth)
+ 13 14 (face
hydra-face-amaranth)
+ 17 18 (face
hydra-face-blue))))
+ (setq hydra-last
+ (hydra-set-transient-map
+ (setq hydra-curr-map
+ (quote (keymap (t lambda nil (interactive)
+ (message "An amaranth
Hydra can only exit through a blue head")
+ (hydra-set-transient-map
hydra-curr-map t)
+ (when hydra-is-helpful
(sit-for 0.8)
+ (message #("vi: l,
h, j, k, [q]: quit." 4 5 (face hydra-face-amaranth)
+ 7 8 (face
hydra-face-amaranth)
+ 10 11
(face hydra-face-amaranth)
+ 13 14
(face hydra-face-amaranth)
+ 17 18
(face hydra-face-blue)))))
+ (113 . hydra-vi/nil)
+ (107 . hydra-vi/previous-line)
+ (106 . hydra-vi/next-line)
+ (104 . hydra-vi/backward-char)
+ (108 . hydra-vi/forward-char)
+ (kp-subtract .
hydra--negative-argument)
+ (kp-9 . hydra--digit-argument)
+ (kp-8 . hydra--digit-argument)
+ (kp-7 . hydra--digit-argument)
+ (kp-6 . hydra--digit-argument)
+ (kp-5 . hydra--digit-argument)
+ (kp-4 . hydra--digit-argument)
+ (kp-3 . hydra--digit-argument)
+ (kp-2 . hydra--digit-argument)
+ (kp-1 . hydra--digit-argument)
+ (kp-0 . hydra--digit-argument)
+ (57 . hydra--digit-argument)
+ (56 . hydra--digit-argument)
+ (55 . hydra--digit-argument)
+ (54 . hydra--digit-argument)
+ (53 . hydra--digit-argument)
+ (52 . hydra--digit-argument)
+ (51 . hydra--digit-argument)
+ (50 . hydra--digit-argument)
+ (49 . hydra--digit-argument)
+ (48 . hydra--digit-argument)
+ (45 .
hydra--negative-argument)
+ (21 .
hydra--universal-argument))))
+ t)))
+ (defun hydra-vi/backward-char nil "Create a hydra with no body and the
heads:
+
+\"l\": `forward-char',
+\"h\": `backward-char',
+\"j\": `next-line',
+\"k\": `previous-line',
+\"q\": `nil'
+
+The body can be accessed via `hydra-vi/body'.
+
+Call the head: `backward-char'."
+ (interactive)
+ (set-cursor-color "#e52b50")
+ (catch (quote hydra-disable)
+ (hydra-disable)
+ (condition-case err (prog1 t (call-interactively (function
backward-char)))
+ ((debug error)
+ (message "%S" err)
+ (sit-for 0.8)
+ nil)))
(when hydra-is-helpful (message #("vi: l, h, j, k, [q]: quit."
4 5 (face hydra-face-amaranth)
7 8 (face hydra-face-amaranth)
10 11 (face
hydra-face-amaranth)
@@ -416,8 +492,8 @@ Call the head: `forward-char'."
(48 . hydra--digit-argument)
(45 . hydra--negative-argument)
(21 . hydra--universal-argument))))
- t))))
- (defun hydra-vi/backward-char nil "Create a hydra with no body and the
heads:
+ t)))
+ (defun hydra-vi/next-line nil "Create a hydra with no body and the
heads:
\"l\": `forward-char',
\"h\": `backward-char',
@@ -427,16 +503,16 @@ Call the head: `forward-char'."
The body can be accessed via `hydra-vi/body'.
-Call the head: `backward-char'."
- (interactive)
- (catch
- (quote hydra-disable)
- (hydra-disable)
- (condition-case err (prog1 t (call-interactively (function
backward-char)))
- ((debug error)
- (message "%S" err)
- (sit-for 0.8)
- nil))
+Call the head: `next-line'."
+ (interactive)
+ (set-cursor-color "#e52b50")
+ (catch (quote hydra-disable)
+ (hydra-disable)
+ (condition-case err (prog1 t (call-interactively (function
next-line)))
+ ((debug error)
+ (message "%S" err)
+ (sit-for 0.8)
+ nil)))
(when hydra-is-helpful (message #("vi: l, h, j, k, [q]: quit."
4 5 (face hydra-face-amaranth)
7 8 (face hydra-face-amaranth)
10 11 (face
hydra-face-amaranth)
@@ -482,8 +558,8 @@ Call the head: `backward-char'."
(48 . hydra--digit-argument)
(45 . hydra--negative-argument)
(21 . hydra--universal-argument))))
- t))))
- (defun hydra-vi/next-line nil "Create a hydra with no body and the heads:
+ t)))
+ (defun hydra-vi/previous-line nil "Create a hydra with no body and the
heads:
\"l\": `forward-char',
\"h\": `backward-char',
@@ -493,16 +569,16 @@ Call the head: `backward-char'."
The body can be accessed via `hydra-vi/body'.
-Call the head: `next-line'."
- (interactive)
- (catch
- (quote hydra-disable)
- (hydra-disable)
- (condition-case err (prog1 t (call-interactively (function
next-line)))
- ((debug error)
- (message "%S" err)
- (sit-for 0.8)
- nil))
+Call the head: `previous-line'."
+ (interactive)
+ (set-cursor-color "#e52b50")
+ (catch (quote hydra-disable)
+ (hydra-disable)
+ (condition-case err (prog1 t (call-interactively (function
previous-line)))
+ ((debug error)
+ (message "%S" err)
+ (sit-for 0.8)
+ nil)))
(when hydra-is-helpful (message #("vi: l, h, j, k, [q]: quit."
4 5 (face hydra-face-amaranth)
7 8 (face hydra-face-amaranth)
10 11 (face
hydra-face-amaranth)
@@ -548,8 +624,8 @@ Call the head: `next-line'."
(48 . hydra--digit-argument)
(45 . hydra--negative-argument)
(21 . hydra--universal-argument))))
- t))))
- (defun hydra-vi/previous-line nil "Create a hydra with no body and the
heads:
+ t)))
+ (defun hydra-vi/nil nil "Create a hydra with no body and the heads:
\"l\": `forward-char',
\"h\": `backward-char',
@@ -559,15 +635,22 @@ Call the head: `next-line'."
The body can be accessed via `hydra-vi/body'.
-Call the head: `previous-line'."
- (interactive)
- (catch (quote hydra-disable)
+Call the head: `nil'."
+ (interactive)
+ (set-cursor-color "#e52b50")
(hydra-disable)
- (condition-case err (prog1 t (call-interactively (function
previous-line)))
- ((debug error)
- (message "%S" err)
- (sit-for 0.8)
- nil))
+ (set-cursor-color "#ffffff"))
+ (defun hydra-vi/body nil "Create a hydra with no body and the heads:
+
+\"l\": `forward-char',
+\"h\": `backward-char',
+\"j\": `next-line',
+\"k\": `previous-line',
+\"q\": `nil'
+
+The body can be accessed via `hydra-vi/body'."
+ (interactive)
+ (set-cursor-color "#e52b50")
(when hydra-is-helpful (message #("vi: l, h, j, k, [q]: quit."
4 5 (face hydra-face-amaranth)
7 8 (face hydra-face-amaranth)
10 11 (face
hydra-face-amaranth)
@@ -613,75 +696,7 @@ Call the head: `previous-line'."
(48 . hydra--digit-argument)
(45 . hydra--negative-argument)
(21 . hydra--universal-argument))))
- t))))
- (defun hydra-vi/nil nil "Create a hydra with no body and the heads:
-
-\"l\": `forward-char',
-\"h\": `backward-char',
-\"j\": `next-line',
-\"k\": `previous-line',
-\"q\": `nil'
-
-The body can be accessed via `hydra-vi/body'.
-
-Call the head: `nil'."
- (interactive)
- (hydra-disable))
- (defun hydra-vi/body nil "Create a hydra with no body and the heads:
-
-\"l\": `forward-char',
-\"h\": `backward-char',
-\"j\": `next-line',
-\"k\": `previous-line',
-\"q\": `nil'
-
-The body can be accessed via `hydra-vi/body'."
- (interactive)
- (when hydra-is-helpful (message #("vi: l, h, j, k, [q]: quit." 4
5 (face hydra-face-amaranth)
- 7 8 (face hydra-face-amaranth)
- 10 11 (face hydra-face-amaranth)
- 13 14 (face hydra-face-amaranth)
- 17 18 (face hydra-face-blue))))
- (setq hydra-last
- (hydra-set-transient-map
- (quote (keymap (t lambda nil (interactive)
- (message "An amaranth Hydra can only
exit through a blue head")
- (hydra-set-transient-map hydra-curr-map
t)
- (when hydra-is-helpful (sit-for 0.8)
- (message #("vi: l, h, j, k, [q]:
quit." 4 5 (face hydra-face-amaranth)
- 7 8 (face
hydra-face-amaranth)
- 10 11 (face
hydra-face-amaranth)
- 13 14 (face
hydra-face-amaranth)
- 17 18 (face
hydra-face-blue)))))
- (113 . hydra-vi/nil)
- (107 . hydra-vi/previous-line)
- (106 . hydra-vi/next-line)
- (104 . hydra-vi/backward-char)
- (108 . hydra-vi/forward-char)
- (kp-subtract . hydra--negative-argument)
- (kp-9 . hydra--digit-argument)
- (kp-8 . hydra--digit-argument)
- (kp-7 . hydra--digit-argument)
- (kp-6 . hydra--digit-argument)
- (kp-5 . hydra--digit-argument)
- (kp-4 . hydra--digit-argument)
- (kp-3 . hydra--digit-argument)
- (kp-2 . hydra--digit-argument)
- (kp-1 . hydra--digit-argument)
- (kp-0 . hydra--digit-argument)
- (57 . hydra--digit-argument)
- (56 . hydra--digit-argument)
- (55 . hydra--digit-argument)
- (54 . hydra--digit-argument)
- (53 . hydra--digit-argument)
- (52 . hydra--digit-argument)
- (51 . hydra--digit-argument)
- (50 . hydra--digit-argument)
- (49 . hydra--digit-argument)
- (48 . hydra--digit-argument)
- (45 . hydra--negative-argument)
- (21 . hydra--universal-argument)))
- t)))))))
+ t))))))))
(provide 'hydra-test)
diff --git a/hydra.el b/hydra.el
index b615c1e..b070e21 100644
--- a/hydra.el
+++ b/hydra.el
@@ -226,6 +226,39 @@ HEADS is a list of heads."
heads ",\n")
(format "The body can be accessed via `%S'." body-name)))
+(defun hydra--make-defun (name cmd color
+ doc hint keymap
+ body-color body-pre body-post)
+ "Make a defun wrapper, using NAME, CMD, COLOR, DOC, HINT, and KEYMAP.
+BODY-COLOR, BODY-PRE, and BODY-POST are used as well."
+ `(defun ,name ()
+ ,doc
+ (interactive)
+ ,@(when body-pre (list body-pre))
+ ,@(delq nil
+ (if (eq color 'blue)
+ `((hydra-disable)
+ ,(when cmd `(call-interactively #',cmd))
+ ,body-post)
+ `(,(when cmd
+ `(catch 'hydra-disable
+ (hydra-disable)
+ (condition-case err
+ (prog1 t
+ (call-interactively #',cmd))
+ ((debug error)
+ (message "%S" err)
+ (sit-for 0.8)
+ nil))))
+ (when hydra-is-helpful
+ (message ,hint))
+ (setq hydra-last
+ (hydra-set-transient-map
+ (setq hydra-curr-map ',keymap)
+ t
+ ,@(if (and (not (eq body-color 'amaranth)) body-post)
+ `((lambda () ,body-post))))))))))
+
;;* Macros
;;** hydra-create
;;;###autoload
@@ -329,32 +362,11 @@ in turn can be either red or blue."
`(progn
,@(cl-mapcar
(lambda (head name)
- `(defun ,name ()
- ,(format "%s\n\nCall the head: `%S'." doc (cadr head))
- (interactive)
- ,@(if body-pre (list body-pre))
- ,@(if (eq (hydra--color head body-color) 'blue)
- `((hydra-disable)
- ,@(unless (null (cadr head))
- `((call-interactively #',(cadr head))))
- ,@(if body-post (list body-post)))
- `((catch 'hydra-disable
- (hydra-disable)
- (condition-case err
- (prog1 t
- (call-interactively #',(cadr head)))
- ((debug error)
- (message "%S" err)
- (sit-for 0.8)
- nil))
- (when hydra-is-helpful
- (message ,hint))
- (setq hydra-last
- (hydra-set-transient-map
- (setq hydra-curr-map ',keymap)
- t
- ,@(if (and body-post (not (eq body-color
'amaranth)))
- `((lambda () ,body-post))))))))))
+ (hydra--make-defun
+ name (cadr head) (hydra--color head body-color)
+ (format "%s\n\nCall the head: `%S'." doc (cadr head))
+ hint keymap
+ body-color body-pre body-post))
heads names)
,@(unless (or (null body-key)
(null method)
@@ -373,18 +385,8 @@ in turn can be either red or blue."
(vconcat (kbd body-key) (kbd (car head)))
(list 'function name))))
heads names))
- (defun ,body-name ()
- ,doc
- (interactive)
- ,@(if body-pre (list body-pre))
- (when hydra-is-helpful
- (message ,hint))
- (setq hydra-last
- (hydra-set-transient-map
- ',keymap
- t
- ,@(if (and body-post (not (eq body-color 'amaranth)))
- `((lambda () ,body-post)))))))))
+ ,(hydra--make-defun body-name nil nil doc hint keymap
+ body-color body-pre body-post))))
(provide 'hydra)
- [elpa] master updated (61bddf2 -> 11b130e), Oleh Krehel, 2015/02/10
- [elpa] master b65db57 02/17: Update :post for amaranth Hydras, Oleh Krehel, 2015/02/10
- [elpa] master 9991985 01/17: hydra-test.el: update the test to not fail for older Emacs, Oleh Krehel, 2015/02/10
- [elpa] master 1660d71 05/17: Allow :pre and :post to be function symbols, Oleh Krehel, 2015/02/10
- [elpa] master 7ead8db 06/17: hydra.el (defhydra): Declare indent 2, Oleh Krehel, 2015/02/10
- [elpa] master 1b1d31d 07/17: Support local hydra heads, Oleh Krehel, 2015/02/10
- [elpa] master 9a8e2f1 04/17: hydra.el (hydra-keyboard-quit): New custom var, Oleh Krehel, 2015/02/10
- [elpa] master 9b31ead 08/17: Update semantics for local heads to `:bind nil', Oleh Krehel, 2015/02/10
- [elpa] master 969fa66 10/17: fix typo - single not singe, Oleh Krehel, 2015/02/10
- [elpa] master d41be74 11/17: `hydra/body' will pass the initial `current-prefix-arg' along, Oleh Krehel, 2015/02/10
- [elpa] master ad771a4 03/17: Move defun-creating code into a defun,
Oleh Krehel <=
- [elpa] master 763bb2a 13/17: Allow lambda :bind property for body and heads, Oleh Krehel, 2015/02/10
- [elpa] master 0712a43 12/17: README.md: update, Oleh Krehel, 2015/02/10
- [elpa] master d10c26e 14/17: Update comments and mark the old examples obsolete, Oleh Krehel, 2015/02/10
- [elpa] master 0c08964 16/17: README.md: update, Oleh Krehel, 2015/02/10
- [elpa] master 4ca646e 15/17: Allow a sexp as head's CMD paramater, Oleh Krehel, 2015/02/10
- [elpa] master bb01930 09/17: Fix "catch 'hydra-disable", Oleh Krehel, 2015/02/10
- [elpa] master 11b130e 17/17: Merge commit '0c08964462812942db51d177e6ea922b26019e65' from hydra, Oleh Krehel, 2015/02/10