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/>.
29 (setq text-quoting-style 'grave)
30 (message "Emacs version: %s" emacs-version)
32 (ert-deftest hydra-red-error ()
36 '(defhydra hydra-error (global-map "M-g")
38 ("h" first-error "first")
39 ("j" next-error "next")
40 ("k" previous-error "prev")
41 ("SPC" hydra-repeat "rep" :bind nil)))
44 (defvar hydra-error/keymap nil
45 "Keymap for hydra-error.")
49 (107 . hydra-error/previous-error)
50 (106 . hydra-error/next-error)
51 (104 . hydra-error/first-error)
52 (kp-subtract . hydra--negative-argument)
53 (kp-9 . hydra--digit-argument)
54 (kp-8 . hydra--digit-argument)
55 (kp-7 . hydra--digit-argument)
56 (kp-6 . hydra--digit-argument)
57 (kp-5 . hydra--digit-argument)
58 (kp-4 . hydra--digit-argument)
59 (kp-3 . hydra--digit-argument)
60 (kp-2 . hydra--digit-argument)
61 (kp-1 . hydra--digit-argument)
62 (kp-0 . hydra--digit-argument)
63 (57 . hydra--digit-argument)
64 (56 . hydra--digit-argument)
65 (55 . hydra--digit-argument)
66 (54 . hydra--digit-argument)
67 (53 . hydra--digit-argument)
68 (52 . hydra--digit-argument)
69 (51 . hydra--digit-argument)
70 (50 . hydra--digit-argument)
71 (49 . hydra--digit-argument)
72 (48 . hydra--digit-argument)
73 (45 . hydra--negative-argument)
74 (21 . hydra--universal-argument))))
76 (defvar hydra-error/heads nil
77 "Heads for hydra-error.")
97 (defvar hydra-error/hint nil
98 "Dynamic hint for hydra-error.")
101 #("error: [h]: first, [j]: next, [k]: prev, [SPC]: rep."
102 8 9 (face hydra-face-red)
103 20 21 (face hydra-face-red)
104 31 32 (face hydra-face-red)
105 42 45 (face hydra-face-red)))))
106 (defun hydra-error/first-error nil
107 "Create a hydra with a \"M-g\" body and the heads:
109 \"h\": `first-error',
111 \"k\": `previous-error',
112 \"SPC\": `hydra-repeat'
114 The body can be accessed via `hydra-error/body'.
116 Call the head: `first-error'."
119 (let ((hydra--ignore t))
120 (hydra-keyboard-quit)
121 (setq hydra-curr-body-fn
122 (quote hydra-error/body)))
128 (function first-error)))
131 (unless hydra-lv (sit-for 0.8))))
132 (when hydra-is-helpful
135 (eval hydra-error/hint))
137 (eval hydra-error/hint))))
138 (hydra-set-transient-map
141 (hydra-keyboard-quit)
144 (defun hydra-error/next-error nil
145 "Create a hydra with a \"M-g\" body and the heads:
147 \"h\": `first-error',
149 \"k\": `previous-error',
150 \"SPC\": `hydra-repeat'
152 The body can be accessed via `hydra-error/body'.
154 Call the head: `next-error'."
157 (let ((hydra--ignore t))
158 (hydra-keyboard-quit)
159 (setq hydra-curr-body-fn
160 (quote hydra-error/body)))
166 (function next-error)))
169 (unless hydra-lv (sit-for 0.8))))
170 (when hydra-is-helpful
173 (eval hydra-error/hint))
175 (eval hydra-error/hint))))
176 (hydra-set-transient-map
179 (hydra-keyboard-quit)
182 (defun hydra-error/previous-error nil
183 "Create a hydra with a \"M-g\" body and the heads:
185 \"h\": `first-error',
187 \"k\": `previous-error',
188 \"SPC\": `hydra-repeat'
190 The body can be accessed via `hydra-error/body'.
192 Call the head: `previous-error'."
195 (let ((hydra--ignore t))
196 (hydra-keyboard-quit)
197 (setq hydra-curr-body-fn
198 (quote hydra-error/body)))
202 (quote previous-error))
204 (function previous-error)))
207 (unless hydra-lv (sit-for 0.8))))
208 (when hydra-is-helpful
211 (eval hydra-error/hint))
213 (eval hydra-error/hint))))
214 (hydra-set-transient-map
217 (hydra-keyboard-quit)
224 (define-key global-map (kbd "M-g")
226 (define-key global-map [134217831 104]
227 (quote hydra-error/first-error))
228 (define-key global-map [134217831 106]
229 (quote hydra-error/next-error))
230 (define-key global-map [134217831 107]
232 hydra-error/previous-error))
233 (defun hydra-error/body nil
234 "Create a hydra with a \"M-g\" body and the heads:
236 \"h\": `first-error',
238 \"k\": `previous-error',
239 \"SPC\": `hydra-repeat'
241 The body can be accessed via `hydra-error/body'."
244 (let ((hydra--ignore nil))
245 (hydra-keyboard-quit)
246 (setq hydra-curr-body-fn
247 (quote hydra-error/body)))
248 (when hydra-is-helpful
251 (eval hydra-error/hint))
253 (eval hydra-error/hint))))
254 (hydra-set-transient-map
257 (hydra-keyboard-quit)
261 current-prefix-arg))))))
263 (ert-deftest hydra-blue-toggle ()
267 '(defhydra hydra-toggle (:color blue)
269 ("t" toggle-truncate-lines "truncate")
270 ("f" auto-fill-mode "fill")
271 ("a" abbrev-mode "abbrev")
275 (defvar hydra-toggle/keymap nil
276 "Keymap for hydra-toggle.")
279 (113 . hydra-toggle/nil)
280 (97 . hydra-toggle/abbrev-mode-and-exit)
281 (102 . hydra-toggle/auto-fill-mode-and-exit)
282 (116 . hydra-toggle/toggle-truncate-lines-and-exit)
283 (kp-subtract . hydra--negative-argument)
284 (kp-9 . hydra--digit-argument)
285 (kp-8 . hydra--digit-argument)
286 (kp-7 . hydra--digit-argument)
287 (kp-6 . hydra--digit-argument)
288 (kp-5 . hydra--digit-argument)
289 (kp-4 . hydra--digit-argument)
290 (kp-3 . hydra--digit-argument)
291 (kp-2 . hydra--digit-argument)
292 (kp-1 . hydra--digit-argument)
293 (kp-0 . hydra--digit-argument)
294 (57 . hydra--digit-argument)
295 (56 . hydra--digit-argument)
296 (55 . hydra--digit-argument)
297 (54 . hydra--digit-argument)
298 (53 . hydra--digit-argument)
299 (52 . hydra--digit-argument)
300 (51 . hydra--digit-argument)
301 (50 . hydra--digit-argument)
302 (49 . hydra--digit-argument)
303 (48 . hydra--digit-argument)
304 (45 . hydra--negative-argument)
305 (21 . hydra--universal-argument))))
307 (defvar hydra-toggle/heads nil
308 "Heads for hydra-toggle.")
311 toggle-truncate-lines
322 ("q" nil "cancel" :exit t))))
324 (defvar hydra-toggle/hint nil
325 "Dynamic hint for hydra-toggle.")
328 #("toggle: [t]: truncate, [f]: fill, [a]: abbrev, [q]: cancel."
329 9 10 (face hydra-face-blue)
330 24 25 (face hydra-face-blue)
331 35 36 (face hydra-face-blue)
332 48 49 (face hydra-face-blue)))))
333 (defun hydra-toggle/toggle-truncate-lines-and-exit nil
334 "Create a hydra with no body and the heads:
336 \"t\": `toggle-truncate-lines',
337 \"f\": `auto-fill-mode',
338 \"a\": `abbrev-mode',
341 The body can be accessed via `hydra-toggle/body'.
343 Call the head: `toggle-truncate-lines'."
346 (hydra-keyboard-quit)
347 (setq hydra-curr-body-fn
348 (quote hydra-toggle/body))
351 (quote toggle-truncate-lines))
354 toggle-truncate-lines))))
355 (defun hydra-toggle/auto-fill-mode-and-exit nil
356 "Create a hydra with no body and the heads:
358 \"t\": `toggle-truncate-lines',
359 \"f\": `auto-fill-mode',
360 \"a\": `abbrev-mode',
363 The body can be accessed via `hydra-toggle/body'.
365 Call the head: `auto-fill-mode'."
368 (hydra-keyboard-quit)
369 (setq hydra-curr-body-fn
370 (quote hydra-toggle/body))
373 (quote auto-fill-mode))
375 (function auto-fill-mode))))
376 (defun hydra-toggle/abbrev-mode-and-exit nil
377 "Create a hydra with no body and the heads:
379 \"t\": `toggle-truncate-lines',
380 \"f\": `auto-fill-mode',
381 \"a\": `abbrev-mode',
384 The body can be accessed via `hydra-toggle/body'.
386 Call the head: `abbrev-mode'."
389 (hydra-keyboard-quit)
390 (setq hydra-curr-body-fn
391 (quote hydra-toggle/body))
396 (function abbrev-mode))))
397 (defun hydra-toggle/nil nil
398 "Create a hydra with no body and the heads:
400 \"t\": `toggle-truncate-lines',
401 \"f\": `auto-fill-mode',
402 \"a\": `abbrev-mode',
405 The body can be accessed via `hydra-toggle/body'.
407 Call the head: `nil'."
410 (hydra-keyboard-quit)
411 (setq hydra-curr-body-fn
412 (quote hydra-toggle/body)))
413 (defun hydra-toggle/body nil
414 "Create a hydra with no body and the heads:
416 \"t\": `toggle-truncate-lines',
417 \"f\": `auto-fill-mode',
418 \"a\": `abbrev-mode',
421 The body can be accessed via `hydra-toggle/body'."
424 (let ((hydra--ignore nil))
425 (hydra-keyboard-quit)
426 (setq hydra-curr-body-fn
427 (quote hydra-toggle/body)))
428 (when hydra-is-helpful
431 (eval hydra-toggle/hint))
433 (eval hydra-toggle/hint))))
434 (hydra-set-transient-map
437 (hydra-keyboard-quit)
441 current-prefix-arg))))))
443 (ert-deftest hydra-amaranth-vi ()
449 (set-cursor-color "#e52b50")
451 (set-cursor-color "#ffffff")
459 (defvar hydra-vi/keymap nil
460 "Keymap for hydra-vi.")
464 (107 . hydra-vi/previous-line)
465 (106 . hydra-vi/next-line)
466 (kp-subtract . hydra--negative-argument)
467 (kp-9 . hydra--digit-argument)
468 (kp-8 . hydra--digit-argument)
469 (kp-7 . hydra--digit-argument)
470 (kp-6 . hydra--digit-argument)
471 (kp-5 . hydra--digit-argument)
472 (kp-4 . hydra--digit-argument)
473 (kp-3 . hydra--digit-argument)
474 (kp-2 . hydra--digit-argument)
475 (kp-1 . hydra--digit-argument)
476 (kp-0 . hydra--digit-argument)
477 (57 . hydra--digit-argument)
478 (56 . hydra--digit-argument)
479 (55 . hydra--digit-argument)
480 (54 . hydra--digit-argument)
481 (53 . hydra--digit-argument)
482 (52 . hydra--digit-argument)
483 (51 . hydra--digit-argument)
484 (50 . hydra--digit-argument)
485 (49 . hydra--digit-argument)
486 (48 . hydra--digit-argument)
487 (45 . hydra--negative-argument)
488 (21 . hydra--universal-argument))))
490 (defvar hydra-vi/heads nil
491 "Heads for hydra-vi.")
493 (("j" next-line "" :exit nil)
498 ("q" nil "quit" :exit t))))
500 (defvar hydra-vi/hint nil
501 "Dynamic hint for hydra-vi.")
504 #("vi: j, k, [q]: quit."
505 4 5 (face hydra-face-amaranth)
506 7 8 (face hydra-face-amaranth)
507 11 12 (face hydra-face-teal)))))
508 (defun hydra-vi/next-line nil
509 "Create a hydra with no body and the heads:
512 \"k\": `previous-line',
515 The body can be accessed via `hydra-vi/body'.
517 Call the head: `next-line'."
520 (set-cursor-color "#e52b50")
521 (let ((hydra--ignore t))
522 (hydra-keyboard-quit)
523 (setq hydra-curr-body-fn
524 (quote hydra-vi/body)))
530 (function next-line)))
533 (unless hydra-lv (sit-for 0.8))))
534 (when hydra-is-helpful
537 (eval hydra-vi/hint))
538 (message (eval hydra-vi/hint))))
539 (hydra-set-transient-map
542 (hydra-keyboard-quit)
543 (set-cursor-color "#ffffff"))
545 (defun hydra-vi/previous-line nil
546 "Create a hydra with no body and the heads:
549 \"k\": `previous-line',
552 The body can be accessed via `hydra-vi/body'.
554 Call the head: `previous-line'."
557 (set-cursor-color "#e52b50")
558 (let ((hydra--ignore t))
559 (hydra-keyboard-quit)
560 (setq hydra-curr-body-fn
561 (quote hydra-vi/body)))
565 (quote previous-line))
567 (function previous-line)))
570 (unless hydra-lv (sit-for 0.8))))
571 (when hydra-is-helpful
574 (eval hydra-vi/hint))
575 (message (eval hydra-vi/hint))))
576 (hydra-set-transient-map
579 (hydra-keyboard-quit)
580 (set-cursor-color "#ffffff"))
582 (defun hydra-vi/nil nil
583 "Create a hydra with no body and the heads:
586 \"k\": `previous-line',
589 The body can be accessed via `hydra-vi/body'.
591 Call the head: `nil'."
594 (set-cursor-color "#e52b50")
595 (hydra-keyboard-quit)
596 (setq hydra-curr-body-fn
597 (quote hydra-vi/body)))
598 (defun hydra-vi/body nil
599 "Create a hydra with no body and the heads:
602 \"k\": `previous-line',
605 The body can be accessed via `hydra-vi/body'."
608 (set-cursor-color "#e52b50")
609 (let ((hydra--ignore nil))
610 (hydra-keyboard-quit)
611 (setq hydra-curr-body-fn
612 (quote hydra-vi/body)))
613 (when hydra-is-helpful
616 (eval hydra-vi/hint))
617 (message (eval hydra-vi/hint))))
618 (hydra-set-transient-map
621 (hydra-keyboard-quit)
622 (set-cursor-color "#ffffff"))
625 current-prefix-arg))))))
627 (ert-deftest hydra-zoom-duplicate-1 ()
631 '(defhydra hydra-zoom ()
633 ("r" (text-scale-set 0) "reset")
634 ("0" (text-scale-set 0) :bind nil :exit t)
635 ("1" (text-scale-set 0) nil :bind nil :exit t)))
638 (defvar hydra-zoom/keymap nil
639 "Keymap for hydra-zoom.")
642 (114 . hydra-zoom/lambda-r)
643 (kp-subtract . hydra--negative-argument)
644 (kp-9 . hydra--digit-argument)
645 (kp-8 . hydra--digit-argument)
646 (kp-7 . hydra--digit-argument)
647 (kp-6 . hydra--digit-argument)
648 (kp-5 . hydra--digit-argument)
649 (kp-4 . hydra--digit-argument)
650 (kp-3 . hydra--digit-argument)
651 (kp-2 . hydra--digit-argument)
652 (kp-1 . hydra--digit-argument)
653 (kp-0 . hydra--digit-argument)
654 (57 . hydra--digit-argument)
655 (56 . hydra--digit-argument)
656 (55 . hydra--digit-argument)
657 (54 . hydra--digit-argument)
658 (53 . hydra--digit-argument)
659 (52 . hydra--digit-argument)
660 (51 . hydra--digit-argument)
661 (50 . hydra--digit-argument)
662 (49 . hydra-zoom/lambda-0-and-exit)
663 (48 . hydra-zoom/lambda-0-and-exit)
664 (45 . hydra--negative-argument)
665 (21 . hydra--universal-argument))))
667 (defvar hydra-zoom/heads nil
668 "Heads for hydra-zoom.")
685 (defvar hydra-zoom/hint nil
686 "Dynamic hint for hydra-zoom.")
689 #("zoom: [r 0]: reset."
690 7 8 (face hydra-face-red)
691 9 10 (face hydra-face-blue)))))
692 (defun hydra-zoom/lambda-r nil
693 "Create a hydra with no body and the heads:
695 \"r\": `(text-scale-set 0)',
696 \"0\": `(text-scale-set 0)',
697 \"1\": `(text-scale-set 0)'
699 The body can be accessed via `hydra-zoom/body'.
701 Call the head: `(text-scale-set 0)'."
704 (let ((hydra--ignore t))
705 (hydra-keyboard-quit)
706 (setq hydra-curr-body-fn
707 (quote hydra-zoom/body)))
713 (text-scale-set 0))))
716 (unless hydra-lv (sit-for 0.8))))
717 (when hydra-is-helpful
720 (eval hydra-zoom/hint))
722 (eval hydra-zoom/hint))))
723 (hydra-set-transient-map
726 (hydra-keyboard-quit)
729 (defun hydra-zoom/lambda-0-and-exit nil
730 "Create a hydra with no body and the heads:
732 \"r\": `(text-scale-set 0)',
733 \"0\": `(text-scale-set 0)',
734 \"1\": `(text-scale-set 0)'
736 The body can be accessed via `hydra-zoom/body'.
738 Call the head: `(text-scale-set 0)'."
741 (hydra-keyboard-quit)
742 (setq hydra-curr-body-fn
743 (quote hydra-zoom/body))
748 (text-scale-set 0)))))
749 (defun hydra-zoom/body nil
750 "Create a hydra with no body and the heads:
752 \"r\": `(text-scale-set 0)',
753 \"0\": `(text-scale-set 0)',
754 \"1\": `(text-scale-set 0)'
756 The body can be accessed via `hydra-zoom/body'."
759 (let ((hydra--ignore nil))
760 (hydra-keyboard-quit)
761 (setq hydra-curr-body-fn
762 (quote hydra-zoom/body)))
763 (when hydra-is-helpful
766 (eval hydra-zoom/hint))
768 (eval hydra-zoom/hint))))
769 (hydra-set-transient-map
772 (hydra-keyboard-quit)
776 current-prefix-arg))))))
778 (ert-deftest hydra-zoom-duplicate-2 ()
782 '(defhydra hydra-zoom ()
784 ("r" (text-scale-set 0) "reset")
785 ("0" (text-scale-set 0) :bind nil :exit t)
786 ("1" (text-scale-set 0) nil :bind nil)))
789 (defvar hydra-zoom/keymap nil
790 "Keymap for hydra-zoom.")
793 (114 . hydra-zoom/lambda-r)
794 (kp-subtract . hydra--negative-argument)
795 (kp-9 . hydra--digit-argument)
796 (kp-8 . hydra--digit-argument)
797 (kp-7 . hydra--digit-argument)
798 (kp-6 . hydra--digit-argument)
799 (kp-5 . hydra--digit-argument)
800 (kp-4 . hydra--digit-argument)
801 (kp-3 . hydra--digit-argument)
802 (kp-2 . hydra--digit-argument)
803 (kp-1 . hydra--digit-argument)
804 (kp-0 . hydra--digit-argument)
805 (57 . hydra--digit-argument)
806 (56 . hydra--digit-argument)
807 (55 . hydra--digit-argument)
808 (54 . hydra--digit-argument)
809 (53 . hydra--digit-argument)
810 (52 . hydra--digit-argument)
811 (51 . hydra--digit-argument)
812 (50 . hydra--digit-argument)
813 (49 . hydra-zoom/lambda-r)
814 (48 . hydra-zoom/lambda-0-and-exit)
815 (45 . hydra--negative-argument)
816 (21 . hydra--universal-argument))))
818 (defvar hydra-zoom/heads nil
819 "Heads for hydra-zoom.")
836 (defvar hydra-zoom/hint nil
837 "Dynamic hint for hydra-zoom.")
840 #("zoom: [r 0]: reset."
841 7 8 (face hydra-face-red)
842 9 10 (face hydra-face-blue)))))
843 (defun hydra-zoom/lambda-r nil
844 "Create a hydra with no body and the heads:
846 \"r\": `(text-scale-set 0)',
847 \"0\": `(text-scale-set 0)',
848 \"1\": `(text-scale-set 0)'
850 The body can be accessed via `hydra-zoom/body'.
852 Call the head: `(text-scale-set 0)'."
855 (let ((hydra--ignore t))
856 (hydra-keyboard-quit)
857 (setq hydra-curr-body-fn
858 (quote hydra-zoom/body)))
864 (text-scale-set 0))))
867 (unless hydra-lv (sit-for 0.8))))
868 (when hydra-is-helpful
871 (eval hydra-zoom/hint))
873 (eval hydra-zoom/hint))))
874 (hydra-set-transient-map
877 (hydra-keyboard-quit)
880 (defun hydra-zoom/lambda-0-and-exit nil
881 "Create a hydra with no body and the heads:
883 \"r\": `(text-scale-set 0)',
884 \"0\": `(text-scale-set 0)',
885 \"1\": `(text-scale-set 0)'
887 The body can be accessed via `hydra-zoom/body'.
889 Call the head: `(text-scale-set 0)'."
892 (hydra-keyboard-quit)
893 (setq hydra-curr-body-fn
894 (quote hydra-zoom/body))
899 (text-scale-set 0)))))
900 (defun hydra-zoom/body nil
901 "Create a hydra with no body and the heads:
903 \"r\": `(text-scale-set 0)',
904 \"0\": `(text-scale-set 0)',
905 \"1\": `(text-scale-set 0)'
907 The body can be accessed via `hydra-zoom/body'."
910 (let ((hydra--ignore nil))
911 (hydra-keyboard-quit)
912 (setq hydra-curr-body-fn
913 (quote hydra-zoom/body)))
914 (when hydra-is-helpful
917 (eval hydra-zoom/hint))
919 (eval hydra-zoom/hint))))
920 (hydra-set-transient-map
923 (hydra-keyboard-quit)
927 current-prefix-arg))))))
929 (ert-deftest defhydradio ()
932 '(defhydradio hydra-test ()
933 (num "Num" [0 1 2 3 4 5 6 7 8 9 10])
934 (str "Str" ["foo" "bar" "baz"])))
936 (defvar hydra-test/num 0
938 (put 'hydra-test/num 'range [0 1 2 3 4 5 6 7 8 9 10])
939 (defun hydra-test/num ()
940 (hydra--cycle-radio 'hydra-test/num))
941 (defvar hydra-test/str "foo"
943 (put 'hydra-test/str 'range ["foo" "bar" "baz"])
944 (defun hydra-test/str ()
945 (hydra--cycle-radio 'hydra-test/str))
946 (defvar hydra-test/names '(hydra-test/num hydra-test/str))))))
948 (ert-deftest hydra-blue-compat ()
952 '(defhydra hydra-toggle (:color blue)
954 ("t" toggle-truncate-lines "truncate")
955 ("f" auto-fill-mode "fill")
956 ("a" abbrev-mode "abbrev")
959 '(defhydra hydra-toggle (:exit t)
961 ("t" toggle-truncate-lines "truncate")
962 ("f" auto-fill-mode "fill")
963 ("a" abbrev-mode "abbrev")
964 ("q" nil "cancel"))))))
966 (ert-deftest hydra-amaranth-compat ()
972 (set-cursor-color "#e52b50")
974 (set-cursor-color "#ffffff")
983 (set-cursor-color "#e52b50")
985 (set-cursor-color "#ffffff")
990 ("q" nil "quit"))))))
992 (ert-deftest hydra-pink-compat ()
996 '(defhydra hydra-zoom (global-map "<f2>"
999 ("g" text-scale-increase "in")
1000 ("l" text-scale-decrease "out")
1003 '(defhydra hydra-zoom (global-map "<f2>"
1006 ("g" text-scale-increase "in")
1007 ("l" text-scale-decrease "out")
1008 ("q" nil "quit"))))))
1010 (ert-deftest hydra-teal-compat ()
1014 '(defhydra hydra-zoom (global-map "<f2>"
1017 ("g" text-scale-increase "in")
1018 ("l" text-scale-decrease "out")
1021 '(defhydra hydra-zoom (global-map "<f2>"
1025 ("g" text-scale-increase "in")
1026 ("l" text-scale-decrease "out")
1027 ("q" nil "quit"))))))
1029 (ert-deftest hydra-format-1 ()
1031 (let ((hydra-fontify-head-function
1032 'hydra-fontify-head-greyscale))
1037 _a_ abbrev-mode: %`abbrev-mode
1038 _d_ debug-on-error: %`debug-on-error
1039 _f_ auto-fill-mode: %`auto-fill-function
1040 " '(("a" abbrev-mode nil)
1041 ("d" toggle-debug-on-error nil)
1042 ("f" auto-fill-mode nil)
1043 ("g" golden-ratio-mode nil)
1044 ("t" toggle-truncate-lines nil)
1045 ("w" whitespace-mode nil)
1047 '(concat (format "%s abbrev-mode: %S
1048 %s debug-on-error: %S
1049 %s auto-fill-mode: %S
1050 " "{a}" abbrev-mode "{d}" debug-on-error "{f}" auto-fill-function) "[{q}]: quit."))))
1052 (ert-deftest hydra-format-2 ()
1054 (let ((hydra-fontify-head-function
1055 'hydra-fontify-head-greyscale))
1060 '(("a" (quote t) "" :cmd-name bar/lambda-a :exit nil)
1061 ("q" nil "" :cmd-name bar/nil :exit t))))
1062 '(concat (format " bar %s\n" foo) "{a}, [q]."))))
1064 (ert-deftest hydra-format-3 ()
1066 (let ((hydra-fontify-head-function
1067 'hydra-fontify-head-greyscale))
1071 "\n_<SPC>_ ^^ace jump\n"
1072 '(("<SPC>" ace-jump-char-mode nil :cmd-name bar/ace-jump-char-mode))))
1073 '(concat (format "%s ace jump\n" "{<SPC>}") ""))))
1075 (ert-deftest hydra-format-4 ()
1077 (equal (hydra--format
1079 '(nil nil :hint nil)
1081 '(("j" nil nil :exit t) ("k" nil nil :exit t)))
1082 '(concat (format "%s,%s"
1083 #("j" 0 1 (face hydra-face-blue))
1084 #("k" 0 1 (face hydra-face-blue))) ""))))
1086 (ert-deftest hydra-format-5 ()
1088 (equal (hydra--format
1089 nil nil "\n_-_: mark _u_: unmark\n"
1090 '(("-" Buffer-menu-mark)
1091 ("u" Buffer-menu-unmark)))
1094 "%s: mark %s: unmark\n"
1095 #("-" 0 1 (face hydra-face-red))
1096 #("u" 0 1 (face hydra-face-red)))
1099 (ert-deftest hydra-format-6 ()
1101 (equal (hydra--format
1102 nil nil "\n[_]_] forward [_[_] backward\n"
1103 '(("]" forward-char)
1104 ("[" backward-char)))
1107 "[%s] forward [%s] backward\n"
1116 (ert-deftest hydra-format-7 ()
1119 (hydra--format nil nil "test"
1120 '(("%" forward-char "" :exit nil)
1121 ("b" backward-char "" :exit nil)))
1124 6 7 (face hydra-face-red)
1125 7 8 (face hydra-face-red)
1126 8 9 (face hydra-face-red)
1127 9 10 (face hydra-face-red)
1128 12 13 (face hydra-face-red)))))
1131 (hydra--format nil nil "\n_%_ forward\n"
1132 '(("%" forward-char nil :exit nil)))
1137 0 2 (face hydra-face-red)))
1140 (ert-deftest hydra-format-with-sexp-1 ()
1142 (let ((hydra-fontify-head-function
1143 'hydra-fontify-head-greyscale))
1146 "\n_n_ narrow-or-widen-dwim %(progn (message \"checking\")(buffer-narrowed-p))asdf\n"
1147 '(("n" narrow-to-region nil) ("q" nil "cancel" :exit t))))
1148 '(concat (format "%s narrow-or-widen-dwim %Sasdf\n"
1151 (message "checking")
1152 (buffer-narrowed-p)))
1153 "[[q]]: cancel."))))
1155 (ert-deftest hydra-format-with-sexp-2 ()
1157 (let ((hydra-fontify-head-function
1158 'hydra-fontify-head-greyscale))
1161 "\n_n_ narrow-or-widen-dwim %s(progn (message \"checking\")(buffer-narrowed-p))asdf\n"
1162 '(("n" narrow-to-region nil) ("q" nil "cancel" :exit t))))
1163 '(concat (format "%s narrow-or-widen-dwim %sasdf\n"
1166 (message "checking")
1167 (buffer-narrowed-p)))
1168 "[[q]]: cancel."))))
1170 (ert-deftest hydra-compat-colors-2 ()
1174 '(defhydra hydra-test (:color amaranth)
1176 ("b" fun-b :color blue)
1177 ("c" fun-c :color blue)
1178 ("d" fun-d :color blue)
1179 ("e" fun-e :color blue)
1180 ("f" fun-f :color blue)))
1182 '(defhydra hydra-test (:color teal)
1183 ("a" fun-a :color red)
1190 (ert-deftest hydra-compat-colors-3 ()
1194 '(defhydra hydra-test ()
1196 ("b" fun-b :color blue)
1197 ("c" fun-c :color blue)
1198 ("d" fun-d :color blue)
1199 ("e" fun-e :color blue)
1200 ("f" fun-f :color blue)))
1202 '(defhydra hydra-test (:color blue)
1203 ("a" fun-a :color red)
1210 (ert-deftest hydra-compat-colors-4 ()
1214 '(defhydra hydra-test ()
1220 ("f" fun-f :exit t)))
1222 '(defhydra hydra-test (:exit t)
1223 ("a" fun-a :exit nil)
1230 (ert-deftest hydra--pad ()
1231 (should (equal (hydra--pad '(a b c) 3)
1233 (should (equal (hydra--pad '(a) 3)
1236 (ert-deftest hydra--matrix ()
1237 (should (equal (hydra--matrix '(a b c) 2 2)
1239 (should (equal (hydra--matrix '(a b c d e f g h i) 4 3)
1240 '((a b c d) (e f g h) (i nil nil nil)))))
1242 (ert-deftest hydra--cell ()
1243 (should (equal (hydra--cell "% -75s %%`%s" '(hydra-lv hydra-verbose))
1244 "When non-nil, `lv-message' (not `message') will be used to display hints. %`hydra-lv^^^^^
1245 When non-nil, hydra will issue some non essential style warnings. %`hydra-verbose")))
1247 (ert-deftest hydra--vconcat ()
1248 (should (equal (hydra--vconcat '("abc\ndef" "012\n34" "def\nabc"))
1249 "abc012def\ndef34abc")))
1251 (defhydradio hydra-tng ()
1252 (picard "_p_ Captain Jean Luc Picard:")
1253 (riker "_r_ Commander William Riker:")
1254 (data "_d_ Lieutenant Commander Data:")
1256 (la-forge "_f_ Geordi La Forge:")
1257 (troi "_t_ Deanna Troi:")
1258 (dr-crusher "_c_ Doctor Beverly Crusher:")
1259 (phaser "_h_ Set phasers to " [stun kill]))
1261 (ert-deftest hydra--table ()
1262 (let ((hydra-cell-format "% -30s %% -8`%s"))
1263 (should (equal (hydra--table hydra-tng/names 5 2)
1265 _p_ Captain Jean Luc Picard: % -8`hydra-tng/picard^^ _t_ Deanna Troi: % -8`hydra-tng/troi^^^^^^
1266 _r_ Commander William Riker: % -8`hydra-tng/riker^^^ _c_ Doctor Beverly Crusher: % -8`hydra-tng/dr-crusher
1267 _d_ Lieutenant Commander Data: % -8`hydra-tng/data^^^^ _h_ Set phasers to % -8`hydra-tng/phaser^^^^
1268 _w_ Worf: % -8`hydra-tng/worf^^^^
1269 _f_ Geordi La Forge: % -8`hydra-tng/la-forge" 1)))
1270 (should (equal (hydra--table hydra-tng/names 4 3)
1272 _p_ Captain Jean Luc Picard: % -8`hydra-tng/picard _f_ Geordi La Forge: % -8`hydra-tng/la-forge^^
1273 _r_ Commander William Riker: % -8`hydra-tng/riker^ _t_ Deanna Troi: % -8`hydra-tng/troi^^^^^^
1274 _d_ Lieutenant Commander Data: % -8`hydra-tng/data^^ _c_ Doctor Beverly Crusher: % -8`hydra-tng/dr-crusher
1275 _w_ Worf: % -8`hydra-tng/worf^^ _h_ Set phasers to % -8`hydra-tng/phaser^^^^" 1)))))
1277 (ert-deftest hydra--make-funcall ()
1278 (should (equal (let ((body-pre 'foo))
1279 (hydra--make-funcall body-pre)
1281 '(funcall (function foo)))))
1283 (defhydra hydra-simple-1 (global-map "C-c")
1288 (defhydra hydra-simple-2 (global-map "C-c" :color amaranth)
1289 ("c" self-insert-command)
1290 ("d" self-insert-command)
1293 (defhydra hydra-simple-3 (global-map "C-c")
1298 (defmacro hydra-with (in &rest body)
1299 `(let ((temp-buffer (generate-new-buffer " *temp*")))
1300 (save-window-excursion
1303 (switch-to-buffer temp-buffer)
1304 (transient-mark-mode 1)
1306 (goto-char (point-min))
1307 (when (search-forward "~" nil t)
1308 (backward-delete-char 1)
1310 (goto-char (point-max))
1311 (search-backward "|")
1313 (setq current-prefix-arg nil)
1316 (when (region-active-p)
1317 (exchange-point-and-mark)
1319 (buffer-substring-no-properties
1322 (and (buffer-name temp-buffer)
1323 (kill-buffer temp-buffer))))))
1325 (ert-deftest hydra-integration-1 ()
1326 (should (string= (hydra-with "|"
1328 (kbd "C-c aabbaaqaabbaa")))
1330 (should (string= (hydra-with "|"
1333 (kbd "C-c aabb C-g"))
1335 (execute-kbd-macro "aaqaabbaa"))
1338 (ert-deftest hydra-integration-2 ()
1339 (should (string= (hydra-with "|"
1341 (kbd "C-c c 1 c 2 d 4 c q")))
1343 (should (string= (hydra-with "|"
1345 (kbd "C-c c 1 c C-u d C-u 10 c q")))
1346 "ccddddcccccccccc|")))
1348 (ert-deftest hydra-integration-3 ()
1349 (should (string= (hydra-with "foo\nbar|"
1351 (kbd "C-c g 1 RET q")))
1354 (ert-deftest hydra-columns-1 ()
1355 (should (equal (eval
1360 '(defhydra hydra-info (:color blue
1363 ("?" Info-summary "summary")
1364 ("]" Info-forward-node "forward")
1365 ("[" Info-backward-node "backward")
1366 ("<" Info-top-node "top node")
1367 (">" Info-final-node "final node")
1368 ("h" Info-help "help")
1369 ("d" Info-directory "info dir")
1370 ("f" Info-follow-reference "follow ref")
1371 ("g" Info-goto-node "goto node")
1372 ("l" Info-history-back "hist back")
1373 ("r" Info-history-forward "hist forward")
1374 ("i" Info-index "index")
1375 ("I" Info-virtual-index "virtual index")
1376 ("L" Info-history "hist")
1377 ("n" Info-next "next")
1378 ("p" Info-prev "previous")
1379 ("s" Info-search "search")
1380 ("S" Info-search-case-sensitively "case-search")
1381 ("T" Info-toc "TOC")
1383 ("m" Info-menu "menu")
1384 ("t" hydra-info-to/body "info-to")))))))
1386 ?: summary ]: forward [: backward
1387 <: top node >: final node h: help
1388 d: info dir f: follow ref g: goto node
1389 l: hist back r: hist forward i: index
1390 I: virtual index L: hist n: next
1391 p: previous s: search S: case-search
1392 T: TOC u: up m: menu
1394 11 12 (face hydra-face-blue)
1395 28 29 (face hydra-face-blue)
1396 45 46 (face hydra-face-blue)
1397 57 58 (face hydra-face-blue)
1398 74 75 (face hydra-face-blue)
1399 91 92 (face hydra-face-blue)
1400 99 100 (face hydra-face-blue)
1401 116 117 (face hydra-face-blue)
1402 133 134 (face hydra-face-blue)
1403 146 147 (face hydra-face-blue)
1404 163 164 (face hydra-face-blue)
1405 180 181 (face hydra-face-blue)
1406 189 190 (face hydra-face-blue)
1407 206 207 (face hydra-face-blue)
1408 223 224 (face hydra-face-blue)
1409 231 232 (face hydra-face-blue)
1410 248 249 (face hydra-face-blue)
1411 265 266 (face hydra-face-blue)
1412 280 281 (face hydra-face-blue)
1413 297 298 (face hydra-face-blue)
1414 314 315 (face hydra-face-blue)
1415 322 323 (face hydra-face-blue)))))
1417 (provide 'hydra-test)
1419 ;;; hydra-test.el ends here