From a73992f7366d2c0af639a6c0d2bf381feea41e80 Mon Sep 17 00:00:00 2001 From: glepnir Date: Mon, 29 Apr 2024 19:21:08 +0800 Subject: [PATCH] invalid buffer check --- lua/indentmini/init.lua | 19 ++++++++++++++----- test.lua | 1 + 2 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 test.lua diff --git a/lua/indentmini/init.lua b/lua/indentmini/init.lua index b504898..0530d14 100644 --- a/lua/indentmini/init.lua +++ b/lua/indentmini/init.lua @@ -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 @@ -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 diff --git a/test.lua b/test.lua new file mode 100644 index 0000000..c98d6e0 --- /dev/null +++ b/test.lua @@ -0,0 +1 @@ +local function test() end