Skip to content

Commit 5b9b6f6

Browse files
committed
feat(plenary): remove window
1 parent 2a86566 commit 5b9b6f6

3 files changed

Lines changed: 29 additions & 41 deletions

File tree

lua/neoplen/border.lua

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -273,22 +273,26 @@ function Border:new(content_bufnr, content_win_id, content_win_options, border_w
273273

274274
set_title_highlights(obj.bufnr, obj.title_ranges, obj._border_win_options.titlehighlight)
275275

276-
vim.cmd(
277-
string.format(
278-
"autocmd BufDelete <buffer=%s> ++nested ++once :lua require('neoplen.window').close_related_win(%s, %s)",
279-
content_bufnr,
280-
content_win_id,
281-
obj.win_id
282-
)
283-
)
284-
285-
vim.cmd(
286-
string.format(
287-
"autocmd WinClosed <buffer=%s> ++nested ++once :lua require('neoplen.window').try_close(%s, true)",
288-
content_bufnr,
289-
obj.win_id
290-
)
291-
)
276+
local augroup = api.nvim_create_augroup("neoplen.border", {})
277+
api.nvim_create_autocmd("BufDelete", {
278+
group = augroup,
279+
buffer = content_bufnr,
280+
once = true,
281+
nested = true,
282+
callback = function()
283+
pcall(api.nvim_win_close, content_win_id, true)
284+
pcall(api.nvim_win_close, obj.win_id, true)
285+
end,
286+
})
287+
api.nvim_create_autocmd("WinClosed", {
288+
group = augroup,
289+
buffer = content_bufnr,
290+
once = true,
291+
nested = true,
292+
callback = function()
293+
pcall(api.nvim_win_close, obj.win_id, true)
294+
end,
295+
})
292296

293297
setmetatable(obj, Border)
294298

lua/neoplen/popup.lua

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -219,15 +219,15 @@ function M.create(what, vim_options)
219219
-- TODO: Handle word, WORD, expr, and the range functions... which seem hard?
220220
end
221221
else
222-
local silent = false
223-
vim.cmd(
224-
string.format(
225-
"autocmd BufDelete %s <buffer=%s> ++once ++nested :lua require('neoplen.window').try_close(%s, true)",
226-
(silent and "<silent>") or "",
227-
bufnr,
228-
win_id
229-
)
230-
)
222+
api.nvim_create_autocmd("BufDelete", {
223+
group = api.nvim_create_augroup("neoplen.window", {}),
224+
buffer = bufnr,
225+
once = true,
226+
nested = true,
227+
callback = function()
228+
pcall(api.nvim_win_close, win_id, true)
229+
end,
230+
})
231231
end
232232

233233
-- Buffer Options

lua/neoplen/window.lua

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)