[nvim] fix: correctly shorten "_XXX" elements in statusline
This commit is contained in:
parent
9aae779da4
commit
55c27719d3
@ -113,7 +113,11 @@ local function shorten_path(path, max_len)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local segment = segments[idx]
|
local segment = segments[idx]
|
||||||
local shortened = segment:sub(1, vim.startswith(segment, '.') and 2 or 1)
|
local short_end = 1
|
||||||
|
if (vim.startswith(segment, '.') or vim.startswith(segment, '_')) then
|
||||||
|
short_end = 2
|
||||||
|
end
|
||||||
|
local shortened = segment:sub(1, short_end)
|
||||||
segments[idx] = shortened
|
segments[idx] = shortened
|
||||||
len = len - (#segment - #shortened)
|
len = len - (#segment - #shortened)
|
||||||
end
|
end
|
||||||
@ -169,49 +173,48 @@ local function statusline_focused()
|
|||||||
local winwidth = vim.fn.winwidth(0)
|
local winwidth = vim.fn.winwidth(0)
|
||||||
|
|
||||||
local left = table.concat {
|
local left = table.concat {
|
||||||
gen_section(accent_color, { get_mode_display_name(mg) }),
|
gen_section(accent_color, { get_mode_display_name(mg) }),
|
||||||
gen_section("%#Middle#", { shorten_path(file, winwidth / 3) }),
|
gen_section("%#Middle#", { shorten_path(file, winwidth / 3) }),
|
||||||
gen_section("%#Bottom#", { "%m", "%r" }),
|
gen_section("%#Bottom#", { "%m", "%r" }),
|
||||||
gen_section(
|
gen_section(
|
||||||
"%#Alert#",
|
"%#Alert#",
|
||||||
{
|
{
|
||||||
process_diagnostics(
|
process_diagnostics(
|
||||||
globals.sign_error .. " ",
|
globals.sign_error .. " ",
|
||||||
diagnostics.error,
|
diagnostics.error,
|
||||||
"%#DiagnosticVirtualTextError#"
|
"%#DiagnosticVirtualTextError#"
|
||||||
),
|
),
|
||||||
process_diagnostics(
|
process_diagnostics(
|
||||||
globals.sign_warn .. " ",
|
globals.sign_warn .. " ",
|
||||||
diagnostics.warn,
|
diagnostics.warn,
|
||||||
"%#DiagnosticVirtualTextWarn#"
|
"%#DiagnosticVirtualTextWarn#"
|
||||||
),
|
),
|
||||||
process_diagnostics(
|
process_diagnostics(
|
||||||
globals.sign_info .. " ",
|
globals.sign_info .. " ",
|
||||||
diagnostics.info,
|
diagnostics.info,
|
||||||
"%#DiagnosticVirtualTextInfo#"
|
"%#DiagnosticVirtualTextInfo#"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
local right = table.concat {
|
local right = table.concat {
|
||||||
gen_section(
|
gen_section(
|
||||||
"%#Bottom#",
|
"%#Bottom#",
|
||||||
{
|
{
|
||||||
spell_check(),
|
spell_check(),
|
||||||
vim.bo.filetype
|
vim.bo.filetype
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
gen_section("%#Middle#", { "%03.p%%" }),
|
gen_section("%#Middle#", { "%03.p%%" }),
|
||||||
gen_section("%#Top#", { "-%03.c-" })
|
gen_section("%#Top#", { "-%03.c-" })
|
||||||
}
|
}
|
||||||
|
|
||||||
return table.concat {
|
return table.concat {
|
||||||
left,
|
left,
|
||||||
"%#Statusline#",
|
"%#Statusline#",
|
||||||
"%=",
|
"%=",
|
||||||
right
|
right
|
||||||
}
|
}
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function statusline_not_focused()
|
local function statusline_not_focused()
|
||||||
@ -219,14 +222,14 @@ local function statusline_not_focused()
|
|||||||
local file = vim.fn.expand("#" .. bufnr .. ":p:~")
|
local file = vim.fn.expand("#" .. bufnr .. ":p:~")
|
||||||
local winwidth = vim.fn.winwidth(0)
|
local winwidth = vim.fn.winwidth(0)
|
||||||
return table.concat {
|
return table.concat {
|
||||||
gen_section("%#StatuslineNF#", {
|
gen_section("%#StatuslineNF#", {
|
||||||
shorten_path(file, winwidth / 3),
|
shorten_path(file, winwidth / 3),
|
||||||
"%m"
|
"%m"
|
||||||
}),
|
}),
|
||||||
"%=",
|
"%=",
|
||||||
gen_section("%#StatuslineNF#", { "%03.p%%" }),
|
gen_section("%#StatuslineNF#", { "%03.p%%" }),
|
||||||
gen_section("%#StatuslineNF#", { "-%03.c-" })
|
gen_section("%#StatuslineNF#", { "-%03.c-" })
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
function _G.gen_statusline()
|
function _G.gen_statusline()
|
||||||
|
Reference in New Issue
Block a user