mirror of
https://codeberg.org/leana8959/.files.git
synced 2025-12-06 06:39:14 +00:00
nvim: once helper
This commit is contained in:
parent
a7ebfdd5f5
commit
b9fae994cb
1 changed files with 15 additions and 0 deletions
15
.config/nvim/lua/once.lua
Normal file
15
.config/nvim/lua/once.lua
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
-- A helper that prevents something to be loaded more than once
|
||||||
|
M = {}
|
||||||
|
|
||||||
|
---@param label string
|
||||||
|
---@param callback function
|
||||||
|
function M.test_and_load(label, callback)
|
||||||
|
local once = vim.g.once or {}
|
||||||
|
if not once[label] then
|
||||||
|
callback()
|
||||||
|
once[label] = true
|
||||||
|
vim.g.once = once
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
||||||
Loading…
Add table
Add a link
Reference in a new issue