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

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

[elpa] master 77c8e40 01/28: Add option to specify :hint in body


From: Oleh Krehel
Subject: [elpa] master 77c8e40 01/28: Add option to specify :hint in body
Date: Sun, 22 Mar 2015 16:34:37 +0000

branch: master
commit 77c8e40002ef299e80a923276f202a5688f5e3af
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>

    Add option to specify :hint in body
    
    * hydra.el (hydra-plist-get-default): New defun, extended `plist-get'.
    (hydra--head-property): Use `hydra-plist-get-default'.
    (defhydra): The heads will inherit their hint from body :hint parameter.
    They can override it, of course.
    
    The most use you can get out of this parameter is to specify :hint nil
    for hydras with a format-style docstring.
    
    Example:
    
    (defhydra hydra-org-template (:color blue :hint nil)
      "
    _c_enter  _q_uote    _L_aTeX:
    _l_atex   _e_xample  _i_ndex:
    _a_scii   _v_erse    _I_NCLUDE:
    _s_rc     ^ ^        _H_TML:
    _h_tml    ^ ^        _A_SCII:
    "
      ("s" (hot-expand "<s"))
      ("e" (hot-expand "<e"))
      ("q" (hot-expand "<q"))
      ("v" (hot-expand "<v"))
      ("c" (hot-expand "<c"))
      ("l" (hot-expand "<l"))
      ("h" (hot-expand "<h"))
      ("a" (hot-expand "<a"))
      ("L" (hot-expand "<L"))
      ("i" (hot-expand "<i"))
      ("I" (hot-expand "<I"))
      ("H" (hot-expand "<H"))
      ("A" (hot-expand "<A"))
      ("<" self-insert-command "ins")
      ("o" nil "quit"))
    
    Some setup:
    
    (defun hot-expand (str)
      "Expand org template."
      (insert str)
      (org-try-structure-completion))
    (define-key org-mode-map "<"
      (lambda () (interactive)
         (if (looking-back "^")
             (hydra-org-template/body)
           (self-insert-command 1))))
---
 hydra.el |   25 +++++++++++++++++++------
 1 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/hydra.el b/hydra.el
index dcdf03b..544e835 100644
--- a/hydra.el
+++ b/hydra.el
@@ -252,13 +252,21 @@ should be a single statement.  Wrap it in an interactive 
lambda."
        (interactive)
        ,x)))
 
+(defun hydra-plist-get-default (plist prop default)
+  "Extract a value from a property list.
+PLIST is a property list, which is a list of the form
+\(PROP1 VALUE1 PROP2 VALUE2...).
+
+Return the value corresponding to PROP, or DEFAULT if PROP is not
+one of the properties on the list."
+  (if (memq prop plist)
+      (plist-get plist prop)
+    default))
+
 (defun hydra--head-property (h prop &optional default)
   "Return for Hydra head H the value of property PROP.
 Return DEFAULT if PROP is not in H."
-  (let ((plist (cl-cdddr h)))
-    (if (memq prop h)
-        (plist-get plist prop)
-      default)))
+  (hydra-plist-get-default (cl-cdddr h) prop default))
 
 (defun hydra--aggregate-color (head-color body-color)
   "Return the resulting head color for HEAD-COLOR and BODY-COLOR."
@@ -839,12 +847,17 @@ result of `defhydra'."
       (cond ((< len 2)
              (error "Each head should have at least two items: %S" h))
             ((= len 2)
-             (setcdr (cdr h) `("" :cmd-name ,cmd-name)))
+             (setcdr (cdr h)
+                     (list
+                      (hydra-plist-get-default (cddr body) :hint "")
+                      :cmd-name cmd-name)))
             (t
              (let ((hint (cl-caddr h)))
                (unless (or (null hint)
                            (stringp hint))
-                 (setcdr (cdr h) (cons "" (cddr h))))
+                 (setcdr (cdr h) (cons
+                                  (hydra-plist-get-default (cddr body) :hint 
"")
+                                  (cddr h))))
                (setcdr (cddr h) `(:cmd-name ,cmd-name ,@(cl-cdddr h))))))))
   (let* ((keymap (copy-keymap hydra-base-map))
          (body-name (intern (format "%S/body" name)))



reply via email to

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