From f05d2ec1423b5d0729e34a1d0f9872eaf497f3ba Mon Sep 17 00:00:00 2001 From: ray-x Date: Thu, 4 Aug 2022 19:17:00 +1000 Subject: [PATCH] lint, expand tab to space for treesitter folding --- lua/navigator/foldts.lua | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lua/navigator/foldts.lua b/lua/navigator/foldts.lua index 2a2e188..ec16cb8 100644 --- a/lua/navigator/foldts.lua +++ b/lua/navigator/foldts.lua @@ -21,7 +21,12 @@ function NG_custom_fold_text() local line = vim.fn.getline(vim.v.foldstart) local line_count = vim.v.foldend - vim.v.foldstart + 1 -- log("" .. line .. " // " .. line_count .. " lines") - return ' ⚡' .. line .. ': ' .. line_count .. ' lines' + local ss, se = line:find('^%s*') + local spaces = line:sub(ss, se) + local tabspace = string.rep(' ', vim.o.tabstop) + spaces = spaces:gsub('\t', tabspace) + line = line:gsub('^%s*(.-)%s*$', '%1') + return spaces .. '⚡' .. line .. ': ' .. line_count .. ' lines' end vim.opt.foldtext = NG_custom_fold_text() @@ -220,7 +225,7 @@ function M.get_fold_indic(lnum) local buf = api.nvim_get_current_buf() local shown = false for i = 1, vim.fn.tabpagenr('$') do - for key, value in pairs(vim.fn.tabpagebuflist(i)) do + for _, value in pairs(vim.fn.tabpagebuflist(i)) do if value == buf then shown = true end