From 6b989ef361ce9351e8f91240bcf956ed0dc51a52 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Fri, 21 Oct 2022 11:51:17 +0800 Subject: [PATCH] feat(todo): add max_len function --- lua/spacevim/plugin/todo.lua | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lua/spacevim/plugin/todo.lua b/lua/spacevim/plugin/todo.lua index c642c39e8..d73f1ac6c 100644 --- a/lua/spacevim/plugin/todo.lua +++ b/lua/spacevim/plugin/todo.lua @@ -107,14 +107,23 @@ local function compare_todo(a, b) -- {{{ end -- }}} +local function max_len(t, k) -- {{{ + local l = 0 + for _, v in ipairs(t) do + l = math.max(#v[k], l) + end + return l +end +-- }}} + function exit(id, data, event) -- {{{ if id ~= todo_jobid then return end logger.info('todomanager job exit with:' .. data) table.sort(todos, compare_todo) - local lw = 15 - local fw = 50 + local lw = max_len(todos, 'label') + 1 + local fw = max_len(todos, 'file') + 1 local lines = {} for _, v in ipairs(todos) do table.insert(lines,