hydra.el (hydra-key-regex): Extract from hydra--format

* hydra.el (hydra-width-spec-regex): Extract from hydra--format.

Now the user can configure the key regex more precisely.

Fixes #187
master
Oleh Krehel 10 years ago
parent a85a617306
commit f01f4a46f2
  1. 12
      hydra.el

@ -584,6 +584,12 @@ HEAD's binding is returned as a string wrapped with [] or {}."
(defvar hydra-docstring-keys-translate-alist
'(("" . "<up>")))
(defconst hydra-width-spec-regex " ?-?[0-9]*s?"
"Regex for the width spec in keys and %` quoted sexps.")
(defvar hydra-key-regex "\\[\\|]\\|[-[:alnum:] ~.,;:/|?<>={}*+#%@!&^↑'`()\"]+?"
"Regex for the key quoted in the docstring.")
(defun hydra--format (_name body docstring heads)
"Generate a `format' statement from STR.
\"%`...\" expressions are extracted into \"%S\".
@ -597,7 +603,11 @@ The expressions can be auto-expanded according to NAME."
offset)
(while (setq start
(string-match
"\\(?:%\\( ?-?[0-9]*s?\\)\\(`[a-z-A-Z/0-9]+\\|(\\)\\)\\|\\(?:[_?]\\( ?-?[0-9]*?\\)\\(\\[\\|]\\|[-[:alnum:] ~.,;:/|?<>={}*+#%@!&^↑]+?\\)[_?]\\)"
(format
"\\(?:%%\\(%s\\)\\(`[a-z-A-Z/0-9]+\\|(\\)\\)\\|\\(?:[_?]\\(%s\\)\\(%s\\)[_?]\\)"
hydra-width-spec-regex
hydra-width-spec-regex
hydra-key-regex)
docstring start))
(cond ((eq ?? (aref (match-string 0 docstring) 0))
(let* ((key (match-string 4 docstring))

Loading…
Cancel
Save