feat(bigfile): show message when bigfile was detected

This commit is contained in:
Folke Lemaitre 2024-11-05 22:51:22 +01:00
parent e6c18f17c8
commit fdc0d3d1f8
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040

View file

@ -3,12 +3,13 @@ local M = {}
---@class snacks.bigfile.Config
local defaults = {
notify = true,
size = 1.5 * 1024 * 1024, -- 1.5MB
---@param ev {buf: number, ft:string}
behave = function(ev)
---@param ctx {buf: number, ft:string}
setup = function(ctx)
vim.b.minianimate_disable = true
vim.schedule(function()
vim.bo[ev.buf].syntax = ev.ft
vim.bo[ctx.buf].syntax = ctx.ft
end)
end,
}
@ -35,8 +36,15 @@ function M.setup()
group = vim.api.nvim_create_augroup("snacks_bigfile", { clear = true }),
pattern = "bigfile",
callback = function(ev)
if opts.notify then
local path = vim.fn.fnamemodify(vim.api.nvim_buf_get_name(ev.buf), ":p:~:.")
Snacks.notify.warn({
("Big file detected `%s`."):format(path),
"Some Neovim features have been **disabled**.",
}, { title = "Big File" })
end
vim.api.nvim_buf_call(ev.buf, function()
opts.behave({
opts.setup({
buf = ev.buf,
ft = vim.filetype.match({ buf = ev.buf }) or "",
})