Skip to content

Commit f96c2ed

Browse files
committed
Skip over invisible overlays by default, closes #46
1 parent 79c13ed commit f96c2ed

File tree

2 files changed

+39
-11
lines changed

2 files changed

+39
-11
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ In addition, various keyword arguments may be used to modify the behavior of the
107107

108108
When specified, `callable` is called on the collected list of points (which is of the form `((point window)...)`). Otherwise, the default function, which sorts the points in order of increasing distance from `(point)`, is used.
109109

110+
* `:include-invisible expr`
111+
112+
When `expr` is non-`nil`, the motion will not skip over invisible overlays. This may be required for motions that generate dramatically different sets of points if they are started at different locations. This defaults to `nil`.
113+
110114
Credits
111115
=======
112116
I'm deeply indebted to:

evil-easymotion.el

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@
125125
all-windows
126126
initial-point
127127
sort-key
128-
collect-postprocess)
128+
collect-postprocess
129+
include-invisible)
129130
"Repeatedly execute func, and collect the cursor positions into a list"
130131
(cl-letf ((points nil)
131132
(point nil)
@@ -156,6 +157,19 @@
156157
(setq this-command func
157158
last-command func)
158159
(call-interactively func)
160+
(unless include-invisible
161+
(let ((ov (car (overlays-at (point)))))
162+
(while (and ov (member
163+
'invisible
164+
(overlay-properties ov)))
165+
(goto-char (overlay-end ov))
166+
;; This is a bit of a hack, since we
167+
;; can't guarantee that we will end
168+
;; up at the same point if we start
169+
;; at the end of the invisible
170+
;; region vs. looping through it.
171+
(call-interactively func)
172+
(setq ov (car (overlays-at (point)))))))
159173
t)
160174
(setq point (cons (point) (get-buffer-window)))
161175
(not (member point points))
@@ -185,7 +199,8 @@
185199
all-windows
186200
initial-point
187201
push-jump
188-
collect-postprocess)
202+
collect-postprocess
203+
include-invisible)
189204
"Automatically define an evil easymotion for `func', naming it `name'"
190205
`(,(if all-windows
191206
'evil-define-command
@@ -205,7 +220,8 @@
205220
,scope
206221
,all-windows
207222
,initial-point
208-
,collect-postprocess))
223+
,collect-postprocess
224+
,include-invisible))
209225
,(when post-hook `(funcall ,(if (functionp post-hook)
210226
post-hook
211227
`(lambda () ,post-hook)))))))))
@@ -219,7 +235,8 @@
219235
scope
220236
all-windows
221237
initial-point
222-
collect-postprocess)
238+
collect-postprocess
239+
include-invisible)
223240
"Automatically define a plain easymotion for `func', naming it `name'"
224241
`(defun ,name ()
225242
(interactive)
@@ -233,7 +250,8 @@
233250
,scope
234251
,all-windows
235252
,initial-point
236-
,collect-postprocess))
253+
,collect-postprocess
254+
,include-invisible))
237255
,(when post-hook `(funcall ,(if (functionp post-hook)
238256
post-hook
239257
`(lambda () ,post-hook))))))))
@@ -248,7 +266,8 @@
248266
all-windows
249267
initial-point
250268
push-jump
251-
collect-postprocess)
269+
collect-postprocess
270+
include-invisible)
252271
`(evilem-make-motion
253272
,(or (evilem--unquote name)
254273
(intern (evilem--make-name motions)))
@@ -260,7 +279,8 @@
260279
:all-windows ,all-windows
261280
:initial-point ,initial-point
262281
:push-jump ,push-jump
263-
:collect-postprocess ,collect-postprocess))
282+
:collect-postprocess ,collect-postprocess
283+
:include-invisible ,include-invisible))
264284

265285
(cl-defmacro evilem-create-plain (motions
266286
&key
@@ -271,7 +291,8 @@
271291
scope
272292
all-windows
273293
initial-point
274-
collect-postprocess)
294+
collect-postprocess
295+
include-invisible)
275296
`(evilem-make-motion-plain
276297
,(or (evilem--unquote name)
277298
(intern (evilem--make-name motions)))
@@ -282,7 +303,8 @@
282303
:scope ,scope
283304
:all-windows ,all-windows
284305
:initial-point ,initial-point
285-
:collect-postprocess ,collect-postprocess))
306+
:collect-postprocess ,collect-postprocess
307+
:include-invisible ,include-invisible))
286308

287309
(cl-defmacro evilem-define (key
288310
motions
@@ -295,7 +317,8 @@
295317
all-windows
296318
initial-point
297319
push-jump
298-
collect-postprocess)
320+
collect-postprocess
321+
include-invisible)
299322
"Automatically create and bind an evil motion"
300323
`(define-key ,(if all-windows
301324
'evil-normal-state-map
@@ -310,7 +333,8 @@
310333
:all-windows ,all-windows
311334
:initial-point ,initial-point
312335
:push-jump ,push-jump
313-
:collect-postprocess ,collect-postprocess)))
336+
:collect-postprocess ,collect-postprocess
337+
:include-invisible ,include-invisible)))
314338

315339
;;;###autoload (autoload 'evilem-motion-forward-word-begin "evil-easymotion" nil t)
316340
(evilem-make-motion

0 commit comments

Comments
 (0)