Skip to content

Commit 3429de4

Browse files
committed
Merge pull request #28 from noctuid/avy-all-windows
Add support for avy-all-windows
2 parents 42bd507 + ced2d80 commit 3429de4

File tree

1 file changed

+48
-40
lines changed

1 file changed

+48
-40
lines changed

evil-easymotion.el

Lines changed: 48 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -103,50 +103,51 @@
103103
"avy-jump to the set of points generated by collector"
104104
(require 'avy)
105105
(let* ((avy-style (or evilem-style avy-style))
106-
(avy-keys (or evilem-keys avy-keys))
107-
(avy-all-windows nil))
108-
(avy--process (mapcar
109-
(lambda (pt)
110-
(cons pt (get-buffer-window)))
111-
points)
106+
(avy-keys (or evilem-keys avy-keys)))
107+
(avy--process points
112108
(avy--style-fn avy-style))))
113109

114-
(defun evilem--collect (func &optional scope)
110+
(defun evilem--collect (func &optional scope all-windows)
115111
"Repeatedly execute func, and collect the cursor positions into a list"
116112
(if (functionp func)
117113
(let ((points)
114+
(point)
115+
(avy-all-windows all-windows)
118116
;; make sure the motion doesn't move the window
119117
(scroll-conservatively 101)
120118
(smooth-scroll-margin 0)
121119
(scroll-margin 0))
122-
(save-excursion
123-
(save-restriction
124-
(cl-destructuring-bind (beg . end)
125-
(if scope
126-
(bounds-of-thing-at-point scope)
127-
(cons (point-min)
128-
(point-max)))
129-
130-
;; trim trailing newline
131-
(when (= (char-before end) 10)
132-
(cl-decf end))
133-
134-
(narrow-to-region (max beg (window-start))
135-
(min end (window-end))))
136-
(while (and (ignore-errors
137-
(setq this-command func
138-
last-command func)
139-
(call-interactively func)
140-
t)
141-
(not (memq (point) points))
142-
(push (point) points))))
143-
(nreverse points)))
120+
(avy-dowindows current-prefix-arg
121+
(save-excursion
122+
(save-restriction
123+
(cl-destructuring-bind (beg . end)
124+
(if scope
125+
(bounds-of-thing-at-point scope)
126+
(cons (point-min)
127+
(point-max)))
128+
129+
;; trim trailing newline
130+
(when (= (char-before end) 10)
131+
(cl-decf end))
132+
133+
(narrow-to-region (max beg (window-start))
134+
(min end (window-end))))
135+
(while (and (ignore-errors
136+
(setq this-command func
137+
last-command func)
138+
(call-interactively func)
139+
t)
140+
(setq point (cons (point) (get-buffer-window)))
141+
(not (member point points))
142+
(push point points))))))
143+
(nreverse points))
144144
(cl-remove-duplicates
145145
(cl-mapcan (lambda (f)
146-
(evilem--collect f scope))
146+
(evilem--collect f scope all-windows))
147147
func))))
148148

149-
(cl-defmacro evilem-make-motion (name func &key pre-hook post-hook bind scope)
149+
(cl-defmacro evilem-make-motion (name func &key pre-hook post-hook bind scope
150+
all-windows)
150151
"Automatically define an evil easymotion for `func', naming it `name'"
151152
`(evil-define-motion ,name (_count)
152153
(evil-without-repeat
@@ -155,50 +156,57 @@
155156
,(when pre-hook `(funcall ,(if (functionp pre-hook)
156157
pre-hook
157158
`(lambda () ,pre-hook))))
158-
(evilem--jump (evilem--collect ,func ,scope))
159+
(evilem--jump (evilem--collect ,func ,scope ,all-windows))
159160
,(when post-hook `(funcall ,(if (functionp post-hook)
160161
post-hook
161162
`(lambda () ,post-hook))))))))
162163

163-
(cl-defmacro evilem-make-motion-plain (name func &key pre-hook post-hook bind scope)
164+
(cl-defmacro evilem-make-motion-plain (name func &key pre-hook post-hook bind scope
165+
all-windows)
164166
"Automatically define a plain easymotion for `func', naming it `name'"
165167
`(defun ,name ()
166168
(interactive)
167169
(cl-letf ,bind
168170
,(when pre-hook `(funcall ,(if (functionp pre-hook)
169171
pre-hook
170172
`(lambda () ,pre-hook))))
171-
(evilem--jump (evilem--collect ,func ,scope))
173+
(evilem--jump (evilem--collect ,func ,scope ,all-windows))
172174
,(when post-hook `(funcall ,(if (functionp post-hook)
173175
post-hook
174176
`(lambda () ,post-hook)))))))
175177

176-
(cl-defmacro evilem-create (motion &key pre-hook post-hook bind scope)
178+
(cl-defmacro evilem-create (motion &key pre-hook post-hook bind scope
179+
all-windows)
177180
`(evilem-make-motion
178181
,(intern (evilem--make-name motion))
179182
,motion
180183
:pre-hook ,pre-hook
181184
:post-hook ,post-hook
182185
:bind ,bind
183-
:scope ,scope))
186+
:scope ,scope
187+
:all-windows ,all-windows))
184188

185-
(cl-defmacro evilem-create-plain (motion &key pre-hook post-hook bind scope)
189+
(cl-defmacro evilem-create-plain (motion &key pre-hook post-hook bind scope
190+
all-windows)
186191
`(evilem-make-motion-plain
187192
,(intern (evilem--make-name motion))
188193
,motion
189194
:pre-hook ,pre-hook
190195
:post-hook ,post-hook
191196
:bind ,bind
192-
:scope ,scope))
197+
:scope ,scope
198+
:all-windows ,all-windows))
193199

194-
(cl-defmacro evilem-define (key motion &key pre-hook post-hook bind scope)
200+
(cl-defmacro evilem-define (key motion &key pre-hook post-hook bind scope
201+
all-windows)
195202
"Automatically create and bind an evil motion"
196203
`(define-key evil-motion-state-map ,key
197204
(evilem-create ,motion
198205
:pre-hook ,pre-hook
199206
:post-hook ,post-hook
200207
:bind ,bind
201-
:scope ,scope)))
208+
:scope ,scope
209+
:all-windows ,all-windows)))
202210

203211
;;;###autoload
204212
(defun evilem-default-keybindings (prefix)

0 commit comments

Comments
 (0)