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 (message "Emacs version: %s" emacs-version)
30 (ert-deftest hydra-red-error ()
34 '(defhydra hydra-error (global-map "M-g")
36 ("h" first-error "first")
37 ("j" next-error "next")
38 ("k" previous-error "prev")
39 ("SPC" hydra-repeat "rep" :bind nil)))
42 (defvar hydra-error/keymap nil
43 "Keymap for hydra-error.")
47 (107 . hydra-error/previous-error)
48 (106 . hydra-error/next-error)
49 (104 . hydra-error/first-error)
50 (kp-subtract . hydra--negative-argument)
51 (kp-9 . hydra--digit-argument)
52 (kp-8 . hydra--digit-argument)
53 (kp-7 . hydra--digit-argument)
54 (kp-6 . hydra--digit-argument)
55 (kp-5 . hydra--digit-argument)
56 (kp-4 . hydra--digit-argument)
57 (kp-3 . hydra--digit-argument)
58 (kp-2 . hydra--digit-argument)
59 (kp-1 . hydra--digit-argument)
60 (kp-0 . hydra--digit-argument)
61 (57 . hydra--digit-argument)
62 (56 . hydra--digit-argument)
63 (55 . hydra--digit-argument)
64 (54 . hydra--digit-argument)
65 (53 . hydra--digit-argument)
66 (52 . hydra--digit-argument)
67 (51 . hydra--digit-argument)
68 (50 . hydra--digit-argument)
69 (49 . hydra--digit-argument)
70 (48 . hydra--digit-argument)
71 (45 . hydra--negative-argument)
72 (21 . hydra--universal-argument))))
74 (defvar hydra-error/heads nil
75 "Heads for hydra-error.")
95 (defvar hydra-error/hint nil
96 "Dynamic hint for hydra-error.")
99 #("error: [h]: first, [j]: next, [k]: prev, [SPC]: rep."
100 8 9 (face hydra-face-red)
101 20 21 (face hydra-face-red)
102 31 32 (face hydra-face-red)
103 42 45 (face hydra-face-red)))))
104 (defun hydra-error/first-error nil
105 "Create a hydra with a \"M-g\" body and the heads:
107 \"h\": `first-error',
109 \"k\": `previous-error',
110 \"SPC\": `hydra-repeat'
112 The body can be accessed via `hydra-error/body'.
114 Call the head: `first-error'."
117 (let ((hydra--ignore t))
118 (hydra-keyboard-quit)
119 (setq hydra-curr-body-fn
120 (quote hydra-error/body)))
126 (function first-error)))
129 (unless hydra-lv (sit-for 0.8))))
130 (when hydra-is-helpful
133 (eval hydra-error/hint))
135 (eval hydra-error/hint))))
136 (hydra-set-transient-map
139 (hydra-keyboard-quit)
142 (defun hydra-error/next-error nil
143 "Create a hydra with a \"M-g\" body and the heads:
145 \"h\": `first-error',
147 \"k\": `previous-error',
148 \"SPC\": `hydra-repeat'
150 The body can be accessed via `hydra-error/body'.
152 Call the head: `next-error'."
155 (let ((hydra--ignore t))
156 (hydra-keyboard-quit)
157 (setq hydra-curr-body-fn
158 (quote hydra-error/body)))
164 (function next-error)))
167 (unless hydra-lv (sit-for 0.8))))
168 (when hydra-is-helpful
171 (eval hydra-error/hint))
173 (eval hydra-error/hint))))
174 (hydra-set-transient-map
177 (hydra-keyboard-quit)
180 (defun hydra-error/previous-error nil
181 "Create a hydra with a \"M-g\" body and the heads:
183 \"h\": `first-error',
185 \"k\": `previous-error',
186 \"SPC\": `hydra-repeat'
188 The body can be accessed via `hydra-error/body'.
190 Call the head: `previous-error'."
193 (let ((hydra--ignore t))
194 (hydra-keyboard-quit)
195 (setq hydra-curr-body-fn
196 (quote hydra-error/body)))
200 (quote previous-error))
202 (function previous-error)))
205 (unless hydra-lv (sit-for 0.8))))
206 (when hydra-is-helpful
209 (eval hydra-error/hint))
211 (eval hydra-error/hint))))
212 (hydra-set-transient-map
215 (hydra-keyboard-quit)
222 (define-key global-map (kbd "M-g")
224 (define-key global-map [134217831 104]
225 (quote hydra-error/first-error))
226 (define-key global-map [134217831 106]
227 (quote hydra-error/next-error))
228 (define-key global-map [134217831 107]
230 hydra-error/previous-error))
231 (defun hydra-error/body nil
232 "Create a hydra with a \"M-g\" body and the heads:
234 \"h\": `first-error',
236 \"k\": `previous-error',
237 \"SPC\": `hydra-repeat'
239 The body can be accessed via `hydra-error/body'."
242 (let ((hydra--ignore nil))
243 (hydra-keyboard-quit)
244 (setq hydra-curr-body-fn
245 (quote hydra-error/body)))
246 (when hydra-is-helpful
249 (eval hydra-error/hint))
251 (eval hydra-error/hint))))
252 (hydra-set-transient-map
255 (hydra-keyboard-quit)
259 current-prefix-arg))))))
261 (ert-deftest hydra-blue-toggle ()
265 '(defhydra hydra-toggle (:color blue)
267 ("t" toggle-truncate-lines "truncate")
268 ("f" auto-fill-mode "fill")
269 ("a" abbrev-mode "abbrev")
273 (defvar hydra-toggle/keymap nil
274 "Keymap for hydra-toggle.")
277 (113 . hydra-toggle/nil)
278 (97 . hydra-toggle/abbrev-mode-and-exit)
279 (102 . hydra-toggle/auto-fill-mode-and-exit)
280 (116 . hydra-toggle/toggle-truncate-lines-and-exit)
281 (kp-subtract . hydra--negative-argument)
282 (kp-9 . hydra--digit-argument)
283 (kp-8 . hydra--digit-argument)
284 (kp-7 . hydra--digit-argument)
285 (kp-6 . hydra--digit-argument)
286 (kp-5 . hydra--digit-argument)
287 (kp-4 . hydra--digit-argument)
288 (kp-3 . hydra--digit-argument)
289 (kp-2 . hydra--digit-argument)
290 (kp-1 . hydra--digit-argument)
291 (kp-0 . hydra--digit-argument)
292 (57 . hydra--digit-argument)
293 (56 . hydra--digit-argument)
294 (55 . hydra--digit-argument)
295 (54 . hydra--digit-argument)
296 (53 . hydra--digit-argument)
297 (52 . hydra--digit-argument)
298 (51 . hydra--digit-argument)
299 (50 . hydra--digit-argument)
300 (49 . hydra--digit-argument)
301 (48 . hydra--digit-argument)
302 (45 . hydra--negative-argument)
303 (21 . hydra--universal-argument))))
305 (defvar hydra-toggle/heads nil
306 "Heads for hydra-toggle.")
309 toggle-truncate-lines
320 ("q" nil "cancel" :exit t))))
322 (defvar hydra-toggle/hint nil
323 "Dynamic hint for hydra-toggle.")
326 #("toggle: [t]: truncate, [f]: fill, [a]: abbrev, [q]: cancel."
327 9 10 (face hydra-face-blue)
328 24 25 (face hydra-face-blue)
329 35 36 (face hydra-face-blue)
330 48 49 (face hydra-face-blue)))))
331 (defun hydra-toggle/toggle-truncate-lines-and-exit nil
332 "Create a hydra with no body and the heads:
334 \"t\": `toggle-truncate-lines',
335 \"f\": `auto-fill-mode',
336 \"a\": `abbrev-mode',
339 The body can be accessed via `hydra-toggle/body'.
341 Call the head: `toggle-truncate-lines'."
344 (hydra-keyboard-quit)
345 (setq hydra-curr-body-fn
346 (quote hydra-toggle/body))
349 (quote toggle-truncate-lines))
352 toggle-truncate-lines))))
353 (defun hydra-toggle/auto-fill-mode-and-exit nil
354 "Create a hydra with no body and the heads:
356 \"t\": `toggle-truncate-lines',
357 \"f\": `auto-fill-mode',
358 \"a\": `abbrev-mode',
361 The body can be accessed via `hydra-toggle/body'.
363 Call the head: `auto-fill-mode'."
366 (hydra-keyboard-quit)
367 (setq hydra-curr-body-fn
368 (quote hydra-toggle/body))
371 (quote auto-fill-mode))
373 (function auto-fill-mode))))
374 (defun hydra-toggle/abbrev-mode-and-exit nil
375 "Create a hydra with no body and the heads:
377 \"t\": `toggle-truncate-lines',
378 \"f\": `auto-fill-mode',
379 \"a\": `abbrev-mode',
382 The body can be accessed via `hydra-toggle/body'.
384 Call the head: `abbrev-mode'."
387 (hydra-keyboard-quit)
388 (setq hydra-curr-body-fn
389 (quote hydra-toggle/body))
394 (function abbrev-mode))))
395 (defun hydra-toggle/nil nil
396 "Create a hydra with no body and the heads:
398 \"t\": `toggle-truncate-lines',
399 \"f\": `auto-fill-mode',
400 \"a\": `abbrev-mode',
403 The body can be accessed via `hydra-toggle/body'.
405 Call the head: `nil'."
408 (hydra-keyboard-quit)
409 (setq hydra-curr-body-fn
410 (quote hydra-toggle/body)))
411 (defun hydra-toggle/body nil
412 "Create a hydra with no body and the heads:
414 \"t\": `toggle-truncate-lines',
415 \"f\": `auto-fill-mode',
416 \"a\": `abbrev-mode',
419 The body can be accessed via `hydra-toggle/body'."
422 (let ((hydra--ignore nil))
423 (hydra-keyboard-quit)
424 (setq hydra-curr-body-fn
425 (quote hydra-toggle/body)))
426 (when hydra-is-helpful
429 (eval hydra-toggle/hint))
431 (eval hydra-toggle/hint))))
432 (hydra-set-transient-map
435 (hydra-keyboard-quit)
439 current-prefix-arg))))))
441 (ert-deftest hydra-amaranth-vi ()
447 (set-cursor-color "#e52b50")
449 (set-cursor-color "#ffffff")
457 (defvar hydra-vi/keymap nil
458 "Keymap for hydra-vi.")
462 (107 . hydra-vi/previous-line)
463 (106 . hydra-vi/next-line)
464 (kp-subtract . hydra--negative-argument)
465 (kp-9 . hydra--digit-argument)
466 (kp-8 . hydra--digit-argument)
467 (kp-7 . hydra--digit-argument)
468 (kp-6 . hydra--digit-argument)
469 (kp-5 . hydra--digit-argument)
470 (kp-4 . hydra--digit-argument)
471 (kp-3 . hydra--digit-argument)
472 (kp-2 . hydra--digit-argument)
473 (kp-1 . hydra--digit-argument)
474 (kp-0 . hydra--digit-argument)
475 (57 . hydra--digit-argument)
476 (56 . hydra--digit-argument)
477 (55 . hydra--digit-argument)
478 (54 . hydra--digit-argument)
479 (53 . hydra--digit-argument)
480 (52 . hydra--digit-argument)
481 (51 . hydra--digit-argument)
482 (50 . hydra--digit-argument)
483 (49 . hydra--digit-argument)
484 (48 . hydra--digit-argument)
485 (45 . hydra--negative-argument)
486 (21 . hydra--universal-argument))))
488 (defvar hydra-vi/heads nil
489 "Heads for hydra-vi.")
491 (("j" next-line "" :exit nil)
496 ("q" nil "quit" :exit t))))
498 (defvar hydra-vi/hint nil
499 "Dynamic hint for hydra-vi.")
502 #("vi: j, k, [q]: quit."
503 4 5 (face hydra-face-amaranth)
504 7 8 (face hydra-face-amaranth)
505 11 12 (face hydra-face-teal)))))
506 (defun hydra-vi/next-line nil
507 "Create a hydra with no body and the heads:
510 \"k\": `previous-line',
513 The body can be accessed via `hydra-vi/body'.
515 Call the head: `next-line'."
518 (set-cursor-color "#e52b50")
519 (let ((hydra--ignore t))
520 (hydra-keyboard-quit)
521 (setq hydra-curr-body-fn
522 (quote hydra-vi/body)))
528 (function next-line)))
531 (unless hydra-lv (sit-for 0.8))))
532 (when hydra-is-helpful
535 (eval hydra-vi/hint))
536 (message (eval hydra-vi/hint))))
537 (hydra-set-transient-map
540 (hydra-keyboard-quit)
541 (set-cursor-color "#ffffff"))
543 (defun hydra-vi/previous-line nil
544 "Create a hydra with no body and the heads:
547 \"k\": `previous-line',
550 The body can be accessed via `hydra-vi/body'.
552 Call the head: `previous-line'."
555 (set-cursor-color "#e52b50")
556 (let ((hydra--ignore t))
557 (hydra-keyboard-quit)
558 (setq hydra-curr-body-fn
559 (quote hydra-vi/body)))
563 (quote previous-line))
565 (function previous-line)))
568 (unless hydra-lv (sit-for 0.8))))
569 (when hydra-is-helpful
572 (eval hydra-vi/hint))
573 (message (eval hydra-vi/hint))))
574 (hydra-set-transient-map
577 (hydra-keyboard-quit)
578 (set-cursor-color "#ffffff"))
580 (defun hydra-vi/nil nil
581 "Create a hydra with no body and the heads:
584 \"k\": `previous-line',
587 The body can be accessed via `hydra-vi/body'.
589 Call the head: `nil'."
592 (set-cursor-color "#e52b50")
593 (hydra-keyboard-quit)
594 (setq hydra-curr-body-fn
595 (quote hydra-vi/body)))
596 (defun hydra-vi/body nil
597 "Create a hydra with no body and the heads:
600 \"k\": `previous-line',
603 The body can be accessed via `hydra-vi/body'."
606 (set-cursor-color "#e52b50")
607 (let ((hydra--ignore nil))
608 (hydra-keyboard-quit)
609 (setq hydra-curr-body-fn
610 (quote hydra-vi/body)))
611 (when hydra-is-helpful
614 (eval hydra-vi/hint))
615 (message (eval hydra-vi/hint))))
616 (hydra-set-transient-map
619 (hydra-keyboard-quit)
620 (set-cursor-color "#ffffff"))
623 current-prefix-arg))))))
625 (ert-deftest hydra-zoom-duplicate-1 ()
629 '(defhydra hydra-zoom ()
631 ("r" (text-scale-set 0) "reset")
632 ("0" (text-scale-set 0) :bind nil :exit t)
633 ("1" (text-scale-set 0) nil :bind nil :exit t)))
636 (defvar hydra-zoom/keymap nil
637 "Keymap for hydra-zoom.")
640 (114 . hydra-zoom/lambda-r)
641 (kp-subtract . hydra--negative-argument)
642 (kp-9 . hydra--digit-argument)
643 (kp-8 . hydra--digit-argument)
644 (kp-7 . hydra--digit-argument)
645 (kp-6 . hydra--digit-argument)
646 (kp-5 . hydra--digit-argument)
647 (kp-4 . hydra--digit-argument)
648 (kp-3 . hydra--digit-argument)
649 (kp-2 . hydra--digit-argument)
650 (kp-1 . hydra--digit-argument)
651 (kp-0 . hydra--digit-argument)
652 (57 . hydra--digit-argument)
653 (56 . hydra--digit-argument)
654 (55 . hydra--digit-argument)
655 (54 . hydra--digit-argument)
656 (53 . hydra--digit-argument)
657 (52 . hydra--digit-argument)
658 (51 . hydra--digit-argument)
659 (50 . hydra--digit-argument)
660 (49 . hydra-zoom/lambda-0-and-exit)
661 (48 . hydra-zoom/lambda-0-and-exit)
662 (45 . hydra--negative-argument)
663 (21 . hydra--universal-argument))))
665 (defvar hydra-zoom/heads nil
666 "Heads for hydra-zoom.")
683 (defvar hydra-zoom/hint nil
684 "Dynamic hint for hydra-zoom.")
687 #("zoom: [r 0]: reset."
688 7 8 (face hydra-face-red)
689 9 10 (face hydra-face-blue)))))
690 (defun hydra-zoom/lambda-r nil
691 "Create a hydra with no body and the heads:
693 \"r\": `(text-scale-set 0)',
694 \"0\": `(text-scale-set 0)',
695 \"1\": `(text-scale-set 0)'
697 The body can be accessed via `hydra-zoom/body'.
699 Call the head: `(text-scale-set 0)'."
702 (let ((hydra--ignore t))
703 (hydra-keyboard-quit)
704 (setq hydra-curr-body-fn
705 (quote hydra-zoom/body)))
711 (text-scale-set 0))))
714 (unless hydra-lv (sit-for 0.8))))
715 (when hydra-is-helpful
718 (eval hydra-zoom/hint))
720 (eval hydra-zoom/hint))))
721 (hydra-set-transient-map
724 (hydra-keyboard-quit)
727 (defun hydra-zoom/lambda-0-and-exit nil
728 "Create a hydra with no body and the heads:
730 \"r\": `(text-scale-set 0)',
731 \"0\": `(text-scale-set 0)',
732 \"1\": `(text-scale-set 0)'
734 The body can be accessed via `hydra-zoom/body'.
736 Call the head: `(text-scale-set 0)'."
739 (hydra-keyboard-quit)
740 (setq hydra-curr-body-fn
741 (quote hydra-zoom/body))
746 (text-scale-set 0)))))
747 (defun hydra-zoom/body nil
748 "Create a hydra with no body and the heads:
750 \"r\": `(text-scale-set 0)',
751 \"0\": `(text-scale-set 0)',
752 \"1\": `(text-scale-set 0)'
754 The body can be accessed via `hydra-zoom/body'."
757 (let ((hydra--ignore nil))
758 (hydra-keyboard-quit)
759 (setq hydra-curr-body-fn
760 (quote hydra-zoom/body)))
761 (when hydra-is-helpful
764 (eval hydra-zoom/hint))
766 (eval hydra-zoom/hint))))
767 (hydra-set-transient-map
770 (hydra-keyboard-quit)
774 current-prefix-arg))))))
776 (ert-deftest hydra-zoom-duplicate-2 ()
780 '(defhydra hydra-zoom ()
782 ("r" (text-scale-set 0) "reset")
783 ("0" (text-scale-set 0) :bind nil :exit t)
784 ("1" (text-scale-set 0) nil :bind nil)))
787 (defvar hydra-zoom/keymap nil
788 "Keymap for hydra-zoom.")
791 (114 . hydra-zoom/lambda-r)
792 (kp-subtract . hydra--negative-argument)
793 (kp-9 . hydra--digit-argument)
794 (kp-8 . hydra--digit-argument)
795 (kp-7 . hydra--digit-argument)
796 (kp-6 . hydra--digit-argument)
797 (kp-5 . hydra--digit-argument)
798 (kp-4 . hydra--digit-argument)
799 (kp-3 . hydra--digit-argument)
800 (kp-2 . hydra--digit-argument)
801 (kp-1 . hydra--digit-argument)
802 (kp-0 . hydra--digit-argument)
803 (57 . hydra--digit-argument)
804 (56 . hydra--digit-argument)
805 (55 . hydra--digit-argument)
806 (54 . hydra--digit-argument)
807 (53 . hydra--digit-argument)
808 (52 . hydra--digit-argument)
809 (51 . hydra--digit-argument)
810 (50 . hydra--digit-argument)
811 (49 . hydra-zoom/lambda-r)
812 (48 . hydra-zoom/lambda-0-and-exit)
813 (45 . hydra--negative-argument)
814 (21 . hydra--universal-argument))))
816 (defvar hydra-zoom/heads nil
817 "Heads for hydra-zoom.")
834 (defvar hydra-zoom/hint nil
835 "Dynamic hint for hydra-zoom.")
838 #("zoom: [r 0]: reset."
839 7 8 (face hydra-face-red)
840 9 10 (face hydra-face-blue)))))
841 (defun hydra-zoom/lambda-r nil
842 "Create a hydra with no body and the heads:
844 \"r\": `(text-scale-set 0)',
845 \"0\": `(text-scale-set 0)',
846 \"1\": `(text-scale-set 0)'
848 The body can be accessed via `hydra-zoom/body'.
850 Call the head: `(text-scale-set 0)'."
853 (let ((hydra--ignore t))
854 (hydra-keyboard-quit)
855 (setq hydra-curr-body-fn
856 (quote hydra-zoom/body)))
862 (text-scale-set 0))))
865 (unless hydra-lv (sit-for 0.8))))
866 (when hydra-is-helpful
869 (eval hydra-zoom/hint))
871 (eval hydra-zoom/hint))))
872 (hydra-set-transient-map
875 (hydra-keyboard-quit)
878 (defun hydra-zoom/lambda-0-and-exit nil
879 "Create a hydra with no body and the heads:
881 \"r\": `(text-scale-set 0)',
882 \"0\": `(text-scale-set 0)',
883 \"1\": `(text-scale-set 0)'
885 The body can be accessed via `hydra-zoom/body'.
887 Call the head: `(text-scale-set 0)'."
890 (hydra-keyboard-quit)
891 (setq hydra-curr-body-fn
892 (quote hydra-zoom/body))
897 (text-scale-set 0)))))
898 (defun hydra-zoom/body nil
899 "Create a hydra with no body and the heads:
901 \"r\": `(text-scale-set 0)',
902 \"0\": `(text-scale-set 0)',
903 \"1\": `(text-scale-set 0)'
905 The body can be accessed via `hydra-zoom/body'."
908 (let ((hydra--ignore nil))
909 (hydra-keyboard-quit)
910 (setq hydra-curr-body-fn
911 (quote hydra-zoom/body)))
912 (when hydra-is-helpful
915 (eval hydra-zoom/hint))
917 (eval hydra-zoom/hint))))
918 (hydra-set-transient-map
921 (hydra-keyboard-quit)
925 current-prefix-arg))))))
927 (ert-deftest defhydradio ()
930 '(defhydradio hydra-test ()
931 (num "Num" [0 1 2 3 4 5 6 7 8 9 10])
932 (str "Str" ["foo" "bar" "baz"])))
934 (defvar hydra-test/num 0
936 (put 'hydra-test/num 'range [0 1 2 3 4 5 6 7 8 9 10])
937 (defun hydra-test/num ()
938 (hydra--cycle-radio 'hydra-test/num))
939 (defvar hydra-test/str "foo"
941 (put 'hydra-test/str 'range ["foo" "bar" "baz"])
942 (defun hydra-test/str ()
943 (hydra--cycle-radio 'hydra-test/str))
944 (defvar hydra-test/names '(hydra-test/num hydra-test/str))))))
946 (ert-deftest hydra-blue-compat ()
950 '(defhydra hydra-toggle (:color blue)
952 ("t" toggle-truncate-lines "truncate")
953 ("f" auto-fill-mode "fill")
954 ("a" abbrev-mode "abbrev")
957 '(defhydra hydra-toggle (:exit t)
959 ("t" toggle-truncate-lines "truncate")
960 ("f" auto-fill-mode "fill")
961 ("a" abbrev-mode "abbrev")
962 ("q" nil "cancel"))))))
964 (ert-deftest hydra-amaranth-compat ()
970 (set-cursor-color "#e52b50")
972 (set-cursor-color "#ffffff")
981 (set-cursor-color "#e52b50")
983 (set-cursor-color "#ffffff")
988 ("q" nil "quit"))))))
990 (ert-deftest hydra-pink-compat ()
994 '(defhydra hydra-zoom (global-map "<f2>"
997 ("g" text-scale-increase "in")
998 ("l" text-scale-decrease "out")
1001 '(defhydra hydra-zoom (global-map "<f2>"
1004 ("g" text-scale-increase "in")
1005 ("l" text-scale-decrease "out")
1006 ("q" nil "quit"))))))
1008 (ert-deftest hydra-teal-compat ()
1012 '(defhydra hydra-zoom (global-map "<f2>"
1015 ("g" text-scale-increase "in")
1016 ("l" text-scale-decrease "out")
1019 '(defhydra hydra-zoom (global-map "<f2>"
1023 ("g" text-scale-increase "in")
1024 ("l" text-scale-decrease "out")
1025 ("q" nil "quit"))))))
1027 (ert-deftest hydra-format-1 ()
1029 (let ((hydra-fontify-head-function
1030 'hydra-fontify-head-greyscale))
1035 _a_ abbrev-mode: %`abbrev-mode
1036 _d_ debug-on-error: %`debug-on-error
1037 _f_ auto-fill-mode: %`auto-fill-function
1038 " '(("a" abbrev-mode nil)
1039 ("d" toggle-debug-on-error nil)
1040 ("f" auto-fill-mode nil)
1041 ("g" golden-ratio-mode nil)
1042 ("t" toggle-truncate-lines nil)
1043 ("w" whitespace-mode nil)
1045 '(concat (format "%s abbrev-mode: %S
1046 %s debug-on-error: %S
1047 %s auto-fill-mode: %S
1048 " "{a}" abbrev-mode "{d}" debug-on-error "{f}" auto-fill-function) "[{q}]: quit."))))
1050 (ert-deftest hydra-format-2 ()
1052 (let ((hydra-fontify-head-function
1053 'hydra-fontify-head-greyscale))
1058 '(("a" (quote t) "" :cmd-name bar/lambda-a :exit nil)
1059 ("q" nil "" :cmd-name bar/nil :exit t))))
1060 '(concat (format " bar %s\n" foo) "{a}, [q]."))))
1062 (ert-deftest hydra-format-3 ()
1064 (let ((hydra-fontify-head-function
1065 'hydra-fontify-head-greyscale))
1069 "\n_<SPC>_ ^^ace jump\n"
1070 '(("<SPC>" ace-jump-char-mode nil :cmd-name bar/ace-jump-char-mode))))
1071 '(concat (format "%s ace jump\n" "{<SPC>}") ""))))
1073 (ert-deftest hydra-format-4 ()
1075 (equal (hydra--format
1077 '(nil nil :hint nil)
1079 '(("j" nil nil :exit t) ("k" nil nil :exit t)))
1080 '(concat (format "%s,%s"
1081 #("j" 0 1 (face hydra-face-blue))
1082 #("k" 0 1 (face hydra-face-blue))) ""))))
1084 (ert-deftest hydra-format-5 ()
1086 (equal (hydra--format
1087 nil nil "\n_-_: mark _u_: unmark\n"
1088 '(("-" Buffer-menu-mark)
1089 ("u" Buffer-menu-unmark)))
1092 "%s: mark %s: unmark\n"
1093 #("-" 0 1 (face hydra-face-red))
1094 #("u" 0 1 (face hydra-face-red)))
1097 (ert-deftest hydra-format-6 ()
1099 (equal (hydra--format
1100 nil nil "\n[_]_] forward [_[_] backward\n"
1101 '(("]" forward-char)
1102 ("[" backward-char)))
1105 "[%s] forward [%s] backward\n"
1114 (ert-deftest hydra-format-7 ()
1117 (hydra--format nil nil "test"
1118 '(("%" forward-char "" :exit nil)
1119 ("b" backward-char "" :exit nil)))
1122 6 7 (face hydra-face-red)
1123 7 8 (face hydra-face-red)
1124 8 9 (face hydra-face-red)
1125 9 10 (face hydra-face-red)
1126 12 13 (face hydra-face-red)))))
1129 (hydra--format nil nil "\n_%_ forward\n"
1130 '(("%" forward-char nil :exit nil)))
1135 0 2 (face hydra-face-red)))
1138 (ert-deftest hydra-format-with-sexp-1 ()
1140 (let ((hydra-fontify-head-function
1141 'hydra-fontify-head-greyscale))
1144 "\n_n_ narrow-or-widen-dwim %(progn (message \"checking\")(buffer-narrowed-p))asdf\n"
1145 '(("n" narrow-to-region nil) ("q" nil "cancel" :exit t))))
1146 '(concat (format "%s narrow-or-widen-dwim %Sasdf\n"
1149 (message "checking")
1150 (buffer-narrowed-p)))
1151 "[[q]]: cancel."))))
1153 (ert-deftest hydra-format-with-sexp-2 ()
1155 (let ((hydra-fontify-head-function
1156 'hydra-fontify-head-greyscale))
1159 "\n_n_ narrow-or-widen-dwim %s(progn (message \"checking\")(buffer-narrowed-p))asdf\n"
1160 '(("n" narrow-to-region nil) ("q" nil "cancel" :exit t))))
1161 '(concat (format "%s narrow-or-widen-dwim %sasdf\n"
1164 (message "checking")
1165 (buffer-narrowed-p)))
1166 "[[q]]: cancel."))))
1168 (ert-deftest hydra-compat-colors-2 ()
1172 '(defhydra hydra-test (:color amaranth)
1174 ("b" fun-b :color blue)
1175 ("c" fun-c :color blue)
1176 ("d" fun-d :color blue)
1177 ("e" fun-e :color blue)
1178 ("f" fun-f :color blue)))
1180 '(defhydra hydra-test (:color teal)
1181 ("a" fun-a :color red)
1188 (ert-deftest hydra-compat-colors-3 ()
1192 '(defhydra hydra-test ()
1194 ("b" fun-b :color blue)
1195 ("c" fun-c :color blue)
1196 ("d" fun-d :color blue)
1197 ("e" fun-e :color blue)
1198 ("f" fun-f :color blue)))
1200 '(defhydra hydra-test (:color blue)
1201 ("a" fun-a :color red)
1208 (ert-deftest hydra-compat-colors-4 ()
1212 '(defhydra hydra-test ()
1218 ("f" fun-f :exit t)))
1220 '(defhydra hydra-test (:exit t)
1221 ("a" fun-a :exit nil)
1228 (ert-deftest hydra--pad ()
1229 (should (equal (hydra--pad '(a b c) 3)
1231 (should (equal (hydra--pad '(a) 3)
1234 (ert-deftest hydra--matrix ()
1235 (should (equal (hydra--matrix '(a b c) 2 2)
1237 (should (equal (hydra--matrix '(a b c d e f g h i) 4 3)
1238 '((a b c d) (e f g h) (i nil nil nil)))))
1240 (ert-deftest hydra--cell ()
1241 (should (equal (hydra--cell "% -75s %%`%s" '(hydra-lv hydra-verbose))
1242 "When non-nil, `lv-message' (not `message') will be used to display hints. %`hydra-lv^^^^^
1243 When non-nil, hydra will issue some non essential style warnings. %`hydra-verbose")))
1245 (ert-deftest hydra--vconcat ()
1246 (should (equal (hydra--vconcat '("abc\ndef" "012\n34" "def\nabc"))
1247 "abc012def\ndef34abc")))
1249 (defhydradio hydra-tng ()
1250 (picard "_p_ Captain Jean Luc Picard:")
1251 (riker "_r_ Commander William Riker:")
1252 (data "_d_ Lieutenant Commander Data:")
1254 (la-forge "_f_ Geordi La Forge:")
1255 (troi "_t_ Deanna Troi:")
1256 (dr-crusher "_c_ Doctor Beverly Crusher:")
1257 (phaser "_h_ Set phasers to " [stun kill]))
1259 (ert-deftest hydra--table ()
1260 (let ((hydra-cell-format "% -30s %% -8`%s"))
1261 (should (equal (hydra--table hydra-tng/names 5 2)
1263 _p_ Captain Jean Luc Picard: % -8`hydra-tng/picard^^ _t_ Deanna Troi: % -8`hydra-tng/troi^^^^^^
1264 _r_ Commander William Riker: % -8`hydra-tng/riker^^^ _c_ Doctor Beverly Crusher: % -8`hydra-tng/dr-crusher
1265 _d_ Lieutenant Commander Data: % -8`hydra-tng/data^^^^ _h_ Set phasers to % -8`hydra-tng/phaser^^^^
1266 _w_ Worf: % -8`hydra-tng/worf^^^^
1267 _f_ Geordi La Forge: % -8`hydra-tng/la-forge" 1)))
1268 (should (equal (hydra--table hydra-tng/names 4 3)
1270 _p_ Captain Jean Luc Picard: % -8`hydra-tng/picard _f_ Geordi La Forge: % -8`hydra-tng/la-forge^^
1271 _r_ Commander William Riker: % -8`hydra-tng/riker^ _t_ Deanna Troi: % -8`hydra-tng/troi^^^^^^
1272 _d_ Lieutenant Commander Data: % -8`hydra-tng/data^^ _c_ Doctor Beverly Crusher: % -8`hydra-tng/dr-crusher
1273 _w_ Worf: % -8`hydra-tng/worf^^ _h_ Set phasers to % -8`hydra-tng/phaser^^^^" 1)))))
1275 (ert-deftest hydra--make-funcall ()
1276 (should (equal (let ((body-pre 'foo))
1277 (hydra--make-funcall body-pre)
1279 '(funcall (function foo)))))
1281 (defhydra hydra-simple-1 (global-map "C-c")
1286 (defhydra hydra-simple-2 (global-map "C-c" :color amaranth)
1287 ("c" self-insert-command)
1288 ("d" self-insert-command)
1291 (defhydra hydra-simple-3 (global-map "C-c")
1296 (defmacro hydra-with (in &rest body)
1297 `(let ((temp-buffer (generate-new-buffer " *temp*")))
1298 (save-window-excursion
1301 (switch-to-buffer temp-buffer)
1302 (transient-mark-mode 1)
1304 (goto-char (point-min))
1305 (when (search-forward "~" nil t)
1306 (backward-delete-char 1)
1308 (goto-char (point-max))
1309 (search-backward "|")
1311 (setq current-prefix-arg)
1314 (when (region-active-p)
1315 (exchange-point-and-mark)
1317 (buffer-substring-no-properties
1320 (and (buffer-name temp-buffer)
1321 (kill-buffer temp-buffer))))))
1323 (ert-deftest hydra-integration-1 ()
1324 (should (string= (hydra-with "|"
1326 (kbd "C-c aabbaaqaabbaa")))
1328 (should (string= (hydra-with "|"
1331 (kbd "C-c aabb C-g"))
1333 (execute-kbd-macro "aaqaabbaa"))
1336 (ert-deftest hydra-integration-2 ()
1337 (should (string= (hydra-with "|"
1339 (kbd "C-c c 1 c 2 d 4 c q")))
1341 (should (string= (hydra-with "|"
1343 (kbd "C-c c 1 c C-u d C-u 10 c q")))
1344 "ccddddcccccccccc|")))
1346 (ert-deftest hydra-integration-3 ()
1347 (should (string= (hydra-with "foo\nbar|"
1349 (kbd "C-c g 1 RET q")))
1352 (ert-deftest hydra-columns-1 ()
1353 (should (equal (eval
1358 '(defhydra hydra-info (:color blue
1361 ("?" Info-summary "summary")
1362 ("]" Info-forward-node "forward")
1363 ("[" Info-backward-node "backward")
1364 ("<" Info-top-node "top node")
1365 (">" Info-final-node "final node")
1366 ("h" Info-help "help")
1367 ("d" Info-directory "info dir")
1368 ("f" Info-follow-reference "follow ref")
1369 ("g" Info-goto-node "goto node")
1370 ("l" Info-history-back "hist back")
1371 ("r" Info-history-forward "hist forward")
1372 ("i" Info-index "index")
1373 ("I" Info-virtual-index "virtual index")
1374 ("L" Info-history "hist")
1375 ("n" Info-next "next")
1376 ("p" Info-prev "previous")
1377 ("s" Info-search "search")
1378 ("S" Info-search-case-sensitively "case-search")
1379 ("T" Info-toc "TOC")
1381 ("m" Info-menu "menu")
1382 ("t" hydra-info-to/body "info-to")))))))
1384 ?: summary ]: forward [: backward
1385 <: top node >: final node h: help
1386 d: info dir f: follow ref g: goto node
1387 l: hist back r: hist forward i: index
1388 I: virtual index L: hist n: next
1389 p: previous s: search S: case-search
1390 T: TOC u: up m: menu
1392 11 12 (face hydra-face-blue)
1393 28 29 (face hydra-face-blue)
1394 45 46 (face hydra-face-blue)
1395 57 58 (face hydra-face-blue)
1396 74 75 (face hydra-face-blue)
1397 91 92 (face hydra-face-blue)
1398 99 100 (face hydra-face-blue)
1399 116 117 (face hydra-face-blue)
1400 133 134 (face hydra-face-blue)
1401 146 147 (face hydra-face-blue)
1402 163 164 (face hydra-face-blue)
1403 180 181 (face hydra-face-blue)
1404 189 190 (face hydra-face-blue)
1405 206 207 (face hydra-face-blue)
1406 223 224 (face hydra-face-blue)
1407 231 232 (face hydra-face-blue)
1408 248 249 (face hydra-face-blue)
1409 265 266 (face hydra-face-blue)
1410 280 281 (face hydra-face-blue)
1411 297 298 (face hydra-face-blue)
1412 314 315 (face hydra-face-blue)
1413 322 323 (face hydra-face-blue)))))
1415 (provide 'hydra-test)
1417 ;;; hydra-test.el ends here