[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 0f733d8 37/72: Add an option to fontify heads in a custom
From: |
Oleh Krehel |
Subject: |
[elpa] master 0f733d8 37/72: Add an option to fontify heads in a custom way |
Date: |
Fri, 06 Mar 2015 13:04:13 +0000 |
branch: master
commit 0f733d8efcce7e82126282bcdfc92c4c7d25b273
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
Add an option to fontify heads in a custom way
* hydra.el (hydra--hint): Forward to `hydra-fontify-head'.
(hydra-fontify-head-function): New defvar.
(hydra-fontify-head-default): New defun that represents the classic
fontification behavior.
(hydra-fontify-head): Fontification dispatch - use
`hydra-fontify-head-default'
unless `hydra-fontify-head-function' is set.
(hydra--format): Forward to `hydra-fontify-head'.
Example:
(setq hydra-fontify-head-function
(lambda (head body)
(let ((color (hydra--head-color head body)))
(format
(if (eq color 'blue)
"[%s]"
"{%s}") (car head)))))
Call `defhydra' here, then reset:
(setq hydra-fontify-head-function nil)
Call another `defhydra' here.
---
hydra.el | 18 +++++++++++++++---
1 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/hydra.el b/hydra.el
index 578d879..7f90315 100644
--- a/hydra.el
+++ b/hydra.el
@@ -310,8 +310,7 @@ NAME, BODY, DOCSTRING and HEADS are parameters to
`defhydra'."
(let (alist)
(dolist (h heads)
(let ((val (assoc (cadr h) alist))
- (pstr (propertize (car h) 'face
- (hydra--face h body))))
+ (pstr (hydra-fontify-head h body)))
(unless (and (> (length h) 2)
(null (cl-caddr h)))
(if val
@@ -332,6 +331,19 @@ NAME, BODY, DOCSTRING and HEADS are parameters to
`defhydra'."
(nreverse (mapcar #'cdr alist))
", ")))
+(defvar hydra-fontify-head-function nil
+ "Possible replacement for `hydra-fontify-head-default'.")
+
+(defun hydra-fontify-head-default (head body)
+ "Produce a pretty string from HEAD and BODY.
+HEAD's binding is returned as a string with a colored face."
+ (propertize (car head) 'face (hydra--face head body)))
+
+(defun hydra-fontify-head (head body)
+ "Produce a pretty string from HEAD and BODY."
+ (funcall (or hydra-fontify-head-function 'hydra-fontify-head-default)
+ head body))
+
(defun hydra--format (name body docstring heads)
"Generate a `format' statement from STR.
\"%`...\" expressions are extracted into \"%S\".
@@ -352,7 +364,7 @@ The expressions can be auto-expanded according to NAME."
(head (assoc key heads)))
(if head
(progn
- (push (propertize key 'face (hydra--face head body)) varlist)
+ (push (hydra-fontify-head head body) varlist)
(setq docstring (replace-match "% 3s" nil nil docstring)))
(error "Unrecognized key: _%s_" key)))
(push (hydra--unalias-var (match-string 2 docstring) prefix) varlist)
- [elpa] master 2c01db0 42/72: hydra.el (hydra--handle-nonhead): Update signature, (continued)
- [elpa] master 2c01db0 42/72: hydra.el (hydra--handle-nonhead): Update signature, Oleh Krehel, 2015/03/06
- [elpa] master a71b76e 35/72: Intercept quit signals, Oleh Krehel, 2015/03/06
- [elpa] master ae70e9a 41/72: Fix pink and teal Hydras running :post, Oleh Krehel, 2015/03/06
- [elpa] master 71d70f6 46/72: Add :body-pre switch, Oleh Krehel, 2015/03/06
- [elpa] master cb28124 44/72: Allow sexps in Ruby-style docstrings, Oleh Krehel, 2015/03/06
- [elpa] master ace99b3 51/72: hydra.el (hydra--make-defun): Update signature, Oleh Krehel, 2015/03/06
- [elpa] master efcffc0 45/72: hydra-examples.el: Add example 9, Oleh Krehel, 2015/03/06
- [elpa] master ef1f61d 40/72: hydra.el (hydra--handle-nonhead): Fix bug, Oleh Krehel, 2015/03/06
- [elpa] master 2eddb83 43/72: hydra-test.el (hydra-format): New test, Oleh Krehel, 2015/03/06
- [elpa] master 5242aad 48/72: Fix :exit t / :exit nil inheritance issue, Oleh Krehel, 2015/03/06
- [elpa] master 0f733d8 37/72: Add an option to fontify heads in a custom way,
Oleh Krehel <=
- [elpa] master c413b5f 54/72: Allow for a custom key format spec in docstrings, Oleh Krehel, 2015/03/06
- [elpa] master 54004d2 52/72: hydra.el (hydra-verbose): New defcustom, Oleh Krehel, 2015/03/06
- [elpa] master 0d9c95e 47/72: Update README.md, Oleh Krehel, 2015/03/06
- [elpa] master 3c06695 56/72: Amend the key regex in docstring to include <>, Oleh Krehel, 2015/03/06
- [elpa] master e567bd6 59/72: lv.el (lv-window): set-window-parameter 'no-other-window, Oleh Krehel, 2015/03/06
- [elpa] master eb1e0fc 58/72: Don't bind nil heads in outside keymaps, Oleh Krehel, 2015/03/06
- [elpa] master 41ec124 50/72: Avoid generating multiple defuns with same name, Oleh Krehel, 2015/03/06
- [elpa] master db0415e 49/72: hydra.el (hydra-keyboard-quit): Add, Oleh Krehel, 2015/03/06
- [elpa] master 55682e7 57/72: Improve handling of heads with duplicate cmd, Oleh Krehel, 2015/03/06
- [elpa] master 7de26d0 64/72: Add `hydra-repeat': hydra-specific `repeat', Oleh Krehel, 2015/03/06