Skip to content

Commit

Permalink
feat(bigfile): show message when bigfile was detected
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Nov 5, 2024
1 parent e6c18f1 commit fdc0d3d
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions lua/snacks/bigfile.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand All @@ -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 "",
})
Expand Down

0 comments on commit fdc0d3d

Please sign in to comment.