Lazy buffer creation
This commit is contained in:
17
lua/cmp/utils/buffer.lua
Normal file
17
lua/cmp/utils/buffer.lua
Normal 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
|
||||
Reference in New Issue
Block a user