From ab45d5bf6d46abd9b29389dee6689044fd63e225 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 21 Aug 2023 10:45:25 +0800 Subject: vim-patch:8.1.2044: no easy way to process postponed work Problem: No easy way to process postponed work. (Paul Jolly) Solution: Add the SafeState autocommand event. https://github.com/vim/vim/commit/8aeec40207b5adcd3a155277dc4f29189343b963 Co-authored-by: Bram Moolenaar --- runtime/doc/autocmd.txt | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'runtime/doc') diff --git a/runtime/doc/autocmd.txt b/runtime/doc/autocmd.txt index a7c28e25d0..90211fc5db 100644 --- a/runtime/doc/autocmd.txt +++ b/runtime/doc/autocmd.txt @@ -862,6 +862,27 @@ RecordingLeave When a macro stops recording. Sets these |v:event| keys: regcontents regname + *SafeState* +SafeState When nothing is pending, going to wait for the + user to type a character. + This will not be triggered when: + - an operator is pending + - a register was entered with "r + - halfway executing a command + - executing a mapping + - there is typeahead + - Insert mode completion is active + - Command line completion is active + You can use `mode()` to find out what state + Vim is in. That may be: + - VIsual mode + - Normal mode + - Insert mode + - Command-line mode + Depending on what you want to do, you may also + check more with `state()`, e.g. whether the + screen was scrolled for messages. + *SessionLoadPost* SessionLoadPost After loading the session file created using the |:mksession| command. -- cgit From 4956f267449ca7526145c63ef095bfd731174635 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 21 Aug 2023 11:11:02 +0800 Subject: vim-patch:8.1.2046: SafeState may be triggered at the wrong moment Problem: SafeState may be triggered at the wrong moment. Solution: Move it up higher to after where messages are processed. Add a SafeStateAgain event to tigger there. https://github.com/vim/vim/commit/69198cb8c08f124729c41a4681f2d142228a9139 SafeStateAgain is N/A. Move SafeState functions to state.c. Co-authored-by: Bram Moolenaar --- runtime/doc/vim_diff.txt | 1 + 1 file changed, 1 insertion(+) (limited to 'runtime/doc') diff --git a/runtime/doc/vim_diff.txt b/runtime/doc/vim_diff.txt index b7bb52333d..29a7c50585 100644 --- a/runtime/doc/vim_diff.txt +++ b/runtime/doc/vim_diff.txt @@ -619,6 +619,7 @@ Eval: *v:sizeofpointer* Events: + *SafeStateAgain* *SigUSR1* Use |Signal| to detect `SIGUSR1` signal instead. Highlight groups: -- cgit From 64ccfdaafef56b451e3a5eed94367fad93978ec8 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 21 Aug 2023 11:22:25 +0800 Subject: vim-patch:8.1.2047: cannot check the current state Problem: Cannot check the current state. Solution: Add the state() function. https://github.com/vim/vim/commit/0e57dd859ecb1e8a3b91509d2f4343e839340eb8 Co-authored-by: Bram Moolenaar --- runtime/doc/builtin.txt | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'runtime/doc') diff --git a/runtime/doc/builtin.txt b/runtime/doc/builtin.txt index 92cedbdc80..c57b8637e0 100644 --- a/runtime/doc/builtin.txt +++ b/runtime/doc/builtin.txt @@ -4753,6 +4753,7 @@ mode([expr]) *mode()* If [expr] is supplied and it evaluates to a non-zero Number or a non-empty String (|non-zero-arg|), then the full mode is returned, otherwise only the first letter is returned. + Also see |state()|. n Normal no Operator-pending @@ -7368,6 +7369,31 @@ srand([{expr}]) *srand()* echo rand(seed) < +state([{what}]) *state()* + Return a string which contains characters indicating the + current state. Mostly useful in callbacks that want to do + work that may not always be safe. Roughly this works like: + - callback uses state() to check if work is safe to do. + If yes, then do it right away. + Otherwise add to work queue and add SafeState autocommand. + - When SafeState is triggered, check with state() if the work + can be done now, and if yes remove it from the queue and + execute. + Also see |mode()|. + + When {what} is given only characters in this string will be + added. E.g, this checks if the screen has scrolled: >vim + if state('s') != '' + + These characters indicate the state: + m halfway a mapping, :normal command, feedkeys() or + stuffed command + o operator pending or waiting for a command argument + a Insert mode autocomplete active + x executing an autocommand + c callback invoked (repeats for recursiveness up to "ccc") + s screen has scrolled for messages + stdioopen({opts}) *stdioopen()* With |--headless| this opens stdin and stdout as a |channel|. May be called only once. See |channel-stdio|. stderr is not -- cgit From 7ce2acd59be89e5e6d2ac778ad074a9ae42951cd Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 21 Aug 2023 12:16:33 +0800 Subject: vim-patch:8.1.2053: SafeStateAgain not triggered if callback uses feedkeys() Problem: SafeStateAgain not triggered if callback uses feedkeys(). Solution: Check for safe state in the input loop. Make log messages easier to find. Add 'S' flag to state(). https://github.com/vim/vim/commit/d103ee78432f9036d243b18dd5aac1263d3b7dc9 Include misc1.c change from patch 8.1.2062. Co-authored-by: Bram Moolenaar --- runtime/doc/builtin.txt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'runtime/doc') diff --git a/runtime/doc/builtin.txt b/runtime/doc/builtin.txt index c57b8637e0..2ce66d8cc2 100644 --- a/runtime/doc/builtin.txt +++ b/runtime/doc/builtin.txt @@ -7385,13 +7385,16 @@ state([{what}]) *state()* added. E.g, this checks if the screen has scrolled: >vim if state('s') != '' - These characters indicate the state: + These characters indicate the state, generally indicating that + something is busy: m halfway a mapping, :normal command, feedkeys() or stuffed command o operator pending or waiting for a command argument a Insert mode autocomplete active x executing an autocommand - c callback invoked (repeats for recursiveness up to "ccc") + S not triggering SafeState + c callback invoked, including timer (repeats for + recursiveness up to "ccc") s screen has scrolled for messages stdioopen({opts}) *stdioopen()* -- cgit