forked from semiosis/pen.el
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpen-avy.el
168 lines (141 loc) · 4.54 KB
/
pen-avy.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
(require 'avy)
(require 'ace-link)
(setq avy-all-windows nil)
;; For avy-goto-char-timer
(setq avy-timeout-seconds 0.2)
(defun avy-goto-char-all-windows (args)
(interactive "P")
(let ((avy-all-windows t))
(call-interactively #'avy-goto-char)))
(defun avy-goto-char-enter ()
"Go to a char with avy and then press 'Enter'"
(interactive)
(call-interactively #'avy-goto-char)
(ekm "C-m"))
(defun avy-goto-char-9 ()
"Go to a char with avy and then press M-9"
(interactive)
(call-interactively #'avy-goto-char)
(ekm "M-9"))
(defun avy-goto-link-or-button-w ()
"Go to a char with avy and then press 'w' for copy"
(interactive)
(call-interactively 'ace-link-goto-link-or-button)
(if (not (eq (key-binding "w") 'self-insert-command))
(ekm "w")
(message "No button/link address here to copy")))
(defun avy-goto-char-doc ()
"Go to a char with avy and then press 'M-9'"
(interactive)
(call-interactively #'avy-goto-char)
(ekm "M-9"))
(defun avy-goto-char-goto-def ()
"Go to a char with avy and then press 'M-.'"
(interactive)
(call-interactively #'avy-goto-char)
(ekm "M-."))
(defun simulate-left-click ()
(interactive)
(pen-cl-sn "tmux run -b \"pen-tm mouseclick\"" :detach t))
(defun simulate-right-click ()
(interactive)
(pen-cl-sn "tmux run -b \"pen-tm mouseup -x -r\"" :detach t))
(defun avy-goto-char-left-click ()
"Go to a char with avy and then left click with tmux.'"
(interactive)
(call-interactively #'avy-goto-char)
(simulate-left-click))
(defun avy-goto-char-right-click ()
"Go to a char with avy and then right click with tmux.'"
(interactive)
(call-interactively #'avy-goto-char)
(simulate-right-click))
(defun avy-goto-char-c-o ()
"Go to a char with avy and then type =C-c C-o=.'"
(interactive)
(call-interactively #'avy-goto-char)
(ekm "C-c C-o"))
(defun avy-new-buffer-from-tmux-pane-capture ()
(interactive)
(with-current-buffer (pen-tmux-pane-capture t)
(call-interactively 'avy-goto-char)))
(defun ace-link-goto-button ()
(interactive)
(avy-with ace-link-help
(avy-process
(mapcar #'cdr (buttons-collect))
(avy--style-fn avy-style))))
(defun ace-link-goto-widget ()
(interactive)
(avy-with ace-link-help
(avy-process
(mapcar #'cdr (pen-widgets-collect))
(avy--style-fn avy-style))))
(defun ace-link-or-button-collect ()
(-union
(-union (-union
(ace-link--help-collect)
(ace-link--org-collect))
(buttons-collect))
(pen-widgets-collect)))
(defun ace-link-goto-link-or-button ()
(interactive)
(avy-with ace-link-help
(avy-process
(mapcar #'cdr (ace-link-or-button-collect))
(avy--style-fn avy-style))))
(defun ace-link-goto-glossary-button ()
(interactive)
(avy-with ace-link-help
(avy-process
(mapcar #'cdr (pen-glossary-buttons-collect))
(avy--style-fn avy-style))))
(defun ace-link-click-glossary-button ()
(interactive)
(ignore-errors
(avy-with ace-link-help
(avy-process
(mapcar #'cdr (pen-glossary-buttons-collect))
(avy--style-fn avy-style)))
(push-button)))
(defun ace-link-click-button ()
(interactive)
(avy-with ace-link-help
(avy-process
(mapcar #'cdr (buttons-collect))
(avy--style-fn avy-style)))
(push-button))
(defun ace-link-click-widget ()
(interactive)
(avy-with ace-link-help
(avy-process
(mapcar #'cdr (pen-widgets-collect))
(avy--style-fn avy-style)))
(widget-button-press (point)))
(defun avy-jump-around-advice (proc &rest args)
(lsp-ui-doc-hide)
(let ((res (apply proc args)))
res))
(advice-add 'avy-jump :around #'avy-jump-around-advice)
;; This fixes the glossary sometimes
(advice-add 'avy--overlay :around #'ignore-errors-around-advice)
(defun link-hint-copy-link ()
"Copy a visible link of a supported type to the kill ring with avy.
`select-enable-clipboard' and `select-enable-primary' can be set to non-nil
values to copy the link to the clipboard and/or primary as well."
(interactive)
(avy-with link-hint-copy-link
(link-hint--one :copy)))
(defun link-hint--button-at-point-p ()
"Return the button at the point or nil."
(let ((button (button-at (point))))
(when button
(cond
((derived-mode-p 'org-brain-visualize-mode)
(try (org-brain-get-path-for-child-name (org-brain-entry-name (org-brain-entry-from-id (button-get button 'id))))
(and (button-get button 'id)
(org-brain-get-path-for-entry (button-label button)))
(button-label button)))
(t
(button-label button))))))
(provide 'pen-avy)