@@ -123,16 +123,31 @@ M.activate = function(languages, completion, diagnostics, tsquery)
123
123
table.insert (keeper .rafts [main_nr ].languages , lang )
124
124
125
125
if config .cfg .buffers .write_to_disk then
126
+ -- closure to clean up this otter buffer and file
127
+ local cleanup = function (ev )
128
+ if api .nvim_buf_is_loaded (otter_nr ) then
129
+ api .nvim_buf_delete (otter_nr , { force = true })
130
+ vim .fn .delete (otter_path )
131
+ end
132
+ end
126
133
-- remove otter buffer when main buffer is closed
127
- api .nvim_create_autocmd ({ " QuitPre " , " BufDelete" }, {
134
+ api .nvim_create_autocmd ({ " BufDelete" }, {
128
135
buffer = main_nr ,
129
- group = api .nvim_create_augroup (" OtterAutoclose" .. otter_nr , {}),
130
- callback = function (_ , _ )
131
- if api .nvim_buf_is_loaded (otter_nr ) then
132
- api .nvim_buf_delete (otter_nr , { force = true })
133
- vim .fn .delete (otter_path )
134
- end
135
- end ,
136
+ group = api .nvim_create_augroup (" OtterAutocloseOnMainDelete" .. otter_nr , {}),
137
+ callback = cleanup
138
+ })
139
+ -- Remove otter buffer before exiting, preventing unsaved otter
140
+ -- buffers from triggering a 'No write since last change' message.
141
+ -- Must be a separate autocmd that is not attached to buffer = main_nr
142
+ -- because the active buffer may be different from the main buffer when
143
+ -- exiting.
144
+ -- Must be ExitPre, not QuitPre, because QuitPre also triggers when a
145
+ -- window with the main buffer is closed, even though the
146
+ -- buffer may still be loaded in another window.
147
+ api .nvim_create_autocmd ({ " ExitPre" }, {
148
+ pattern = " *" ,
149
+ group = api .nvim_create_augroup (" OtterAutocloseOnQuit" .. otter_nr , {}),
150
+ callback = cleanup
136
151
})
137
152
-- write to disk when main buffer is written
138
153
api .nvim_create_autocmd (" BufWritePost" , {
@@ -141,7 +156,7 @@ M.activate = function(languages, completion, diagnostics, tsquery)
141
156
callback = function (_ , _ )
142
157
if api .nvim_buf_is_loaded (otter_nr ) then
143
158
api .nvim_buf_call (otter_nr , function ()
144
- vim .cmd (" write! " .. otter_path )
159
+ vim .cmd (" silent write! " .. otter_path )
145
160
end )
146
161
end
147
162
end ,
@@ -170,7 +185,7 @@ M.activate = function(languages, completion, diagnostics, tsquery)
170
185
-- and also write out once before lsps can complain
171
186
local otter_path = keeper .rafts [main_nr ].paths [lang ]
172
187
api .nvim_buf_call (otter_nr , function ()
173
- vim .cmd (" write! " .. otter_path )
188
+ vim .cmd (" silent write! " .. otter_path )
174
189
end )
175
190
end
176
191
0 commit comments