emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master 71d70f6 46/72: Add :body-pre switch


From: Oleh Krehel
Subject: [elpa] master 71d70f6 46/72: Add :body-pre switch
Date: Fri, 06 Mar 2015 13:04:17 +0000

branch: master
commit 71d70f6aacc4d11b4bd84e95c000d41b42ce34bb
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>

    Add :body-pre switch
    
    It will be run as the first thing in the prefix/body function.
    
    re #41
    
    Example:
    
        (defvar hydra-vi/init-pos nil)
        (defhydra hydra-vi (:body-pre (setq hydra-vi/init-pos (point))
                            :color pink)
          "vi"
          ;; arrows
          ("h" backward-char)
          ("j" next-line)
          ("k" previous-line)
          ("l" forward-char)
          ;; exit points
          ("q" (goto-char hydra-vi/init-pos) "ins" :exit t)
          ("C-n" (forward-line 1) nil :exit t)
          ("C-p" (forward-line -1) nil :exit t))
---
 hydra.el |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/hydra.el b/hydra.el
index a7114ed..7658c76 100644
--- a/hydra.el
+++ b/hydra.el
@@ -610,12 +610,15 @@ result of `defhydra'."
                      (cadr body)))
          (body-color (hydra--body-color body))
          (body-pre (plist-get (cddr body) :pre))
+         (body-body-pre (plist-get (cddr body) :body-pre))
          (body-post (plist-get (cddr body) :post))
          (method (or (plist-get body :bind)
                      (car body)))
          (doc (hydra--doc body-key body-name heads)))
     (when (and body-pre (symbolp body-pre))
       (setq body-pre `(funcall #',body-pre)))
+    (when (and body-body-pre (symbolp body-body-pre))
+      (setq body-body-pre `(funcall #',body-body-pre)))
     (when (and body-post (symbolp body-post))
       (setq body-post `(funcall #',body-post)))
     (hydra--handle-nonhead keymap name body heads)
@@ -665,7 +668,7 @@ result of `defhydra'."
        (defun ,hint-name ()
          ,(hydra--message name body docstring heads))
        ,(hydra--make-defun body-name nil nil doc hint-name keymap
-                           body-color body-pre body-post
+                           body-color (or body-body-pre body-pre) body-post
                            '(setq prefix-arg current-prefix-arg)))))
 
 (defmacro defhydradio (name body &rest heads)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]