]> code.delx.au - gnu-emacs-elpa/commitdiff
Allow binding heads to "%"
authorOleh Krehel <ohwoeowho@gmail.com>
Sat, 18 Jul 2015 16:20:23 +0000 (18:20 +0200)
committerOleh Krehel <ohwoeowho@gmail.com>
Sat, 18 Jul 2015 16:20:23 +0000 (18:20 +0200)
* hydra.el (hydra--format): Update regex. Make sure that there's a
  proper amount of escapes for %, since:

- it first gets evaled via `hydra-test/hint'
- it gets passed to `lv-message'

So to get 1 in the end, the initial amount can be 4.

* hydra-test.el (hydra-format-7): Add tests.

hydra-test.el
hydra.el

index a7704351d734494baf17074d5d90bdd66e724a92..d20e353c31dfab73e0893bce1fb7e6ed37f8941b 100644 (file)
@@ -1113,6 +1113,30 @@ _f_ auto-fill-mode:    %`auto-fill-function
                     hydra-face-red)))
             ""))))
 
+(ert-deftest hydra-format-7 ()
+  (should
+   (equal
+    (hydra--format nil nil "test"
+                   '(("%" forward-char "" :exit nil)
+                     ("b" backward-char "" :exit nil)))
+    '(format
+      #("test: %%%%, b."
+        6 7 (face hydra-face-red)
+        7 8 (face hydra-face-red)
+        8 9 (face hydra-face-red)
+        9 10 (face hydra-face-red)
+        12 13 (face hydra-face-red)))))
+  (should
+   (equal
+    (hydra--format nil nil "\n_%_ forward\n"
+                   '(("%" forward-char nil :exit nil)))
+    '(concat
+      (format
+       "%s forward\n"
+       #("%%"
+         0 2 (face hydra-face-red)))
+      ""))))
+
 (ert-deftest hydra-format-with-sexp-1 ()
   (should (equal
            (let ((hydra-fontify-head-function
index 5a823ff38ebbd6fcac3aa4c41029594e2166e18a..80b1a230ee2947d8ca86fce06bdc7e94735556a1 100644 (file)
--- a/hydra.el
+++ b/hydra.el
@@ -513,7 +513,7 @@ 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:] ~.,;:/|?<>={}*+#]+?\\)_\\)"
+                  "\\(?:%\\( ?-?[0-9]*s?\\)\\(`[a-z-A-Z/0-9]+\\|(\\)\\)\\|\\(?:_\\( ?-?[0-9]*?\\)\\(\\[\\|]\\|[-[:alnum:] ~.,;:/|?<>={}*+#%]+?\\)_\\)"
                   docstring start))
       (cond ((eq ?_ (aref (match-string 0 docstring) 0))
              (let* ((key (match-string 4 docstring))
@@ -551,7 +551,8 @@ The expressions can be auto-expanded according to NAME."
     (if (eq ?\n (aref docstring 0))
         `(concat (format ,(substring docstring 1) ,@(nreverse varlist))
                  ,rest)
-      `(format ,(concat docstring ": " rest ".")))))
+      `(format ,(concat docstring ": " (replace-regexp-in-string
+                                        "\\(%\\)" "\\1\\1" rest) ".")))))
 
 (defun hydra--complain (format-string &rest args)
   "Forward to (`message' FORMAT-STRING ARGS) unless `hydra-verbose' is nil."