argmatcher onadvance doesn't effect the hint to advance #779
-
|
When onadvance moves to a next positional arg, the hint isn't updated. Is it intended behaviour? Reproduce-- complete.lua
function loop_until(word_index, line_state, user_data)
if not user_data.first_index then
user_data.first_index = word_index
end
local diff = user_data.var_max - user_data.var_min
local prev_word = line_state:getword(word_index - 1)
-- var_max is -1 to loop forever and using '--' should break the loop
-- to point to next arg position.
-- diff is used to loop limitedly till max but also break with '--' if greater than min
if (user_data.var_max < 0 and prev_word == "--")
or ((diff > 0 and word_index >= user_data.first_index + diff)
or (prev_word == "--" and word_index >= user_data.first_index + user_data.var_min))
then
return 1
end
return 0
end
clink.argmatcher("prog")
:addarg({"task1", "task2", "task3",
hint = "Looping tasks",
onadvance = function(_,_,wi,ls,ud) ud.var_min=0; ud.var_max=-1; return loop_until(wi,ls,ud) end
})
:addarg({"done", hint = "Done looping"}):: '|' -> cursor
> prog |<TAB>
Looping tasks
> prog task1 |<TAB>
Looping tasks
> prog task1 task2 |
Looping tasks
> prog task1 task2 -- |
Looping tasks
> prog task1 task2 -- |<TAB>
Looping tasks
> prog task1 task2 -- done |
> prog task1 task2 -- done|
Looping tasks |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 8 replies
-
|
Thanks for reporting this! I will need to dig into it a bit to understand specifics, so thank you for sharing a minimal repro script. I'll look into it when I get a chance, which probably won't be until late next week. |
Beta Was this translation helpful? Give feedback.
-
|
loop_until function. |
Beta Was this translation helpful? Give feedback.
Testing revealed that the attempted fix causes problematic side effects.
Which led to realizing my advice to "instead check the current word is
--" was very incorrect. Theonadvancecallback is specifically for advancing the argument index for the current word. If it advances preemptively for the next word, then the argument index ends up double-advancing in that case (which is completely correct behavior given the design and documentation).So, the only thing that can be done about it is to add an extra blank word to the
line_stateif the cursor is past the end of the last real word in the line, so thatonadvancecan run one final time for the cursor position even though there isn't real…