Lazy buffer creation

This commit is contained in:
hrsh7th
2021-10-10 13:57:37 +09:00
parent d901dae302
commit 0a31d67219
4 changed files with 39 additions and 34 deletions

17
lua/cmp/utils/buffer.lua Normal file
View File

@@ -0,0 +1,17 @@
local buffer = {}
buffer.ensure = setmetatable({
cache = {}
}, {
__call = function(self, name)
if not (self.cache[name] and vim.api.nvim_buf_is_valid(self.cache[name])) then
local buf = vim.api.nvim_create_buf(false, true)
vim.api.nvim_buf_set_option(buf, 'buftype', 'nofile')
vim.api.nvim_buf_set_option(buf, 'bufhidden', 'hide')
self.cache[name] = buf
end
return self.cache[name]
end
})
return buffer