1 ;;; hydra-test.el --- Tests for Hydra
3 ;; Copyright (C) 2015 Free Software Foundation, Inc.
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software: you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
28 (setq text-quoting-style 'grave)
29 (message "Emacs version: %s" emacs-version)
31 (ert-deftest hydra-red-error ()
35 '(defhydra hydra-error (global-map "M-g")
37 ("h" first-error "first")
38 ("j" next-error "next")
39 ("k" previous-error "prev")
40 ("SPC" hydra-repeat "rep" :bind nil)))
43 (defvar hydra-error/keymap nil
44 "Keymap for hydra-error.")
48 (107 . hydra-error/previous-error)
49 (106 . hydra-error/next-error)
50 (104 . hydra-error/first-error)
51 (kp-subtract . hydra--negative-argument)
52 (kp-9 . hydra--digit-argument)
53 (kp-8 . hydra--digit-argument)
54 (kp-7 . hydra--digit-argument)
55 (kp-6 . hydra--digit-argument)
56 (kp-5 . hydra--digit-argument)
57 (kp-4 . hydra--digit-argument)
58 (kp-3 . hydra--digit-argument)
59 (kp-2 . hydra--digit-argument)
60 (kp-1 . hydra--digit-argument)
61 (kp-0 . hydra--digit-argument)
62 (57 . hydra--digit-argument)
63 (56 . hydra--digit-argument)
64 (55 . hydra--digit-argument)
65 (54 . hydra--digit-argument)
66 (53 . hydra--digit-argument)
67 (52 . hydra--digit-argument)
68 (51 . hydra--digit-argument)
69 (50 . hydra--digit-argument)
70 (49 . hydra--digit-argument)
71 (48 . hydra--digit-argument)
72 (45 . hydra--negative-argument)
73 (21 . hydra--universal-argument))))
75 (defvar hydra-error/heads nil
76 "Heads for hydra-error.")
96 (defvar hydra-error/hint nil
97 "Dynamic hint for hydra-error.")
100 #("error: [h]: first, [j]: next, [k]: prev, [SPC]: rep."
101 8 9 (face hydra-face-red)
102 20 21 (face hydra-face-red)
103 31 32 (face hydra-face-red)
104 42 45 (face hydra-face-red)))))
105 (defun hydra-error/first-error nil
106 "Create a hydra with a \"M-g\" body and the heads:
108 \"h\": `first-error',
110 \"k\": `previous-error',
111 \"SPC\": `hydra-repeat'
113 The body can be accessed via `hydra-error/body'.
115 Call the head: `first-error'."
118 (let ((hydra--ignore t))
119 (hydra-keyboard-quit)
120 (setq hydra-curr-body-fn
121 (quote hydra-error/body)))
127 (function first-error)))
130 (unless hydra-lv (sit-for 0.8))))
131 (when hydra-is-helpful
134 (eval hydra-error/hint))
136 (eval hydra-error/hint))))
137 (hydra-set-transient-map
140 (hydra-keyboard-quit)
143 (defun hydra-error/next-error nil
144 "Create a hydra with a \"M-g\" body and the heads:
146 \"h\": `first-error',
148 \"k\": `previous-error',
149 \"SPC\": `hydra-repeat'
151 The body can be accessed via `hydra-error/body'.
153 Call the head: `next-error'."
156 (let ((hydra--ignore t))
157 (hydra-keyboard-quit)
158 (setq hydra-curr-body-fn
159 (quote hydra-error/body)))
165 (function next-error)))
168 (unless hydra-lv (sit-for 0.8))))
169 (when hydra-is-helpful
172 (eval hydra-error/hint))
174 (eval hydra-error/hint))))
175 (hydra-set-transient-map
178 (hydra-keyboard-quit)
181 (defun hydra-error/previous-error nil
182 "Create a hydra with a \"M-g\" body and the heads:
184 \"h\": `first-error',
186 \"k\": `previous-error',
187 \"SPC\": `hydra-repeat'
189 The body can be accessed via `hydra-error/body'.
191 Call the head: `previous-error'."
194 (let ((hydra--ignore t))
195 (hydra-keyboard-quit)
196 (setq hydra-curr-body-fn
197 (quote hydra-error/body)))
201 (quote previous-error))
203 (function previous-error)))
206 (unless hydra-lv (sit-for 0.8))))
207 (when hydra-is-helpful
210 (eval hydra-error/hint))
212 (eval hydra-error/hint))))
213 (hydra-set-transient-map
216 (hydra-keyboard-quit)
223 (define-key global-map (kbd "M-g")
225 (define-key global-map [134217831 104]
226 (quote hydra-error/first-error))
227 (define-key global-map [134217831 106]
228 (quote hydra-error/next-error))
229 (define-key global-map [134217831 107]
231 hydra-error/previous-error))
232 (defun hydra-error/body nil
233 "Create a hydra with a \"M-g\" body and the heads:
235 \"h\": `first-error',
237 \"k\": `previous-error',
238 \"SPC\": `hydra-repeat'
240 The body can be accessed via `hydra-error/body'."
243 (let ((hydra--ignore nil))
244 (hydra-keyboard-quit)
245 (setq hydra-curr-body-fn
246 (quote hydra-error/body)))
247 (when hydra-is-helpful
250 (eval hydra-error/hint))
252 (eval hydra-error/hint))))
253 (hydra-set-transient-map
256 (hydra-keyboard-quit)
260 current-prefix-arg))))))
262 (ert-deftest hydra-blue-toggle ()
266 '(defhydra hydra-toggle (:color blue)
268 ("t" toggle-truncate-lines "truncate")
269 ("f" auto-fill-mode "fill")
270 ("a" abbrev-mode "abbrev")
274 (defvar hydra-toggle/keymap nil
275 "Keymap for hydra-toggle.")
278 (113 . hydra-toggle/nil)
279 (97 . hydra-toggle/abbrev-mode-and-exit)
280 (102 . hydra-toggle/auto-fill-mode-and-exit)
281 (116 . hydra-toggle/toggle-truncate-lines-and-exit)
282 (kp-subtract . hydra--negative-argument)
283 (kp-9 . hydra--digit-argument)
284 (kp-8 . hydra--digit-argument)
285 (kp-7 . hydra--digit-argument)
286 (kp-6 . hydra--digit-argument)
287 (kp-5 . hydra--digit-argument)
288 (kp-4 . hydra--digit-argument)
289 (kp-3 . hydra--digit-argument)
290 (kp-2 . hydra--digit-argument)
291 (kp-1 . hydra--digit-argument)
292 (kp-0 . hydra--digit-argument)
293 (57 . hydra--digit-argument)
294 (56 . hydra--digit-argument)
295 (55 . hydra--digit-argument)
296 (54 . hydra--digit-argument)
297 (53 . hydra--digit-argument)
298 (52 . hydra--digit-argument)
299 (51 . hydra--digit-argument)
300 (50 . hydra--digit-argument)
301 (49 . hydra--digit-argument)
302 (48 . hydra--digit-argument)
303 (45 . hydra--negative-argument)
304 (21 . hydra--universal-argument))))
306 (defvar hydra-toggle/heads nil
307 "Heads for hydra-toggle.")
310 toggle-truncate-lines
321 ("q" nil "cancel" :exit t))))
323 (defvar hydra-toggle/hint nil
324 "Dynamic hint for hydra-toggle.")
327 #("toggle: [t]: truncate, [f]: fill, [a]: abbrev, [q]: cancel."
328 9 10 (face hydra-face-blue)
329 24 25 (face hydra-face-blue)
330 35 36 (face hydra-face-blue)
331 48 49 (face hydra-face-blue)))))
332 (defun hydra-toggle/toggle-truncate-lines-and-exit nil
333 "Create a hydra with no body and the heads:
335 \"t\": `toggle-truncate-lines',
336 \"f\": `auto-fill-mode',
337 \"a\": `abbrev-mode',
340 The body can be accessed via `hydra-toggle/body'.
342 Call the head: `toggle-truncate-lines'."
345 (hydra-keyboard-quit)
346 (setq hydra-curr-body-fn
347 (quote hydra-toggle/body))
350 (quote toggle-truncate-lines))
353 toggle-truncate-lines))))
354 (defun hydra-toggle/auto-fill-mode-and-exit nil
355 "Create a hydra with no body and the heads:
357 \"t\": `toggle-truncate-lines',
358 \"f\": `auto-fill-mode',
359 \"a\": `abbrev-mode',
362 The body can be accessed via `hydra-toggle/body'.
364 Call the head: `auto-fill-mode'."
367 (hydra-keyboard-quit)
368 (setq hydra-curr-body-fn
369 (quote hydra-toggle/body))
372 (quote auto-fill-mode))
374 (function auto-fill-mode))))
375 (defun hydra-toggle/abbrev-mode-and-exit nil
376 "Create a hydra with no body and the heads:
378 \"t\": `toggle-truncate-lines',
379 \"f\": `auto-fill-mode',
380 \"a\": `abbrev-mode',
383 The body can be accessed via `hydra-toggle/body'.
385 Call the head: `abbrev-mode'."
388 (hydra-keyboard-quit)
389 (setq hydra-curr-body-fn
390 (quote hydra-toggle/body))
395 (function abbrev-mode))))
396 (defun hydra-toggle/nil nil
397 "Create a hydra with no body and the heads:
399 \"t\": `toggle-truncate-lines',
400 \"f\": `auto-fill-mode',
401 \"a\": `abbrev-mode',
404 The body can be accessed via `hydra-toggle/body'.
406 Call the head: `nil'."
409 (hydra-keyboard-quit)
410 (setq hydra-curr-body-fn
411 (quote hydra-toggle/body)))
412 (defun hydra-toggle/body nil
413 "Create a hydra with no body and the heads:
415 \"t\": `toggle-truncate-lines',
416 \"f\": `auto-fill-mode',
417 \"a\": `abbrev-mode',
420 The body can be accessed via `hydra-toggle/body'."
423 (let ((hydra--ignore nil))
424 (hydra-keyboard-quit)
425 (setq hydra-curr-body-fn
426 (quote hydra-toggle/body)))
427 (when hydra-is-helpful
430 (eval hydra-toggle/hint))
432 (eval hydra-toggle/hint))))
433 (hydra-set-transient-map
436 (hydra-keyboard-quit)
440 current-prefix-arg))))))
442 (ert-deftest hydra-amaranth-vi ()
448 (set-cursor-color "#e52b50")
450 (set-cursor-color "#ffffff")
458 (defvar hydra-vi/keymap nil
459 "Keymap for hydra-vi.")
463 (107 . hydra-vi/previous-line)
464 (106 . hydra-vi/next-line)
465 (kp-subtract . hydra--negative-argument)
466 (kp-9 . hydra--digit-argument)
467 (kp-8 . hydra--digit-argument)
468 (kp-7 . hydra--digit-argument)
469 (kp-6 . hydra--digit-argument)
470 (kp-5 . hydra--digit-argument)
471 (kp-4 . hydra--digit-argument)
472 (kp-3 . hydra--digit-argument)
473 (kp-2 . hydra--digit-argument)
474 (kp-1 . hydra--digit-argument)
475 (kp-0 . hydra--digit-argument)
476 (57 . hydra--digit-argument)
477 (56 . hydra--digit-argument)
478 (55 . hydra--digit-argument)
479 (54 . hydra--digit-argument)
480 (53 . hydra--digit-argument)
481 (52 . hydra--digit-argument)
482 (51 . hydra--digit-argument)
483 (50 . hydra--digit-argument)
484 (49 . hydra--digit-argument)
485 (48 . hydra--digit-argument)
486 (45 . hydra--negative-argument)
487 (21 . hydra--universal-argument))))
489 (defvar hydra-vi/heads nil
490 "Heads for hydra-vi.")
492 (("j" next-line "" :exit nil)
497 ("q" nil "quit" :exit t))))
499 (defvar hydra-vi/hint nil
500 "Dynamic hint for hydra-vi.")
503 #("vi: j, k, [q]: quit."
504 4 5 (face hydra-face-amaranth)
505 7 8 (face hydra-face-amaranth)
506 11 12 (face hydra-face-teal)))))
507 (defun hydra-vi/next-line nil
508 "Create a hydra with no body and the heads:
511 \"k\": `previous-line',
514 The body can be accessed via `hydra-vi/body'.
516 Call the head: `next-line'."
519 (set-cursor-color "#e52b50")
520 (let ((hydra--ignore t))
521 (hydra-keyboard-quit)
522 (setq hydra-curr-body-fn
523 (quote hydra-vi/body)))
529 (function next-line)))
532 (unless hydra-lv (sit-for 0.8))))
533 (when hydra-is-helpful
536 (eval hydra-vi/hint))
537 (message (eval hydra-vi/hint))))
538 (hydra-set-transient-map
541 (hydra-keyboard-quit)
542 (set-cursor-color "#ffffff"))
544 (defun hydra-vi/previous-line nil
545 "Create a hydra with no body and the heads:
548 \"k\": `previous-line',
551 The body can be accessed via `hydra-vi/body'.
553 Call the head: `previous-line'."
556 (set-cursor-color "#e52b50")
557 (let ((hydra--ignore t))
558 (hydra-keyboard-quit)
559 (setq hydra-curr-body-fn
560 (quote hydra-vi/body)))
564 (quote previous-line))
566 (function previous-line)))
569 (unless hydra-lv (sit-for 0.8))))
570 (when hydra-is-helpful
573 (eval hydra-vi/hint))
574 (message (eval hydra-vi/hint))))
575 (hydra-set-transient-map
578 (hydra-keyboard-quit)
579 (set-cursor-color "#ffffff"))
581 (defun hydra-vi/nil nil
582 "Create a hydra with no body and the heads:
585 \"k\": `previous-line',
588 The body can be accessed via `hydra-vi/body'.
590 Call the head: `nil'."
593 (set-cursor-color "#e52b50")
594 (hydra-keyboard-quit)
595 (setq hydra-curr-body-fn
596 (quote hydra-vi/body)))
597 (defun hydra-vi/body nil
598 "Create a hydra with no body and the heads:
601 \"k\": `previous-line',
604 The body can be accessed via `hydra-vi/body'."
607 (set-cursor-color "#e52b50")
608 (let ((hydra--ignore nil))
609 (hydra-keyboard-quit)
610 (setq hydra-curr-body-fn
611 (quote hydra-vi/body)))
612 (when hydra-is-helpful
615 (eval hydra-vi/hint))
616 (message (eval hydra-vi/hint))))
617 (hydra-set-transient-map
620 (hydra-keyboard-quit)
621 (set-cursor-color "#ffffff"))
624 current-prefix-arg))))))
626 (ert-deftest hydra-zoom-duplicate-1 ()
630 '(defhydra hydra-zoom ()
632 ("r" (text-scale-set 0) "reset")
633 ("0" (text-scale-set 0) :bind nil :exit t)
634 ("1" (text-scale-set 0) nil :bind nil :exit t)))
637 (defvar hydra-zoom/keymap nil
638 "Keymap for hydra-zoom.")
641 (114 . hydra-zoom/lambda-r)
642 (kp-subtract . hydra--negative-argument)
643 (kp-9 . hydra--digit-argument)
644 (kp-8 . hydra--digit-argument)
645 (kp-7 . hydra--digit-argument)
646 (kp-6 . hydra--digit-argument)
647 (kp-5 . hydra--digit-argument)
648 (kp-4 . hydra--digit-argument)
649 (kp-3 . hydra--digit-argument)
650 (kp-2 . hydra--digit-argument)
651 (kp-1 . hydra--digit-argument)
652 (kp-0 . hydra--digit-argument)
653 (57 . hydra--digit-argument)
654 (56 . hydra--digit-argument)
655 (55 . hydra--digit-argument)
656 (54 . hydra--digit-argument)
657 (53 . hydra--digit-argument)
658 (52 . hydra--digit-argument)
659 (51 . hydra--digit-argument)
660 (50 . hydra--digit-argument)
661 (49 . hydra-zoom/lambda-0-and-exit)
662 (48 . hydra-zoom/lambda-0-and-exit)
663 (45 . hydra--negative-argument)
664 (21 . hydra--universal-argument))))
666 (defvar hydra-zoom/heads nil
667 "Heads for hydra-zoom.")
684 (defvar hydra-zoom/hint nil
685 "Dynamic hint for hydra-zoom.")
688 #("zoom: [r 0]: reset."
689 7 8 (face hydra-face-red)
690 9 10 (face hydra-face-blue)))))
691 (defun hydra-zoom/lambda-r nil
692 "Create a hydra with no body and the heads:
694 \"r\": `(text-scale-set 0)',
695 \"0\": `(text-scale-set 0)',
696 \"1\": `(text-scale-set 0)'
698 The body can be accessed via `hydra-zoom/body'.
700 Call the head: `(text-scale-set 0)'."
703 (let ((hydra--ignore t))
704 (hydra-keyboard-quit)
705 (setq hydra-curr-body-fn
706 (quote hydra-zoom/body)))
712 (text-scale-set 0))))
715 (unless hydra-lv (sit-for 0.8))))
716 (when hydra-is-helpful
719 (eval hydra-zoom/hint))
721 (eval hydra-zoom/hint))))
722 (hydra-set-transient-map
725 (hydra-keyboard-quit)
728 (defun hydra-zoom/lambda-0-and-exit nil
729 "Create a hydra with no body and the heads:
731 \"r\": `(text-scale-set 0)',
732 \"0\": `(text-scale-set 0)',
733 \"1\": `(text-scale-set 0)'
735 The body can be accessed via `hydra-zoom/body'.
737 Call the head: `(text-scale-set 0)'."
740 (hydra-keyboard-quit)
741 (setq hydra-curr-body-fn
742 (quote hydra-zoom/body))
747 (text-scale-set 0)))))
748 (defun hydra-zoom/body nil
749 "Create a hydra with no body and the heads:
751 \"r\": `(text-scale-set 0)',
752 \"0\": `(text-scale-set 0)',
753 \"1\": `(text-scale-set 0)'
755 The body can be accessed via `hydra-zoom/body'."
758 (let ((hydra--ignore nil))
759 (hydra-keyboard-quit)
760 (setq hydra-curr-body-fn
761 (quote hydra-zoom/body)))
762 (when hydra-is-helpful
765 (eval hydra-zoom/hint))
767 (eval hydra-zoom/hint))))
768 (hydra-set-transient-map
771 (hydra-keyboard-quit)
775 current-prefix-arg))))))
777 (ert-deftest hydra-zoom-duplicate-2 ()
781 '(defhydra hydra-zoom ()
783 ("r" (text-scale-set 0) "reset")
784 ("0" (text-scale-set 0) :bind nil :exit t)
785 ("1" (text-scale-set 0) nil :bind nil)))
788 (defvar hydra-zoom/keymap nil
789 "Keymap for hydra-zoom.")
792 (114 . hydra-zoom/lambda-r)
793 (kp-subtract . hydra--negative-argument)
794 (kp-9 . hydra--digit-argument)
795 (kp-8 . hydra--digit-argument)
796 (kp-7 . hydra--digit-argument)
797 (kp-6 . hydra--digit-argument)
798 (kp-5 . hydra--digit-argument)
799 (kp-4 . hydra--digit-argument)
800 (kp-3 . hydra--digit-argument)
801 (kp-2 . hydra--digit-argument)
802 (kp-1 . hydra--digit-argument)
803 (kp-0 . hydra--digit-argument)
804 (57 . hydra--digit-argument)
805 (56 . hydra--digit-argument)
806 (55 . hydra--digit-argument)
807 (54 . hydra--digit-argument)
808 (53 . hydra--digit-argument)
809 (52 . hydra--digit-argument)
810 (51 . hydra--digit-argument)
811 (50 . hydra--digit-argument)
812 (49 . hydra-zoom/lambda-r)
813 (48 . hydra-zoom/lambda-0-and-exit)
814 (45 . hydra--negative-argument)
815 (21 . hydra--universal-argument))))
817 (defvar hydra-zoom/heads nil
818 "Heads for hydra-zoom.")
835 (defvar hydra-zoom/hint nil
836 "Dynamic hint for hydra-zoom.")
839 #("zoom: [r 0]: reset."
840 7 8 (face hydra-face-red)
841 9 10 (face hydra-face-blue)))))
842 (defun hydra-zoom/lambda-r nil
843 "Create a hydra with no body and the heads:
845 \"r\": `(text-scale-set 0)',
846 \"0\": `(text-scale-set 0)',
847 \"1\": `(text-scale-set 0)'
849 The body can be accessed via `hydra-zoom/body'.
851 Call the head: `(text-scale-set 0)'."
854 (let ((hydra--ignore t))
855 (hydra-keyboard-quit)
856 (setq hydra-curr-body-fn
857 (quote hydra-zoom/body)))
863 (text-scale-set 0))))
866 (unless hydra-lv (sit-for 0.8))))
867 (when hydra-is-helpful
870 (eval hydra-zoom/hint))
872 (eval hydra-zoom/hint))))
873 (hydra-set-transient-map
876 (hydra-keyboard-quit)
879 (defun hydra-zoom/lambda-0-and-exit nil
880 "Create a hydra with no body and the heads:
882 \"r\": `(text-scale-set 0)',
883 \"0\": `(text-scale-set 0)',
884 \"1\": `(text-scale-set 0)'
886 The body can be accessed via `hydra-zoom/body'.
888 Call the head: `(text-scale-set 0)'."
891 (hydra-keyboard-quit)
892 (setq hydra-curr-body-fn
893 (quote hydra-zoom/body))
898 (text-scale-set 0)))))
899 (defun hydra-zoom/body nil
900 "Create a hydra with no body and the heads:
902 \"r\": `(text-scale-set 0)',
903 \"0\": `(text-scale-set 0)',
904 \"1\": `(text-scale-set 0)'
906 The body can be accessed via `hydra-zoom/body'."
909 (let ((hydra--ignore nil))
910 (hydra-keyboard-quit)
911 (setq hydra-curr-body-fn
912 (quote hydra-zoom/body)))
913 (when hydra-is-helpful
916 (eval hydra-zoom/hint))
918 (eval hydra-zoom/hint))))
919 (hydra-set-transient-map
922 (hydra-keyboard-quit)
926 current-prefix-arg))))))
928 (ert-deftest defhydradio ()
931 '(defhydradio hydra-test ()
932 (num "Num" [0 1 2 3 4 5 6 7 8 9 10])
933 (str "Str" ["foo" "bar" "baz"])))
935 (defvar hydra-test/num 0
937 (put 'hydra-test/num 'range [0 1 2 3 4 5 6 7 8 9 10])
938 (defun hydra-test/num ()
939 (hydra--cycle-radio 'hydra-test/num))
940 (defvar hydra-test/str "foo"
942 (put 'hydra-test/str 'range ["foo" "bar" "baz"])
943 (defun hydra-test/str ()
944 (hydra--cycle-radio 'hydra-test/str))
945 (defvar hydra-test/names '(hydra-test/num hydra-test/str))))))
947 (ert-deftest hydra-blue-compat ()
951 '(defhydra hydra-toggle (:color blue)
953 ("t" toggle-truncate-lines "truncate")
954 ("f" auto-fill-mode "fill")
955 ("a" abbrev-mode "abbrev")
958 '(defhydra hydra-toggle (:exit t)
960 ("t" toggle-truncate-lines "truncate")
961 ("f" auto-fill-mode "fill")
962 ("a" abbrev-mode "abbrev")
963 ("q" nil "cancel"))))))
965 (ert-deftest hydra-amaranth-compat ()
971 (set-cursor-color "#e52b50")
973 (set-cursor-color "#ffffff")
982 (set-cursor-color "#e52b50")
984 (set-cursor-color "#ffffff")
989 ("q" nil "quit"))))))
991 (ert-deftest hydra-pink-compat ()
995 '(defhydra hydra-zoom (global-map "<f2>"
998 ("g" text-scale-increase "in")
999 ("l" text-scale-decrease "out")
1002 '(defhydra hydra-zoom (global-map "<f2>"
1005 ("g" text-scale-increase "in")
1006 ("l" text-scale-decrease "out")
1007 ("q" nil "quit"))))))
1009 (ert-deftest hydra-teal-compat ()
1013 '(defhydra hydra-zoom (global-map "<f2>"
1016 ("g" text-scale-increase "in")
1017 ("l" text-scale-decrease "out")
1020 '(defhydra hydra-zoom (global-map "<f2>"
1024 ("g" text-scale-increase "in")
1025 ("l" text-scale-decrease "out")
1026 ("q" nil "quit"))))))
1028 (ert-deftest hydra-format-1 ()
1030 (let ((hydra-fontify-head-function
1031 'hydra-fontify-head-greyscale))
1036 _a_ abbrev-mode: %`abbrev-mode
1037 _d_ debug-on-error: %`debug-on-error
1038 _f_ auto-fill-mode: %`auto-fill-function
1039 " '(("a" abbrev-mode nil)
1040 ("d" toggle-debug-on-error nil)
1041 ("f" auto-fill-mode nil)
1042 ("g" golden-ratio-mode nil)
1043 ("t" toggle-truncate-lines nil)
1044 ("w" whitespace-mode nil)
1046 '(concat (format "%s abbrev-mode: %S
1047 %s debug-on-error: %S
1048 %s auto-fill-mode: %S
1049 " "{a}" abbrev-mode "{d}" debug-on-error "{f}" auto-fill-function) "[{q}]: quit."))))
1051 (ert-deftest hydra-format-2 ()
1053 (let ((hydra-fontify-head-function
1054 'hydra-fontify-head-greyscale))
1059 '(("a" (quote t) "" :cmd-name bar/lambda-a :exit nil)
1060 ("q" nil "" :cmd-name bar/nil :exit t))))
1061 '(concat (format " bar %s\n" foo) "{a}, [q]."))))
1063 (ert-deftest hydra-format-3 ()
1065 (let ((hydra-fontify-head-function
1066 'hydra-fontify-head-greyscale))
1070 "\n_<SPC>_ ^^ace jump\n"
1071 '(("<SPC>" ace-jump-char-mode nil :cmd-name bar/ace-jump-char-mode))))
1072 '(concat (format "%s ace jump\n" "{<SPC>}") ""))))
1074 (ert-deftest hydra-format-4 ()
1076 (equal (hydra--format
1078 '(nil nil :hint nil)
1080 '(("j" nil nil :exit t) ("k" nil nil :exit t)))
1081 '(concat (format "%s,%s"
1082 #("j" 0 1 (face hydra-face-blue))
1083 #("k" 0 1 (face hydra-face-blue))) ""))))
1085 (ert-deftest hydra-format-5 ()
1087 (equal (hydra--format
1088 nil nil "\n_-_: mark _u_: unmark\n"
1089 '(("-" Buffer-menu-mark)
1090 ("u" Buffer-menu-unmark)))
1093 "%s: mark %s: unmark\n"
1094 #("-" 0 1 (face hydra-face-red))
1095 #("u" 0 1 (face hydra-face-red)))
1098 (ert-deftest hydra-format-6 ()
1100 (equal (hydra--format
1101 nil nil "\n[_]_] forward [_[_] backward\n"
1102 '(("]" forward-char)
1103 ("[" backward-char)))
1106 "[%s] forward [%s] backward\n"
1115 (ert-deftest hydra-format-7 ()
1118 (hydra--format nil nil "test"
1119 '(("%" forward-char "" :exit nil)
1120 ("b" backward-char "" :exit nil)))
1123 6 7 (face hydra-face-red)
1124 7 8 (face hydra-face-red)
1125 8 9 (face hydra-face-red)
1126 9 10 (face hydra-face-red)
1127 12 13 (face hydra-face-red)))))
1130 (hydra--format nil nil "\n_%_ forward\n"
1131 '(("%" forward-char nil :exit nil)))
1136 0 2 (face hydra-face-red)))
1139 (ert-deftest hydra-format-with-sexp-1 ()
1141 (let ((hydra-fontify-head-function
1142 'hydra-fontify-head-greyscale))
1145 "\n_n_ narrow-or-widen-dwim %(progn (message \"checking\")(buffer-narrowed-p))asdf\n"
1146 '(("n" narrow-to-region nil) ("q" nil "cancel" :exit t))))
1147 '(concat (format "%s narrow-or-widen-dwim %Sasdf\n"
1150 (message "checking")
1151 (buffer-narrowed-p)))
1152 "[[q]]: cancel."))))
1154 (ert-deftest hydra-format-with-sexp-2 ()
1156 (let ((hydra-fontify-head-function
1157 'hydra-fontify-head-greyscale))
1160 "\n_n_ narrow-or-widen-dwim %s(progn (message \"checking\")(buffer-narrowed-p))asdf\n"
1161 '(("n" narrow-to-region nil) ("q" nil "cancel" :exit t))))
1162 '(concat (format "%s narrow-or-widen-dwim %sasdf\n"
1165 (message "checking")
1166 (buffer-narrowed-p)))
1167 "[[q]]: cancel."))))
1169 (ert-deftest hydra-compat-colors-2 ()
1173 '(defhydra hydra-test (:color amaranth)
1175 ("b" fun-b :color blue)
1176 ("c" fun-c :color blue)
1177 ("d" fun-d :color blue)
1178 ("e" fun-e :color blue)
1179 ("f" fun-f :color blue)))
1181 '(defhydra hydra-test (:color teal)
1182 ("a" fun-a :color red)
1189 (ert-deftest hydra-compat-colors-3 ()
1193 '(defhydra hydra-test ()
1195 ("b" fun-b :color blue)
1196 ("c" fun-c :color blue)
1197 ("d" fun-d :color blue)
1198 ("e" fun-e :color blue)
1199 ("f" fun-f :color blue)))
1201 '(defhydra hydra-test (:color blue)
1202 ("a" fun-a :color red)
1209 (ert-deftest hydra-compat-colors-4 ()
1213 '(defhydra hydra-test ()
1219 ("f" fun-f :exit t)))
1221 '(defhydra hydra-test (:exit t)
1222 ("a" fun-a :exit nil)
1229 (ert-deftest hydra--pad ()
1230 (should (equal (hydra--pad '(a b c) 3)
1232 (should (equal (hydra--pad '(a) 3)
1235 (ert-deftest hydra--matrix ()
1236 (should (equal (hydra--matrix '(a b c) 2 2)
1238 (should (equal (hydra--matrix '(a b c d e f g h i) 4 3)
1239 '((a b c d) (e f g h) (i nil nil nil)))))
1241 (ert-deftest hydra--cell ()
1242 (should (equal (hydra--cell "% -75s %%`%s" '(hydra-lv hydra-verbose))
1243 "When non-nil, `lv-message' (not `message') will be used to display hints. %`hydra-lv^^^^^
1244 When non-nil, hydra will issue some non essential style warnings. %`hydra-verbose")))
1246 (ert-deftest hydra--vconcat ()
1247 (should (equal (hydra--vconcat '("abc\ndef" "012\n34" "def\nabc"))
1248 "abc012def\ndef34abc")))
1250 (defhydradio hydra-tng ()
1251 (picard "_p_ Captain Jean Luc Picard:")
1252 (riker "_r_ Commander William Riker:")
1253 (data "_d_ Lieutenant Commander Data:")
1255 (la-forge "_f_ Geordi La Forge:")
1256 (troi "_t_ Deanna Troi:")
1257 (dr-crusher "_c_ Doctor Beverly Crusher:")
1258 (phaser "_h_ Set phasers to " [stun kill]))
1260 (ert-deftest hydra--table ()
1261 (let ((hydra-cell-format "% -30s %% -8`%s"))
1262 (should (equal (hydra--table hydra-tng/names 5 2)
1264 _p_ Captain Jean Luc Picard: % -8`hydra-tng/picard^^ _t_ Deanna Troi: % -8`hydra-tng/troi^^^^^^
1265 _r_ Commander William Riker: % -8`hydra-tng/riker^^^ _c_ Doctor Beverly Crusher: % -8`hydra-tng/dr-crusher
1266 _d_ Lieutenant Commander Data: % -8`hydra-tng/data^^^^ _h_ Set phasers to % -8`hydra-tng/phaser^^^^
1267 _w_ Worf: % -8`hydra-tng/worf^^^^
1268 _f_ Geordi La Forge: % -8`hydra-tng/la-forge" 1)))
1269 (should (equal (hydra--table hydra-tng/names 4 3)
1271 _p_ Captain Jean Luc Picard: % -8`hydra-tng/picard _f_ Geordi La Forge: % -8`hydra-tng/la-forge^^
1272 _r_ Commander William Riker: % -8`hydra-tng/riker^ _t_ Deanna Troi: % -8`hydra-tng/troi^^^^^^
1273 _d_ Lieutenant Commander Data: % -8`hydra-tng/data^^ _c_ Doctor Beverly Crusher: % -8`hydra-tng/dr-crusher
1274 _w_ Worf: % -8`hydra-tng/worf^^ _h_ Set phasers to % -8`hydra-tng/phaser^^^^" 1)))))
1276 (ert-deftest hydra--make-funcall ()
1277 (should (equal (let ((body-pre 'foo))
1278 (hydra--make-funcall body-pre)
1280 '(funcall (function foo)))))
1282 (defhydra hydra-simple-1 (global-map "C-c")
1287 (defhydra hydra-simple-2 (global-map "C-c" :color amaranth)
1288 ("c" self-insert-command)
1289 ("d" self-insert-command)
1292 (defhydra hydra-simple-3 (global-map "C-c")
1297 (defmacro hydra-with (in &rest body)
1298 `(let ((temp-buffer (generate-new-buffer " *temp*")))
1299 (save-window-excursion
1302 (switch-to-buffer temp-buffer)
1303 (transient-mark-mode 1)
1305 (goto-char (point-min))
1306 (when (search-forward "~" nil t)
1307 (backward-delete-char 1)
1309 (goto-char (point-max))
1310 (search-backward "|")
1312 (setq current-prefix-arg)
1315 (when (region-active-p)
1316 (exchange-point-and-mark)
1318 (buffer-substring-no-properties
1321 (and (buffer-name temp-buffer)
1322 (kill-buffer temp-buffer))))))
1324 (ert-deftest hydra-integration-1 ()
1325 (should (string= (hydra-with "|"
1327 (kbd "C-c aabbaaqaabbaa")))
1329 (should (string= (hydra-with "|"
1332 (kbd "C-c aabb C-g"))
1334 (execute-kbd-macro "aaqaabbaa"))
1337 (ert-deftest hydra-integration-2 ()
1338 (should (string= (hydra-with "|"
1340 (kbd "C-c c 1 c 2 d 4 c q")))
1342 (should (string= (hydra-with "|"
1344 (kbd "C-c c 1 c C-u d C-u 10 c q")))
1345 "ccddddcccccccccc|")))
1347 (ert-deftest hydra-integration-3 ()
1348 (should (string= (hydra-with "foo\nbar|"
1350 (kbd "C-c g 1 RET q")))
1353 (ert-deftest hydra-columns-1 ()
1354 (should (equal (eval
1359 '(defhydra hydra-info (:color blue
1362 ("?" Info-summary "summary")
1363 ("]" Info-forward-node "forward")
1364 ("[" Info-backward-node "backward")
1365 ("<" Info-top-node "top node")
1366 (">" Info-final-node "final node")
1367 ("h" Info-help "help")
1368 ("d" Info-directory "info dir")
1369 ("f" Info-follow-reference "follow ref")
1370 ("g" Info-goto-node "goto node")
1371 ("l" Info-history-back "hist back")
1372 ("r" Info-history-forward "hist forward")
1373 ("i" Info-index "index")
1374 ("I" Info-virtual-index "virtual index")
1375 ("L" Info-history "hist")
1376 ("n" Info-next "next")
1377 ("p" Info-prev "previous")
1378 ("s" Info-search "search")
1379 ("S" Info-search-case-sensitively "case-search")
1380 ("T" Info-toc "TOC")
1382 ("m" Info-menu "menu")
1383 ("t" hydra-info-to/body "info-to")))))))
1385 ?: summary ]: forward [: backward
1386 <: top node >: final node h: help
1387 d: info dir f: follow ref g: goto node
1388 l: hist back r: hist forward i: index
1389 I: virtual index L: hist n: next
1390 p: previous s: search S: case-search
1391 T: TOC u: up m: menu
1393 11 12 (face hydra-face-blue)
1394 28 29 (face hydra-face-blue)
1395 45 46 (face hydra-face-blue)
1396 57 58 (face hydra-face-blue)
1397 74 75 (face hydra-face-blue)
1398 91 92 (face hydra-face-blue)
1399 99 100 (face hydra-face-blue)
1400 116 117 (face hydra-face-blue)
1401 133 134 (face hydra-face-blue)
1402 146 147 (face hydra-face-blue)
1403 163 164 (face hydra-face-blue)
1404 180 181 (face hydra-face-blue)
1405 189 190 (face hydra-face-blue)
1406 206 207 (face hydra-face-blue)
1407 223 224 (face hydra-face-blue)
1408 231 232 (face hydra-face-blue)
1409 248 249 (face hydra-face-blue)
1410 265 266 (face hydra-face-blue)
1411 280 281 (face hydra-face-blue)
1412 297 298 (face hydra-face-blue)
1413 314 315 (face hydra-face-blue)
1414 322 323 (face hydra-face-blue)))))
1416 (provide 'hydra-test)
1418 ;;; hydra-test.el ends here