branch: master commit 1660d71516cb80fe1aa654495ab30594463e8a2a Author: Oleh Krehel <ohwoeo...@gmail.com> Commit: Oleh Krehel <ohwoeo...@gmail.com>
Allow :pre and :post to be function symbols * hydra.el (defhydra): :pre and :post are eihter sexps or function symbols. Re #16. Example: (defun hydra-vi/pre () (set-cursor-color "#e52b50")) (defun hydra-vi/post () (set-cursor-color "#ffffff")) (global-set-key (kbd "C-z") (defhydra hydra-vi (:pre hydra-vi/pre :post hydra-vi/post :color amaranth) "vi" ("l" forward-char) ("h" backward-char) ("j" next-line) ("k" previous-line) ("m" set-mark-command "mark") ("a" move-beginning-of-line "beg") ("e" move-end-of-line "end") ("d" delete-region "del" :color blue) ("y" kill-ring-save "yank" :color blue) ("q" nil "quit"))) --- hydra.el | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/hydra.el b/hydra.el index 89f21d8..db0a89b 100644 --- a/hydra.el +++ b/hydra.el @@ -352,6 +352,10 @@ in turn can be either red or blue." (when (and (or body-pre body-post) (version< emacs-version "24.4")) (error "At least Emacs 24.4 is needed for :pre and :post")) + (when (and body-pre (symbolp body-pre)) + (setq body-pre `(funcall #',body-pre))) + (when (and body-post (symbolp body-post)) + (setq body-post `(funcall #',body-post))) (when (eq body-color 'amaranth) (if (cl-some `(lambda (h) (eq (hydra--color h ',body-color) 'blue))