Skip to content

Commit

Permalink
Allow for a custom key format spec in docstrings
Browse files Browse the repository at this point in the history
* hydra.el (hydra-key-format-spec): New defcustom.
(hydra--format): Use `hydra-key-format-spec'. Allow for 0-9 and / in key
bindings.

Here's an example of how to use a flexible format spec for each key:

(let (hydra-key-format-spec)
  (defhydra hydra-zoom (global-map "<f2>")
    "
zoom: _g_reater _ -5l_esser re_ 7c_enter zer_0_"
    ("g" text-scale-increase nil)
    ("l" text-scale-decrease nil)
    ("c" recenter-top-bottom nil)
    ("0" (text-scale-set 0) nil :exit t)))

Fixes #50.
  • Loading branch information
abo-abo committed Feb 23, 2015
1 parent 989ed95 commit c413b5f
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions hydra.el
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ It's possible to set this to nil.")
"When non-nil, hydra will issue some non-essential style warnings."
:type 'boolean)

(defcustom hydra-key-format-spec "% 3s"
"Default `format'-style specifier for _a_ syntax in docstrings.
When nil, you can specify your own at each location like this: _ 5a_.")

(defface hydra-face-red
'((t (:foreground "#FF0000" :bold t)))
"Red Hydra heads will persist indefinitely."
Expand Down Expand Up @@ -448,15 +452,20 @@ The expressions can be auto-expanded according to NAME."
offset)
(while (setq start
(string-match
"\\(?:%\\( ?-?[0-9]*\\)\\(`[a-z-A-Z/0-9]+\\|(\\)\\)\\|\\(?:_\\([a-z-~A-Z]+\\)_\\)"
"\\(?:%\\( ?-?[0-9]*\\)\\(`[a-z-A-Z/0-9]+\\|(\\)\\)\\|\\(?:_\\( ?-?[0-9]*\\)\\([a-z-~A-Z0-9/]+\\)_\\)"
docstring start))
(cond ((eq ?_ (aref (match-string 0 docstring) 0))
(let* ((key (match-string 3 docstring))
(let* ((key (match-string 4 docstring))
(head (assoc key heads)))
(if head
(progn
(push (hydra-fontify-head head body) varlist)
(setq docstring (replace-match "% 3s" nil nil docstring)))
(setq docstring
(replace-match
(or
hydra-key-format-spec
(concat "%" (match-string 3 docstring) "s"))
nil nil docstring)))
(error "Unrecognized key: _%s_" key))))

((eq ?` (aref (match-string 2 docstring) 0))
Expand Down

0 comments on commit c413b5f

Please sign in to comment.