From 20bfdbe83253cf5ec0a42bd75bd4ed7df945ab37 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Tue, 1 Aug 2023 11:12:00 +0100 Subject: docs(builtin): right align tags (#24522) --- scripts/gen_eval_files.lua | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) (limited to 'scripts/gen_eval_files.lua') diff --git a/scripts/gen_eval_files.lua b/scripts/gen_eval_files.lua index ee8bbe48a3..0b845fb246 100755 --- a/scripts/gen_eval_files.lua +++ b/scripts/gen_eval_files.lua @@ -113,6 +113,31 @@ end --- @type table local rendered_tags = {} +--- @param name string +--- @param fun vim.EvalFn +--- @param write fun(line: string) +local function render_sig_and_tag(name, fun, write) + local tags = { '*' .. name .. '()*' } + + if fun.tags then + for _, t in ipairs(fun.tags) do + tags[#tags + 1] = '*' .. t .. '*' + end + end + + local tag = table.concat(tags, ' ') + local siglen = #fun.signature + local conceal_offset = 2*(#tags - 1) + local tag_pad_len = math.max(1, 80 - #tag + conceal_offset) + + if siglen + #tag > 80 then + write(string.rep(' ', tag_pad_len) .. tag) + write(fun.signature) + else + write(string.format('%s%s%s', fun.signature, string.rep(' ', tag_pad_len - siglen), tag)) + end +end + --- @param f string --- @param fun vim.EvalFn --- @param write fun(line: string) @@ -133,27 +158,13 @@ local function render_eval_doc(f, fun, write) end local name = fun.name or f - local tags = { '*' .. name .. '()*' } - if fun.tags then - for _, t in ipairs(fun.tags) do - tags[#tags + 1] = '*' .. t .. '*' - end - end - local tag = table.concat(tags, ' ') - local siglen = #fun.signature if rendered_tags[name] then write(fun.signature) else - if siglen + #tag > 80 then - write(string.rep('\t', 6) .. tag) - write(fun.signature) - else - local tt = math.max(1, (76 - siglen - #tag) / 8) - write(string.format('%s%s%s', fun.signature, string.rep('\t', tt), tag)) - end + render_sig_and_tag(name, fun, write) + rendered_tags[name] = true end - rendered_tags[name] = true desc = vim.trim(desc) local desc_l = vim.split(desc, '\n', { plain = true }) -- cgit