Skip to content

Commit 3b6e8eb

Browse files
Fix capture closing autocmds
1 parent 1acd23f commit 3b6e8eb

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

lua/orgmode/capture/init.lua

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ function Capture:open_template(template)
7676
vim.api.nvim_buf_set_var(0, 'org_capture', true)
7777
config:setup_mappings('capture')
7878

79-
vim.api.nvim_create_autocmd('BufWipeout', {
79+
self.wipeout_autocmd_id = vim.api.nvim_create_autocmd('BufWipeout', {
8080
buffer = 0,
8181
group = capture_augroup,
8282
callback = function()
@@ -118,11 +118,11 @@ function Capture:refile(confirm)
118118
self:_refile_to_end(file, lines)
119119
end
120120

121-
vim.api.nvim_create_autocmd('BufWipeout', {
122-
buffer = 0,
123-
group = capture_augroup,
124-
command = 'silent! wq',
125-
})
121+
if self.wipeout_autocmd_id then
122+
vim.api.nvim_del_autocmd(self.wipeout_autocmd_id)
123+
self.wipeout_autocmd_id = nil
124+
end
125+
vim.cmd('silent! wq')
126126
end, 0)
127127
end
128128

@@ -307,13 +307,11 @@ function Capture.autocomplete_refile(arg_lead)
307307
end
308308

309309
function Capture:kill()
310-
vim.api.nvim_create_autocmd('BufWipeout', {
311-
buffer = 0,
312-
group = capture_augroup,
313-
callback = function()
314-
return vim.api.nvim_win_close(0, true)
315-
end,
316-
})
310+
if self.wipeout_autocmd_id then
311+
vim.api.nvim_del_autocmd(self.wipeout_autocmd_id)
312+
self.wipeout_autocmd_id = nil
313+
end
314+
return vim.api.nvim_win_close(0, true)
317315
end
318316

319317
return Capture

0 commit comments

Comments
 (0)