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 = {
|
local defaults = {
|
||||||
notify = true, -- show notification when big file detected
|
notify = true, -- show notification when big file detected
|
||||||
size = 1.5 * 1024 * 1024, -- 1.5MB
|
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
|
-- Enable or disable features when big file detected
|
||||||
---@param ctx {buf: number, ft:string}
|
---@param ctx {buf: number, ft:string}
|
||||||
setup = function(ctx)
|
setup = function(ctx)
|
||||||
|
@ -36,12 +37,15 @@ function M.setup()
|
||||||
pattern = {
|
pattern = {
|
||||||
[".*"] = {
|
[".*"] = {
|
||||||
function(path, buf)
|
function(path, buf)
|
||||||
return vim.bo[buf]
|
if not path or not buf or vim.bo[buf].filetype == "bigfile" then
|
||||||
and vim.bo[buf].filetype ~= "bigfile"
|
return
|
||||||
and path
|
end
|
||||||
and vim.fn.getfsize(path) > opts.size
|
local size = vim.fn.getfsize(path)
|
||||||
and "bigfile"
|
if size > opts.size then
|
||||||
or nil
|
return "bigfile"
|
||||||
|
end
|
||||||
|
local lines = vim.api.nvim_buf_line_count(buf)
|
||||||
|
return (size - lines) / lines > opts.line_length and "bigfile" or nil
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue