Skip to content

Commit

Permalink
invalid buffer check
Browse files Browse the repository at this point in the history
  • Loading branch information
glepnir committed Apr 29, 2024
1 parent cae26f3 commit a73992f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
19 changes: 14 additions & 5 deletions lua/indentmini/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,21 @@ local config = {
}

local function indentline(opt)
local function invalid_buf(bufnr)
if
not vim.bo[bufnr].expandtab
or vim.tbl_contains({ 'nofile', 'terminal' }, vim.bo[bufnr].buftype)
or vim.tbl_contains(opt.exclude, vim.bo[bufnr].ft)
then
return true
end
end
config.virt_text = { { opt.char } }
local function on_line(_, _, bufnr, row)
if invalid_buf(bufnr) then
return
end

local indent = indent_fn(row + 1)
local ok, lines = pcall(api.nvim_buf_get_text, bufnr, row, 0, row, -1, {})
if not ok then
Expand Down Expand Up @@ -87,11 +100,7 @@ local function indentline(opt)

local function on_start(_, _)
local bufnr = api.nvim_get_current_buf()
if
not vim.bo[bufnr].expandtab
or vim.tbl_contains({ 'nofile', 'terminal' }, vim.bo[bufnr].buftype)
or vim.tbl_contains(opt.exclude, vim.bo[bufnr].ft)
then
if invalid_buf(bufnr) then
return false
end
end
Expand Down
1 change: 1 addition & 0 deletions test.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
local function test() end

0 comments on commit a73992f

Please sign in to comment.