Skip to content

Commit

Permalink
Add columns limit file
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisands committed Jan 17, 2025
1 parent 71f69e5 commit b6e1e4a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/snacks-bigfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ mini.animate <https://github.com/echasnovski/mini.animate> (if used)
{
notify = true, -- show notification when big file detected
size = 1.5 * 1024 * 1024, -- 1.5MB
columns = 500,
-- Enable or disable features when big file detected
---@param ctx {buf: number, ft:string}
setup = function(ctx)
Expand Down
1 change: 1 addition & 0 deletions docs/bigfile.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ The default implementation enables `syntax` for the buffer and disables
{
notify = true, -- show notification when big file detected
size = 1.5 * 1024 * 1024, -- 1.5MB
columns = 500,
-- Enable or disable features when big file detected
---@param ctx {buf: number, ft:string}
setup = function(ctx)
Expand Down
16 changes: 15 additions & 1 deletion lua/snacks/bigfile.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ M.meta = {
local defaults = {
notify = true, -- show notification when big file detected
size = 1.5 * 1024 * 1024, -- 1.5MB
columns = 500,
-- Enable or disable features when big file detected
---@param ctx {buf: number, ft:string}
setup = function(ctx)
Expand All @@ -34,10 +35,23 @@ function M.setup()
pattern = {
[".*"] = {
function(path, buf)
local columns_exceed_limit = false

local status, file = pcall(io.open, path, "r")
if status ~= nil and file ~= nil then
for line in file:lines() do
if #line > opts.columns then
columns_exceed_limit = true
file:close()
break
end
end
end

return vim.bo[buf]
and vim.bo[buf].filetype ~= "bigfile"
and path
and vim.fn.getfsize(path) > opts.size
and (vim.fn.getfsize(path) > opts.size or columns_exceed_limit)
and "bigfile"
or nil
end,
Expand Down

0 comments on commit b6e1e4a

Please sign in to comment.