blob: 0705cbc74f3e484af02862c72e358165937fa298 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
local buffer = {}
buffer.cache = {}
---@return integer buf
buffer.get = function(name)
local buf = buffer.cache[name]
if buf and vim.api.nvim_buf_is_valid(buf) then
return buf
else
return nil
end
end
---@return integer buf
---@return boolean created_new
buffer.ensure = function(name)
local created_new = false
local buf = buffer.get(name)
if not buf then
created_new = true
buf = vim.api.nvim_create_buf(false, true)
buffer.cache[name] = buf
end
return buf, created_new
end
return buffer
|