|
107 | 107 | (avy--process points
|
108 | 108 | (avy--style-fn avy-style))))
|
109 | 109 |
|
110 |
| -(defun evilem--collect (func &optional scope all-windows initial-point) |
| 110 | +(defun evilem--default-collect-postprocess (points) |
| 111 | + (cl-stable-sort |
| 112 | + points |
| 113 | + #'< |
| 114 | + :key (lambda (pt) |
| 115 | + (if (equal (selected-window) (cdr pt)) |
| 116 | + (abs (- (point) (car pt))) |
| 117 | + most-positive-fixnum)))) |
| 118 | + |
| 119 | +(defun evilem--collect (func &optional |
| 120 | + scope |
| 121 | + all-windows |
| 122 | + initial-point |
| 123 | + sort-key |
| 124 | + collect-postprocess) |
111 | 125 | "Repeatedly execute func, and collect the cursor positions into a list"
|
112 | 126 | (require 'avy)
|
113 |
| - (if (functionp func) |
114 |
| - (cl-letf ((points nil) |
115 |
| - (point nil) |
116 |
| - (avy-all-windows all-windows) |
117 |
| - ;; make sure the motion doesn't move the window |
118 |
| - (scroll-conservatively 101) |
119 |
| - (smooth-scrolling-mode nil) |
120 |
| - (scroll-margin 0)) |
| 127 | + (cl-letf ((points nil) |
| 128 | + (point nil) |
| 129 | + (avy-all-windows all-windows) |
| 130 | + ;; make sure the motion doesn't move the window |
| 131 | + (scroll-conservatively 101) |
| 132 | + (smooth-scrolling-mode nil) |
| 133 | + (scroll-margin 0)) |
| 134 | + (if (functionp func) |
121 | 135 | (avy-dowindows current-prefix-arg
|
122 | 136 | (save-excursion
|
123 | 137 | (save-restriction
|
|
143 | 157 | (setq point (cons (point) (get-buffer-window)))
|
144 | 158 | (not (member point points))
|
145 | 159 | (push point points))))))
|
146 |
| - (nreverse points)) |
147 |
| - (cl-remove-duplicates |
148 |
| - (cl-mapcan (lambda (f) |
149 |
| - (evilem--collect f scope all-windows)) |
150 |
| - func)))) |
| 160 | + (setq points (cl-remove-duplicates |
| 161 | + (cl-mapcan (lambda (f) |
| 162 | + (evilem--collect f scope all-windows)) |
| 163 | + func)))) |
| 164 | + (funcall (or collect-postprocess |
| 165 | + #'evilem--default-collect-postprocess) |
| 166 | + points))) |
151 | 167 |
|
152 | 168 | (cl-defmacro evilem-make-motion (name
|
153 | 169 | funcs
|
|
157 | 173 | bind
|
158 | 174 | scope
|
159 | 175 | all-windows
|
160 |
| - initial-point) |
| 176 | + initial-point |
| 177 | + collect-postprocess) |
161 | 178 | "Automatically define an evil easymotion for `func', naming it `name'"
|
162 | 179 | `(,(if all-windows
|
163 | 180 | 'evil-define-command
|
164 | 181 | 'evil-define-motion)
|
165 | 182 | ,name (&optional _count)
|
166 |
| - (evil-without-repeat |
167 |
| - (setq evil-this-type 'inclusive) |
168 |
| - (cl-letf* ,bind |
169 |
| - ,(when pre-hook `(funcall ,(if (functionp pre-hook) |
170 |
| - pre-hook |
171 |
| - `(lambda () ,pre-hook)))) |
172 |
| - (evilem--jump (evilem--collect ,funcs |
173 |
| - ,scope |
174 |
| - ,all-windows |
175 |
| - ,initial-point)) |
176 |
| - ,(when post-hook `(funcall ,(if (functionp post-hook) |
177 |
| - post-hook |
178 |
| - `(lambda () ,post-hook)))))))) |
| 183 | + (evil-without-repeat |
| 184 | + (setq evil-this-type 'inclusive) |
| 185 | + (cl-letf* ,bind |
| 186 | + ,(when pre-hook `(funcall ,(if (functionp pre-hook) |
| 187 | + pre-hook |
| 188 | + `(lambda () ,pre-hook)))) |
| 189 | + (evilem--jump (evilem--collect ,funcs |
| 190 | + ,scope |
| 191 | + ,all-windows |
| 192 | + ,initial-point |
| 193 | + ,collect-postprocess)) |
| 194 | + ,(when post-hook `(funcall ,(if (functionp post-hook) |
| 195 | + post-hook |
| 196 | + `(lambda () ,post-hook)))))))) |
179 | 197 |
|
180 | 198 | (cl-defmacro evilem-make-motion-plain (name
|
181 | 199 | funcs
|
|
185 | 203 | bind
|
186 | 204 | scope
|
187 | 205 | all-windows
|
188 |
| - initial-point) |
| 206 | + initial-point |
| 207 | + collect-postprocess) |
189 | 208 | "Automatically define a plain easymotion for `func', naming it `name'"
|
190 | 209 | `(defun ,name ()
|
191 | 210 | (interactive)
|
|
196 | 215 | (evilem--jump (evilem--collect ,funcs
|
197 | 216 | ,scope
|
198 | 217 | ,all-windows
|
199 |
| - ,initial-point)) |
| 218 | + ,initial-point |
| 219 | + ,collect-postprocess)) |
200 | 220 | ,(when post-hook `(funcall ,(if (functionp post-hook)
|
201 | 221 | post-hook
|
202 | 222 | `(lambda () ,post-hook)))))))
|
|
208 | 228 | bind
|
209 | 229 | scope
|
210 | 230 | all-windows
|
211 |
| - initial-point) |
| 231 | + initial-point |
| 232 | + collect-postprocess) |
212 | 233 | `(evilem-make-motion
|
213 | 234 | ,(intern (evilem--make-name motions))
|
214 | 235 | ,motions
|
|
217 | 238 | :bind ,bind
|
218 | 239 | :scope ,scope
|
219 | 240 | :all-windows ,all-windows
|
220 |
| - :initial-point ,initial-point)) |
| 241 | + :initial-point ,initial-point |
| 242 | + :collect-postprocess ,collect-postprocess)) |
221 | 243 |
|
222 | 244 | (cl-defmacro evilem-create-plain (motions
|
223 | 245 | &key
|
|
226 | 248 | bind
|
227 | 249 | scope
|
228 | 250 | all-windows
|
229 |
| - initial-point) |
| 251 | + initial-point |
| 252 | + collect-postprocess) |
230 | 253 | `(evilem-make-motion-plain
|
231 | 254 | ,(intern (evilem--make-name motions))
|
232 | 255 | ,motions
|
|
235 | 258 | :bind ,bind
|
236 | 259 | :scope ,scope
|
237 | 260 | :all-windows ,all-windows
|
238 |
| - :initial-point ,initial-point)) |
| 261 | + :initial-point ,initial-point |
| 262 | + :collect-postprocess ,collect-postprocess)) |
239 | 263 |
|
240 | 264 | (cl-defmacro evilem-define (key
|
241 | 265 | motions
|
|
245 | 269 | bind
|
246 | 270 | scope
|
247 | 271 | all-windows
|
248 |
| - initial-point) |
| 272 | + initial-point |
| 273 | + collect-postprocess) |
249 | 274 | "Automatically create and bind an evil motion"
|
250 | 275 | `(define-key ,(if all-windows
|
251 | 276 | 'evil-normal-state-map
|
|
257 | 282 | :bind ,bind
|
258 | 283 | :scope ,scope
|
259 | 284 | :all-windows ,all-windows
|
260 |
| - :initial-point ,initial-point))) |
| 285 | + :initial-point ,initial-point |
| 286 | + :collect-postprocess ,collect-postprocess))) |
261 | 287 |
|
262 | 288 | ;;;###autoload
|
263 | 289 | (defun evilem-default-keybindings (prefix)
|
|
0 commit comments