[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)))
- [elpa] master updated (af29d76 -> 5aa7896), Oleh Krehel, 2015/03/22
- [elpa] master 9623625 02/28: hydra-ox.el (hydra-ox): Update parameter list, Oleh Krehel, 2015/03/22
- [elpa] master b840227 03/28: Update `golden-ratio-mode' work-around, Oleh Krehel, 2015/03/22
- [elpa] master 77c8e40 01/28: Add option to specify :hint in body,
Oleh Krehel <=
- [elpa] master 88c7dc4 04/28: Fix wrong type argument in hydra-timeout, Oleh Krehel, 2015/03/22
- [elpa] master 5c2f420 06/28: hydra-examples.el: Fixup, Oleh Krehel, 2015/03/22
- [elpa] master 58075f5 08/28: hydra-examples.el (hydra-buffer-menu): Fix example, Oleh Krehel, 2015/03/22
- [elpa] master bca2441 07/28: Makefile: Simplify, Oleh Krehel, 2015/03/22
- [elpa] master a867927 05/28: "C-g" (`hydra-keyboard-quit' ) should run :post, Oleh Krehel, 2015/03/22
- [elpa] master 7f4c835 11/28: README.md: finish up the rules, Oleh Krehel, 2015/03/22
- [elpa] master 556db52 14/28: Wiki link to the "Home" page instead., Oleh Krehel, 2015/03/22
- [elpa] master c9432e8 12/28: README.md: describe docstring, Oleh Krehel, 2015/03/22
- [elpa] master 3c4b3fd 16/28: lv.el: Update truncation rules, Oleh Krehel, 2015/03/22
- [elpa] master 3f11348 13/28: README.md: Add toc, Oleh Krehel, 2015/03/22