[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master e8bbb70 2/7: Add :pre and :post clauses to Hydra body
From: |
Oleh Krehel |
Subject: |
[elpa] master e8bbb70 2/7: Add :pre and :post clauses to Hydra body |
Date: |
Sun, 08 Feb 2015 15:06:31 +0000 |
branch: master
commit e8bbb70545b6d5316d1797ebb5e76c5a30dff266
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
Add :pre and :post clauses to Hydra body
* hydra.el (defhydra): the PLIST part of BODY argument now recognizes
:pre and :post keys. These should be single Elisp statements,
wrappable in a lambda. When you need more than one statement, use a
`progn'.
:pre will be called by `hydra-foo/body', as well as by all heads.
:post will be called by the blue heads, as well as on Hydra termination
by a command that isn't a head.
Fixes #16.
An Example:
(global-set-key
(kbd "C-z")
(defhydra hydra-vi
(:pre
(set-cursor-color "#40e0d0")
:post
(set-cursor-color "#ffffff"))
"vi"
("l" forward-char)
("h" backward-char)
("j" next-line)
("k" previous-line)
("q" nil "quit")))
---
hydra.el | 26 ++++++++++++++++++++------
1 files changed, 20 insertions(+), 6 deletions(-)
diff --git a/hydra.el b/hydra.el
index 043b2a3..23b563d 100644
--- a/hydra.el
+++ b/hydra.el
@@ -5,7 +5,7 @@
;; Author: Oleh Krehel <address@hidden>
;; Maintainer: Oleh Krehel <address@hidden>
;; URL: https://github.com/abo-abo/hydra
-;; Version: 0.6.1
+;; Version: 0.7.0
;; Keywords: bindings
;; Package-Requires: ((cl-lib "0.5"))
@@ -116,7 +116,7 @@
(define-key map [kp-9] 'hydra--digit-argument)
(define-key map [kp-subtract] 'hydra--negative-argument)
map)
- "Keymap that all Hydras inherit. See `universal-argument-map'.")
+ "Keymap that all Hydras inherit. See `universal-argument-map'.")
(defvar hydra-curr-map
(make-sparse-keymap)
@@ -130,7 +130,7 @@
(if (eq arg '-)
(list -4)
'(4))))
- (hydra-set-transient-map hydra-curr-map))
+ (hydra-set-transient-map hydra-curr-map t))
(defun hydra--digit-argument (arg)
"Forward to (`digit-argument' ARG)."
@@ -298,21 +298,28 @@ in turn can be either red or blue."
'red
(or (plist-get (cddr body) :color)
'red)))
+ (body-pre (plist-get (cddr body) :pre))
+ (body-post (plist-get (cddr body) :post))
(method (if (hydra--callablep body)
body
(car body)))
(hint (hydra--hint docstring heads body-color))
(doc (hydra--doc body-key body-name heads)))
+ (when (and (or body-pre body-post)
+ (version< emacs-version "24.4"))
+ (error "At least Emacs 24.4 is needed for :pre and :post"))
`(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)))))
+ `((call-interactively #',(cadr head))))
+ ,@(if body-post (list body-post)))
`((catch 'hydra-disable
(hydra-disable)
(condition-case err
@@ -325,7 +332,10 @@ in turn can be either red or blue."
(when hydra-is-helpful
(message ,hint))
(setq hydra-last
- (hydra-set-transient-map (setq hydra-curr-map
',keymap) t)))))))
+ (hydra-set-transient-map
+ (setq hydra-curr-map ',keymap)
+ t
+ ,@(if body-post `((lambda ()
,body-post))))))))))
heads names)
,@(unless (or (null body-key)
(null method)
@@ -347,10 +357,14 @@ in turn can be either red or blue."
(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))))))
+ (hydra-set-transient-map
+ ',keymap
+ t
+ ,@(if body-post `((lambda () ,body-post)))))))))
(provide 'hydra)
- [elpa] master updated (8b585bc -> 2fb700c), Oleh Krehel, 2015/02/08
- [elpa] master 37b6177 3/7: README.md: update for 0.7.0, Oleh Krehel, 2015/02/08
- [elpa] master e8bbb70 2/7: Add :pre and :post clauses to Hydra body,
Oleh Krehel <=
- [elpa] master 843bc70 4/7: Add amaranth (immortal) Hydras, Oleh Krehel, 2015/02/08
- [elpa] master e21d1d8 1/7: Update the call order and allow called functions to exit, Oleh Krehel, 2015/02/08
- [elpa] master 68bcaa8 6/7: Bump version, Oleh Krehel, 2015/02/08
- [elpa] master 07e4aaa 5/7: hydra-test.el: add test, Oleh Krehel, 2015/02/08
- [elpa] master 2fb700c 7/7: Merge commit '68bcaa8d8df5518217a3833fd1bb400c8225fe02' from hydra, Oleh Krehel, 2015/02/08