From b9fae994cb2ea78da014fabd73b715e9f31a0bcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9ana=20=E6=B1=9F?= Date: Mon, 28 Jul 2025 00:23:02 +0200 Subject: [PATCH] nvim: once helper --- .config/nvim/lua/once.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 .config/nvim/lua/once.lua diff --git a/.config/nvim/lua/once.lua b/.config/nvim/lua/once.lua new file mode 100644 index 00000000..a3979b24 --- /dev/null +++ b/.config/nvim/lua/once.lua @@ -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