Skip to content

Commit 01bc09f

Browse files
fix: multiple au attached to one buf (#117)
* initial commit * fix: dup au
1 parent 9d3e669 commit 01bc09f

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

lua/guard/events.lua

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,15 @@ local function watch_ft(fts)
88
group = group,
99
pattern = fts,
1010
callback = function(args)
11-
format.attach_to_buf(args.buf)
11+
if
12+
#api.nvim_get_autocmds({
13+
group = group,
14+
event = 'BufWritePre',
15+
buffer = args.buf,
16+
}) == 0
17+
then
18+
format.attach_to_buf(args.buf)
19+
end
1220
end,
1321
desc = 'guard',
1422
})

lua/guard/format.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,11 @@ local function attach_to_buf(buf)
211211
api.nvim_create_autocmd('BufWritePre', {
212212
group = require('guard.events').group,
213213
buffer = buf,
214-
callback = function(opt)
215-
if not vim.bo[opt.buf].modified then
214+
callback = function()
215+
if not vim.bo[buf].modified then
216216
return
217217
end
218-
require('guard.format').do_fmt(opt.buf)
218+
require('guard.format').do_fmt(buf)
219219
end,
220220
})
221221
end

0 commit comments

Comments
 (0)