galaxyline.nvim
galaxyline.nvim copied to clipboard
Settings getting cached somehow?
I'm using a configuration I've taken from NvChad and edited a bit.
The main thing i've done is create a status item on the left side that represents the vim mode. There is already an item on the right side that does this, but I wanted to create a symbol based one.
gls.left[2] = {
viMode_icon = {
provider = function()
local alias = {
n = "Normal",
i = "Insert",
c = "Command",
V = "VisualLine",
[''] = "VisualBlock",
[''] = "SelectBlock",
v = "Visual",
--[[ R = "Replace",
Rv = "VReplace",
ce = "Ex",
cv = "VimEx",
r = "Prompt",
rm = "More", ]]
}
local current_Mode = alias[vim.fn.mode()]
if current_Mode == "Normal" then
return " "
elseif current_Mode == "Insert" then
return " "
elseif current_Mode == "Visual" then
return " "
elseif current_Mode == "VisualLine" then
return " "
elseif current_Mode == "VisualBlock" then
return " "
elseif current_Mode == "Replace" then
return ""
elseif current_Mode == "Command" then
return ""
else
return "? "
-- return current_Mode
end
end,
separator = " ",
-- highlight = {colors.statusline_bg, colors.red},
highlight = 'StatusLine',
separator_highlight = {colors.red, colors.statusline_bg}
}
}
Here is a shot of the left side of the bar when I open an empty buffer
My Issue
At one point when I was testing the above function, the function returned the
character instead of the question mark (a relic from the original function I copied). But now, even after I've long removed that line, I'm still seeing it when I should be seeing the correct indicators for Normal mode, etc.
Here I've opened up an existing file in the same folder as before, and I'm still seeing the wind symbol?!?!?
What's more, I was able to change the highlight
option for that block and the change was immediately reflected by turning the symbol red. Why is it not respecting the actual characters?
I think I just got very similar problem to yours and also trying to find out where the settings could be cached. I am updating the configuration and when I run nvim with galaxyline there is like 50 % change of getting the provider executed :thinking:. For example given this peace of code in FileName provider:
local long_fname = vim.fn.fnamemodify(vim.fn.expand("%"), ":~:.")
print(file_long_name_at_least_width + string.len(long_fname))
if wide_enough(file_long_name_at_least_width + string.len(long_fname)) then
fname = long_fname
else
fname = vim.fn.expand("%:t")
end
sometimes it executes, prints the width and file is correctly expanded and sometimes there is just short version (which was previous configuration to show just short version e.g. filename). The filename is constant and screen is way wider than needed for the condition :thinking:
ok, my problem was in naming actual components with the same name as in different parts of galaxyline ( I had FileName
component in left
and also in short_line_right
and also this is name of builtin ) and according to source code the component existence is checked here with this function:
local function check_component_exists(component_name)
for _,pos_value in pairs(M.section) do
for _,v in pairs(pos_value) do
if v[component_name] ~= nil then
return true,v[component_name]
end
end
end
return false,nil
end
which iterates over all sections and try to find first match (although I am not exactly sure yet how did builtin function get there because apparently my FileIcon
provider did not really work :thinking: ).