vim icon indicating copy to clipboard operation
vim copied to clipboard

Add a way to know if <expr> mapping is triggered on timeout

Open zeertzjq opened this issue 4 years ago • 2 comments

I've currently chosen v:timedout as the name, as this name may be reused for other timeout-related things in future.

zeertzjq avatar Jul 03 '22 03:07 zeertzjq

Codecov Report

Merging #10652 (fe62ba2) into master (9032b9c) will increase coverage by 0.81%. The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master   #10652      +/-   ##
==========================================
+ Coverage   81.87%   82.69%   +0.81%     
==========================================
  Files         158      148      -10     
  Lines      186147   173684   -12463     
  Branches    42029    39244    -2785     
==========================================
- Hits       152414   143620    -8794     
+ Misses      21251    17474    -3777     
- Partials    12482    12590     +108     
Flag Coverage Δ
huge-clang-none 82.69% <100.00%> (+<0.01%) :arrow_up:
linux 82.69% <100.00%> (+<0.01%) :arrow_up:
mingw-x64-HUGE-gui ?
windows ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/evalvars.c 90.87% <ø> (-0.88%) :arrow_down:
src/getchar.c 84.62% <100.00%> (-0.85%) :arrow_down:
src/map.c 87.15% <100.00%> (-1.33%) :arrow_down:
src/highlight.c 78.40% <0.00%> (-2.86%) :arrow_down:
src/misc2.c 86.71% <0.00%> (-2.61%) :arrow_down:
src/time.c 87.08% <0.00%> (-2.56%) :arrow_down:
src/help.c 80.06% <0.00%> (-2.48%) :arrow_down:
src/buffer.c 84.15% <0.00%> (-2.31%) :arrow_down:
src/gui.c 71.24% <0.00%> (-1.95%) :arrow_down:
src/session.c 63.15% <0.00%> (-1.94%) :arrow_down:
... and 131 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

codecov[bot] avatar Jul 03 '22 03:07 codecov[bot]

The initial use case I thought of is to enable a way to make a mapping prefix "never time out", for example:

nmap <expr> g v:timedout ? '<Ignore>g' : 'g'

Makes mapping starting with g behave as if they never time out. Only using nmap g <Ignore>g may also achieve this, but will lead to high CPU usage, whereas using this example the CPU usage is fine as long as 'timeoutlen' is non-zero.

Another use case I noticed is to possibly achieve the purpose mentioned in #10503. Using this mapping (g<Plug> is a dummy mapping to avoid triggering g mapping immediately):

nnoremap <expr> g v:timedout ? '<Cmd>echo 123<CR>' : 'g'
nnoremap g<Plug> <Nop>

Makes pressing gg within 'timeoutlen' trigger builtin gg command, while a timed out g prints 123.

zeertzjq avatar Aug 03 '22 06:08 zeertzjq

I've currently chosen v:timedout as the name, as this name may be reused for other timeout-related things in future.

What do you need this for?

The help says "mapping triggered on timeout". What does that mean exactly? I suppose 'timeoutlen' and 'ttimeoutlen' matter.

-- Nothing is fool-proof to a sufficiently talented fool.

/// Bram Moolenaar -- @.*** -- http://www.Moolenaar.net \\ /// \\ \\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\ help me help AIDS victims -- http://ICCF-Holland.org ///

brammool avatar Oct 11 '22 08:10 brammool

This isn't very useful and can also be implemented by calculating the time difference between two mappings. Closing.

zeertzjq avatar Oct 11 '22 08:10 zeertzjq