6 local M
= {prefix
= "<Enter>"} -- ensures hands alternating
8 local function selection_new_from_motion(keys
)
9 -- XXX: only motions with one-key mappings are supported:
10 if #keys
< 1 then return -1 end
11 -- XXX: do not consume the count argument:
12 if tonumber(keys
) then return -1 end
13 -- XXX: avoid entering an infinite loop:
14 if keys
== M
.prefix
then return #keys
end
16 for _
= 1, vis
.count
or 1 do
17 local first
= vis
.win
.selections
[1].pos
18 local last
= vis
.win
.selections
[#vis
.win
.selections
].pos
19 vis
:feedkeys("<vis-mark>a<vis-selections-save><vis-selections-remove-all>")
21 -- test the motion direction:
22 local pos
= vis
.win
.selection
.pos
24 local forward
= vis
.win
.selection
.pos
> pos
26 -- perform the motion again, this time on the appropriate end of the selection set:
27 vis
.win
.selection
.pos
= forward
and last
or first
30 vis
:feedkeys("<vis-mark>a<vis-selections-union>")
32 -- for convenience, set the primary selection to either the first or last one,
33 -- according to the motion direction:
35 vis
:feedkeys("<vis-selection-prev>")
41 vis
.events
.subscribe(vis
.events
.INIT
, function()
43 return string.format("|@%s| %s", progname
, msg
)
46 vis
:map(vis
.modes
.NORMAL
, M
.prefix
, selection_new_from_motion
, h
"Create a new selection at the end of the motion that follows")