File tree Expand file tree Collapse file tree 3 files changed +16
-9
lines changed
Expand file tree Collapse file tree 3 files changed +16
-9
lines changed Original file line number Diff line number Diff line change 1- *guard.nvim.txt* For NVIM v0.8.0 Last change: 2024 December 03
1+ *guard.nvim.txt* For NVIM v0.8.0 Last change: 2024 December 07
22
33==============================================================================
44Table of Contents *guard.nvim-table-of-contents*
Original file line number Diff line number Diff line change @@ -8,14 +8,7 @@ local M = {}
88M .group = api .nvim_create_augroup (' Guard' , { clear = true })
99
1010function M .try_attach_to_buf (buf )
11- if
12- # api .nvim_get_autocmds ({
13- group = M .group ,
14- event = ' BufWritePre' ,
15- buffer = buf ,
16- }) > 0
17- then
18- -- already attached
11+ if not util .check_should_attach (buf ) then
1912 return
2013 end
2114 au (' BufWritePre' , {
Original file line number Diff line number Diff line change 8383--- @param filename string
8484--- @return string | false
8585local function exists (filename )
86+ --- @diagnostic disable-next-line : undefined-field
8687 local stat = vim .uv .fs_stat (filename )
8788 return stat and stat .type or false
8889end
132133--- @return string , string ?
133134function M .buf_get_info (buf )
134135 local fname = vim .fn .fnameescape (api .nvim_buf_get_name (buf ))
136+ --- @diagnostic disable-next-line : undefined-field
135137 return fname , M .get_lsp_root () or vim .uv .cwd ()
136138end
137139
@@ -215,4 +217,16 @@ function M.eval(xs)
215217 end , xs )
216218end
217219
220+ --- @param buf number
221+ --- @return boolean
222+ function M .check_should_attach (buf )
223+ local bo = vim .bo [buf ]
224+ -- check if it's not attached already and has an underlying file
225+ return # api .nvim_get_autocmds ({
226+ group = M .group ,
227+ event = ' BufWritePre' ,
228+ buffer = buf ,
229+ }) == 0 and bo .buftype ~= ' nofile'
230+ end
231+
218232return M
You can’t perform that action at this time.
0 commit comments