]> code.delx.au - gnu-emacs-elpa/blob - packages/hydra/hydra-test.el
Add 'packages/sotlisp/' from commit 'a781d1e12fac2dbad52d300aaa1b4bcfce83a5a7'
[gnu-emacs-elpa] / packages / hydra / hydra-test.el
1 (require 'ert)
2
3 (ert-deftest defhydra ()
4 (should
5 (equal
6 (macroexpand
7 '(defhydra hydra-error (global-map "M-g")
8 "error"
9 ("h" first-error "first")
10 ("j" next-error "next")
11 ("k" previous-error "prev")))
12 '(progn
13 (defun hydra-error/first-error ()
14 "Create a hydra with a \"M-g\" body and the heads:
15
16 \"h\": `first-error',
17 \"j\": `next-error',
18 \"k\": `previous-error'
19
20 The body can be accessed via `hydra-error/body'.
21
22 Call the head: `first-error'."
23 (interactive)
24 (call-interactively #'first-error)
25 (when hydra-is-helpful
26 (message #("error: [h]: first, [j]: next, [k]: prev."
27 8 9 (face font-lock-keyword-face)
28 20 21 (face font-lock-keyword-face)
29 31 32 (face font-lock-keyword-face))))
30 (setq hydra-last
31 (hydra-set-transient-map
32 '(keymap
33 (107 . hydra-error/previous-error)
34 (106 . hydra-error/next-error)
35 (104 . hydra-error/first-error)) t)))
36
37 (defun hydra-error/next-error ()
38 "Create a hydra with a \"M-g\" body and the heads:
39
40 \"h\": `first-error',
41 \"j\": `next-error',
42 \"k\": `previous-error'
43
44 The body can be accessed via `hydra-error/body'.
45
46 Call the head: `next-error'."
47 (interactive)
48 (call-interactively #'next-error)
49 (when hydra-is-helpful
50 (message #("error: [h]: first, [j]: next, [k]: prev."
51 8 9 (face font-lock-keyword-face)
52 20 21 (face font-lock-keyword-face)
53 31 32 (face font-lock-keyword-face))))
54 (setq hydra-last
55 (hydra-set-transient-map
56 '(keymap
57 (107 . hydra-error/previous-error)
58 (106 . hydra-error/next-error)
59 (104 . hydra-error/first-error)) t)))
60
61 (defun hydra-error/previous-error ()
62 "Create a hydra with a \"M-g\" body and the heads:
63
64 \"h\": `first-error',
65 \"j\": `next-error',
66 \"k\": `previous-error'
67
68 The body can be accessed via `hydra-error/body'.
69
70 Call the head: `previous-error'."
71 (interactive)
72 (call-interactively #'previous-error)
73 (when hydra-is-helpful
74 (message #("error: [h]: first, [j]: next, [k]: prev."
75 8 9 (face font-lock-keyword-face)
76 20 21 (face font-lock-keyword-face)
77 31 32 (face font-lock-keyword-face))))
78 (setq hydra-last
79 (hydra-set-transient-map
80 '(keymap
81 (107 . hydra-error/previous-error)
82 (106 . hydra-error/next-error)
83 (104 . hydra-error/first-error)) t)))
84
85 (unless (keymapp (lookup-key global-map (kbd "M-g")))
86 (define-key global-map (kbd "M-g") nil))
87 (define-key global-map [134217831 104] #'hydra-error/first-error)
88 (define-key global-map [134217831 106] #'hydra-error/next-error)
89 (define-key global-map [134217831 107] #'hydra-error/previous-error)
90
91 (defun hydra-error/body ()
92 "Create a hydra with a \"M-g\" body and the heads:
93
94 \"h\": `first-error',
95 \"j\": `next-error',
96 \"k\": `previous-error'
97
98 The body can be accessed via `hydra-error/body'."
99 (interactive)
100 (when hydra-is-helpful
101 (message #("error: [h]: first, [j]: next, [k]: prev."
102 8 9 (face font-lock-keyword-face)
103 20 21 (face font-lock-keyword-face)
104 31 32 (face font-lock-keyword-face))))
105 (setq hydra-last
106 (hydra-set-transient-map
107 '(keymap
108 (107 . hydra-error/previous-error)
109 (106 . hydra-error/next-error)
110 (104 . hydra-error/first-error)) t)))))))
111
112 (provide 'hydra-test)