branch: master
commit d41be74d54aee29a0e9b55ead32960b75d70c438
Author: Oleh Krehel <[email protected]>
Commit: Oleh Krehel <[email protected]>
`hydra/body' will pass the initial `current-prefix-arg' along
* hydra.el (hydra--make-defun): Take an additional arg to paste as the
last statement.
(defhydra): Set `hydra-foo/body' last statement to
`(setq prefix-arg current-prefix-arg)'.
* hydra-test.el: Update tests.
Example:
(global-set-key
(kbd "C-z")
(defhydra hydra-vi ()
"vi"
("l" forward-char)
("q" nil "quit")))
Now, "C-u C-z l" will result in (forward-char 4). All the other "l" will
normally call (forward-char 1), unless an additional prefix is given.
The previous behavior allowed only for "C-z C-u l" to get
(forward-char 4).
Fixes #21.
---
hydra-test.el | 9 ++++++---
hydra.el | 8 +++++---
2 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/hydra-test.el b/hydra-test.el
index 4376ab3..f2311ab 100644
--- a/hydra-test.el
+++ b/hydra-test.el
@@ -237,7 +237,8 @@ The body can be accessed via `hydra-error/body'."
(48 . hydra--digit-argument)
(45 . hydra--negative-argument)
(21 . hydra--universal-argument))))
- t))))))))
+ t))
+ (setq prefix-arg current-prefix-arg)))))))
(ert-deftest hydra-blue-toggle ()
(should
@@ -350,7 +351,8 @@ The body can be accessed via `toggle/body'."
(48 . hydra--digit-argument)
(45 . hydra--negative-argument)
(21 . hydra--universal-argument))))
- t))))))))
+ t))
+ (setq prefix-arg current-prefix-arg)))))))
(ert-deftest hydra-amaranth-vi ()
(unless (version< emacs-version "24.4")
@@ -557,7 +559,8 @@ The body can be accessed via `hydra-vi/body'."
(48 . hydra--digit-argument)
(45 . hydra--negative-argument)
(21 .
hydra--universal-argument))))
- t)))))))))
+ t))
+ (setq prefix-arg current-prefix-arg))))))))
(provide 'hydra-test)
diff --git a/hydra.el b/hydra.el
index 86abcfc..e4699ee 100644
--- a/hydra.el
+++ b/hydra.el
@@ -240,7 +240,7 @@ HEADS is a list of heads."
(defun hydra--make-defun (name cmd color
doc hint keymap
- body-color body-pre body-post)
+ body-color body-pre body-post &optional other-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 ()
@@ -268,7 +268,8 @@ BODY-COLOR, BODY-PRE, and BODY-POST are used as well."
(setq hydra-curr-map ',keymap)
t
,@(if (and (not (eq body-color 'amaranth))
body-post)
- `((lambda () ,body-post)))))))))))
+ `((lambda () ,body-post)))))
+ ,other-post))))))
;;* Macros
;;** hydra-create
@@ -417,7 +418,8 @@ in turn can be either red or blue."
(error "Invalid :bind property %S" head))))))
heads names))
,(hydra--make-defun body-name nil nil doc hint keymap
- body-color body-pre body-post))))
+ body-color body-pre body-post
+ '(setq prefix-arg current-prefix-arg)))))
(provide 'hydra)