branch: master
commit f01f4a46f227961cd2a1571a45a174cfcfbfa81c
Author: Oleh Krehel <ohwoeo...@gmail.com>
Commit: Oleh Krehel <ohwoeo...@gmail.com>

    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
---
 hydra.el | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/hydra.el b/hydra.el
index a048df8..a1f7a8d 100644
--- a/hydra.el
+++ b/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))

Reply via email to