mirror of
https://github.com/folke/snacks.nvim
synced 2025-08-05 03:08:13 +00:00
feat(bigfile): configurable average line length (default = 1000). Useful for minified files. Closes #576. Closes #372
This commit is contained in:
parent
1a30610ab7
commit
7fa92a2450
1 changed files with 10 additions and 6 deletions
|
@ -12,6 +12,7 @@ M.meta = {
|
|||
local defaults = {
|
||||
notify = true, -- show notification when big file detected
|
||||
size = 1.5 * 1024 * 1024, -- 1.5MB
|
||||
line_length = 1000, -- average line length (useful for minified files)
|
||||
-- Enable or disable features when big file detected
|
||||
---@param ctx {buf: number, ft:string}
|
||||
setup = function(ctx)
|
||||
|
@ -36,12 +37,15 @@ function M.setup()
|
|||
pattern = {
|
||||
[".*"] = {
|
||||
function(path, buf)
|
||||
return vim.bo[buf]
|
||||
and vim.bo[buf].filetype ~= "bigfile"
|
||||
and path
|
||||
and vim.fn.getfsize(path) > opts.size
|
||||
and "bigfile"
|
||||
or nil
|
||||
if not path or not buf or vim.bo[buf].filetype == "bigfile" then
|
||||
return
|
||||
end
|
||||
local size = vim.fn.getfsize(path)
|
||||
if size > opts.size then
|
||||
return "bigfile"
|
||||
end
|
||||
local lines = vim.api.nvim_buf_line_count(buf)
|
||||
return (size - lines) / lines > opts.line_length and "bigfile" or nil
|
||||
end,
|
||||
},
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue