diff options
Diffstat (limited to 'runtime/lua/vim/_editor.lua')
-rw-r--r-- | runtime/lua/vim/_editor.lua | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/runtime/lua/vim/_editor.lua b/runtime/lua/vim/_editor.lua index 0215cae0cb..7f09fc8038 100644 --- a/runtime/lua/vim/_editor.lua +++ b/runtime/lua/vim/_editor.lua @@ -29,6 +29,7 @@ for k, v in pairs({ treesitter = true, filetype = true, loader = true, + func = true, F = true, lsp = true, highlight = true, @@ -315,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 @@ -876,7 +888,7 @@ end --- Example: --- --- ```lua ---- local hl_normal = vim.print(vim.api.nvim_get_hl_by_name('Normal', true)) +--- local hl_normal = vim.print(vim.api.nvim_get_hl(0, { name = 'Normal' })) --- ``` --- --- @see |vim.inspect()| |