Closed tan-wei closed 10 months ago
Disable lualine intergration will work OK.
@tan-wei Could you share the configuration you were using when you got the error above please? 🙂
Feel strange. I can't reproduce this on my other computer, which uses an older version neovim and the same plugin versions.
If I reproduce this, I'll come back to reopen this.
Thanks.
I try to update madoicator.nvim to the latest commit, it is fixed. Really strange. But at last, it is fixed. :-P
Based on your error message my guess is that you had disabled the mode section (listed here) in your lualine.
I did push a fix handling that case yesterady in this commit: a9e99a5124f136a8daef3be8acb26dc4216c9e08
Could that be the reason why you got the error?
Hmm, thus I think the commit just ignored the error, not solved it.
Modicator fetches the mode colors from lualine's mode section. If lualine doesn't have a mode section, Modicator can't get its colors.
So the problem is why modicator.nvim
fail to get mode section when I've a mode section in lualine, see here.
OK, I see the code:
local function get_mode_section_name()
local sections = lualine.get_config().sections
for section, values in pairs(sections) do
if vim.tbl_contains(values, 'mode') then
return section
end
end
end
My configuration for lualine with mode section is a function mode
instead of string "mode". It is valid in lualine, but here it just checks values
coantin a string "mode". So how do we handle this?
local mode = {
"mode",
fmt = function(str)
return "-- " .. str .. " --"
end,
}
--[[
Other configurations
--]]
sections = {
lualine_a = { branch, diagnostics },
lualine_b = { mode },
lualine_c = { session, "lsp_progress" },
-- lualine_x = { "encoding", "fileformat", "filetype" },
lualine_x = { diff, spaces, "encoding", filetype },
lualine_y = { location },
lualine_z = { progress },
},
Ah that makes sense. I think I know a way to solve this.
@tan-wei Your use case should be supported now. Try it out and please let me know if it's working 🙂
But I've met this now:
Error detected while processing /home/winterreise/.config/nvim/init.lua:
E5113: Error while calling lua chunk: ...vim/lazy/modicator.nvim/lua/integration/lualine/init.lua:18: attempt to index local 'component' (a function value)
stack traceback:
...vim/lazy/modicator.nvim/lua/integration/lualine/init.lua:18: in function <...vim/lazy/modicator.nvim/lua/integration/lualine/init.lua:17>
vim/shared.lua: in function 'tbl_filter'
...vim/lazy/modicator.nvim/lua/integration/lualine/init.lua:17: in function 'get_mode_table'
...vim/lazy/modicator.nvim/lua/integration/lualine/init.lua:34: in function 'get_mode_section_name'
...vim/lazy/modicator.nvim/lua/integration/lualine/init.lua:55: in function 'use_lualine_mode_highlights'
...al/share/nvim/lazy/modicator.nvim/lua/modicator/init.lua:109: in function 'set_highlight_groups'
...al/share/nvim/lazy/modicator.nvim/lua/modicator/init.lua:171: in function 'setup'
/home/winterreise/.config/nvim/lua/user/modicator.lua:6: in main chunk
[C]: in function 'require'
@tan-wei This should be handled now as well 🙂
Sorry to tell you that a778174 still cause this problem:
Error detected while processing /home/winterreise/.config/nvim/init.lua:
E5113: Error while calling lua chunk: ...vim/lazy/modicator.nvim/lua/integration/lualine/init.lua:18: attempt to index local 'component' (a function value)
stack traceback:
...vim/lazy/modicator.nvim/lua/integration/lualine/init.lua:18: in function <...vim/lazy/modicator.nvim/lua/integration/lualine/init.lua:17>
vim/shared.lua: in function 'tbl_filter'
...vim/lazy/modicator.nvim/lua/integration/lualine/init.lua:17: in function 'get_mode_table'
...vim/lazy/modicator.nvim/lua/integration/lualine/init.lua:34: in function 'get_mode_section_name'
...vim/lazy/modicator.nvim/lua/integration/lualine/init.lua:55: in function 'use_lualine_mode_highlights'
...al/share/nvim/lazy/modicator.nvim/lua/modicator/init.lua:109: in function 'set_highlight_groups'
...al/share/nvim/lazy/modicator.nvim/lua/modicator/init.lua:171: in function 'setup'
/home/winterreise/.config/nvim/lua/user/modicator.lua:7: in main chunk
[C]: in function 'require'
/home/winterreise/.config/nvim/init.lua:82: in main chunk
And I find that, I can currently not use the mode
function and use "mode" string, but I find that modicator.nvim
can not get the highlight group from lualine, so it creates a new highlight group instead. :-(
@tan-wei That's my bad, I realize now that my fix didn't work, try it again now and see if it's solved 🙂
Yes, it is solved, now it will not cause error! But I don't think it works well, because the color of cursor line number does not change. Just like I said before. I try to debug the following code several hours ago:
M.use_lualine_mode_highlights = function()
local mode_section = get_mode_section_name()
-- If lualine doesn't have a `mode` section
if mode_section == nil then return end
for _, mode in pairs(lualine_modes) do
local lualine_hl_group = mode_section .. '_' .. mode
local lualine_mode_bg = get_highlight_bg(lualine_hl_group)
local mode_hl_group = uppercase_first_letter(mode) .. 'Mode'
if not highlight_exists(mode_hl_group) then
vim.api.nvim_set_hl(0, mode_hl_group, { fg = lualine_mode_bg })
end
end
end
So, we use lualine_mode_bg
to create several new highlight groups (NormalMode
, etc.), but I find lualine_mode_bg
is always 0. I think it is not correctly get from lualine. That's why now the color of cursor line number does not change. I could upload a screenshot then.
See the cursor number 13
:
Insert Mode:
Visual Mode:
Normal Mode:
I have now added the ability to manually specify the lualine section to use. This should hopefully solve your issue:
require('modicator').setup({
integration = {
lualine = {
mode_section = 'lualine_a',
},
},
})
So In my use case, it should be:
require('modicator').setup({
integration = {
lualine = {
mode_section = 'lualine_b',
},
},
})
Because I locate mode section in lualine_b
. However, nothing happens (hash: 1940afc3
)
Actually you don't have to specify the lualine section, but you do have to specify to use fg
instead of the default bg
(since that's how lualine_b
gets mode highlighted), which I just added support for as well:
require('modicator').setup({
integration = {
lualine = {
highlight = 'fg',
},
},
})
I use this configure, unfortunately, does not work:
modicator.setup {
show_warnings = false,
integration = {
lualine = {
-- mode_section = "lualine_b",
highlight = "fg",
},
},
}
If I disable lualine integration, modicator works (but the highlight is not the same with lualine).
@tan-wei Make sure that the plugins get loaded in the correct order: colorscheme, lualine.nvim, then modicator.nvim.
Also ensure that you have only one lualine section with the name mode
, otherwise modicator will pick one of them at random (if you haven't manually specified a section).
This config works for me:
local plugins = {
{
'mawkler/modicator.nvim',
dependencies = 'nvim-lualine/lualine.nvim',
init = function()
vim.o.cursorline = true
vim.o.number = true
vim.o.termguicolors = true
end,
config = function()
require('modicator').setup({
integration = {
lualine = {
enabled = true,
highlight = 'fg',
},
},
})
end,
},
{
'nvim-lualine/lualine.nvim',
dependencies = 'Shatur/neovim-ayu',
config = function()
local mode = {
'mode',
fmt = function(str)
return '-- ' .. str .. ' --'
end,
}
require('lualine').setup({
sections = {
lualine_a = {},
lualine_b = { mode },
},
})
end,
},
{
'Shatur/neovim-ayu',
config = function()
require('ayu').setup({ options = { theme = 'ayu' } })
vim.cmd.colorscheme('ayu')
end,
}
}
require('lazy').setup(plugins)
OK, I think my random choice from several colorschemes make it does not work. Thanks!!!