@@ -273,24 +273,35 @@ end
273
273
274
274
--- @param winid number
275
275
--- @param bufnr number
276
- --- @return Image[] | false result Images if the buffer was successfully hijacked, otherwise false
276
+ --- @return boolean hijacked Whether the buffer was successfully hijacked.
277
277
local function try_load_image_nvim_buf (winid , bufnr )
278
278
-- notify only image.nvim to let it try and hijack
279
+ local image_augroup = vim .api .nvim_create_augroup (" image.nvim" , { clear = false })
280
+ if # vim .api .nvim_get_autocmds ({ group = image_augroup }) == 0 then
281
+ local image_available , image = pcall (require , " image" )
282
+ if not image_available then
283
+ local image_nvim_url = " https://github.com/3rd/image.nvim"
284
+ log .debug (" You'll need to install image.nvim to use this command: " .. image_nvim_url )
285
+ return false
286
+ end
287
+ log .warn (" image.nvim was not setup. Calling require('image').setup()." )
288
+ image .setup ()
289
+ image_augroup = vim .api .nvim_create_augroup (" image.nvim" , { clear = false })
290
+ end
291
+
279
292
vim .opt .eventignore :remove (" BufWinEnter" )
280
- vim .api .nvim_win_call ( winid , function ()
281
- vim .api .nvim_exec_autocmds (" BufWinEnter" , { group = " image.nvim " , buffer = bufnr })
293
+ local ok = pcall ( vim .api .nvim_win_call , winid , function ()
294
+ vim .api .nvim_exec_autocmds (" BufWinEnter" , { group = image_augroup , buffer = bufnr })
282
295
end )
283
296
vim .opt .eventignore :append (" BufWinEnter" )
284
- if vim .bo [bufnr ].filetype ~= " image_nvim" then
297
+ if not ok then
298
+ log .debug (" image.nvim doesn't have any file patterns to hijack." )
285
299
return false
286
300
end
287
- local success , mod = pcall (require , " image" )
288
- if not success or not mod .hijack_buffer then
289
- local image_nvim_url = " https://github.com/3rd/image.nvim"
290
- log .debug (" You'll need to install image.nvim to use this command: " .. image_nvim_url )
301
+ if vim .bo [bufnr ].filetype ~= " image_nvim" then
291
302
return false
292
303
end
293
- return mod . get_images ({ buffer = bufnr , window = winid })
304
+ return true
294
305
end
295
306
296
307
--- Set the buffer in the preview window without executing BufEnter or BufWinEnter autocommands.
0 commit comments