aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/_editor.lua
diff options
context:
space:
mode:
authorOliver Marriott <hello@omarriott.com>2023-09-21 15:53:05 +1000
committerOliver Marriott <hello@omarriott.com>2023-09-22 18:38:28 +1000
commitf413597f44f62a62675a3a7149e34a63f16e4821 (patch)
tree6459529aa172c375b5deb002acd5629efe3873fc /runtime/lua/vim/_editor.lua
parentf094db0e5ccaddca2b5db05bf9545d55f3eededf (diff)
downloadrneovim-f413597f44f62a62675a3a7149e34a63f16e4821.tar.gz
rneovim-f413597f44f62a62675a3a7149e34a63f16e4821.tar.bz2
rneovim-f413597f44f62a62675a3a7149e34a63f16e4821.zip
docs: clarify vim.schedule_wrap behaviour
- Remove the usage of the term "defer" to avoid confusion with `vim.defer_fn`, which also calls `vim.schedule_wrap` internally. - Explicitly state that `vim.schedule_wrap` returns a function in the text. - Mention that arguments are passed along. - Include a usage example. - Rename param to `fn`.
Diffstat (limited to 'runtime/lua/vim/_editor.lua')
-rw-r--r--runtime/lua/vim/_editor.lua19
1 files changed, 15 insertions, 4 deletions
diff --git a/runtime/lua/vim/_editor.lua b/runtime/lua/vim/_editor.lua
index 8322777633..e4a2dadb09 100644
--- a/runtime/lua/vim/_editor.lua
+++ b/runtime/lua/vim/_editor.lua
@@ -316,18 +316,29 @@ do
end
end
---- Defers callback `cb` until the Nvim API is safe to call.
+--- Returns a function which calls {fn} via |vim.schedule()|.
+---
+--- The returned function passes all arguments to {fn}.
+---
+--- Example:
+---
+--- ```lua
+--- function notify_readable(_err, readable)
+--- vim.notify("readable? " .. tostring(readable))
+--- end
+--- vim.uv.fs_access(vim.fn.stdpath("config"), "R", vim.schedule_wrap(notify_readable))
+--- ```
---
---@see |lua-loop-callbacks|
---@see |vim.schedule()|
---@see |vim.in_fast_event()|
----@param cb function
+---@param fn function
---@return function
-function vim.schedule_wrap(cb)
+function vim.schedule_wrap(fn)
return function(...)
local args = vim.F.pack_len(...)
vim.schedule(function()
- cb(vim.F.unpack_len(args))
+ fn(vim.F.unpack_len(args))
end)
end
end