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 --- src/nvim/eval.lua | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'src/nvim/eval.lua') diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua index be87201bbf..f244d26375 100644 --- a/src/nvim/eval.lua +++ b/src/nvim/eval.lua @@ -6917,6 +6917,7 @@ M.funcs = { 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 @@ -10451,6 +10452,38 @@ M.funcs = { params = { { 'what', 'any' } }, signature = 'stdpath({what})', }, + state = { + args = {0, 1}, + base = 1, + desc = [=[ + 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 + ]=], + name = 'state', + params = { { 'what', 'string' } }, + signature = 'state([{what}])', + }, str2float = { args = 1, base = 1, -- 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 --- src/nvim/eval.lua | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/nvim/eval.lua') diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua index f244d26375..64b875c981 100644 --- a/src/nvim/eval.lua +++ b/src/nvim/eval.lua @@ -10471,13 +10471,16 @@ M.funcs = { 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 ]=], name = 'state', -- cgit From 6bf5b2428b146330688922d66438357c0568725d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 21 Aug 2023 12:26:02 +0800 Subject: vim-patch:8.1.2066: no tests for state() Problem: No tests for state(). Solution: Add tests. Clean up some feature checks. Make "a" flag work. https://github.com/vim/vim/commit/c2585490321854ca3df115efcf0b40986901d96c Co-authored-by: Bram Moolenaar --- src/nvim/eval.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/eval.lua') diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua index 64b875c981..e786901c2f 100644 --- a/src/nvim/eval.lua +++ b/src/nvim/eval.lua @@ -10483,6 +10483,7 @@ M.funcs = { recursiveness up to "ccc") s screen has scrolled for messages ]=], + fast = true, name = 'state', params = { { 'what', 'string' } }, signature = 'state([{what}])', -- cgit