Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems when sourcing the cokeline config file #160

Closed
stankovictab opened this issue Sep 8, 2023 · 13 comments
Closed

Problems when sourcing the cokeline config file #160

stankovictab opened this issue Sep 8, 2023 · 13 comments

Comments

@stankovictab
Copy link

The error message is the following.

Error detected while processing /home/stankovictab/.dotfiles/.config/nvim/lua/stankovictab/specifics/cokeline.lua:
E5113: Error while calling lua chunk: ...ocal/share/nvim/lazy/nvim-cokeline/lua/cokeline/init.lua:12: attempt to call field 'setup' (a nil value)
stack traceback:
        ...ocal/share/nvim/lazy/nvim-cokeline/lua/cokeline/init.lua:12: in function 'setup'
        ...les/.config/nvim/lua/stankovictab/specifics/cokeline.lua:11: in main chunk

Here's my config file copy pasted, sorry for the comments.

-- This cokeline config file needs to be re-sourced every time you change a theme, or else the colors won't change, the issue is known (#72)
-- To get around this, you can either bind the sourcing to a key so that you manually refresh it,
-- or you can actually use NeoVim like you're supposed to, and use the following autocommand
local group = vim.api.nvim_create_augroup("Alo Bre", { clear = true }) -- A group with clear on true is created so that the autocmd isn't being duplicated on every run in the :autocmd ColorScheme list
vim.api.nvim_create_autocmd("ColorScheme",
	{ command = "source ~/.config/nvim/lua/stankovictab/specifics/cokeline.lua", group = group })
-- This also fixes the issue of cokeline taking the highlights of the default NeoVim theme on startup, as it's config is sourced in plugins.lua and not at the end of themes.lua, where the new colorscheme actually gets applied (doesn't matter, this works)

local get_hex = require('cokeline/utils').get_hex

require('cokeline').setup({
	show_if_buffers_are_at_least = 2, -- Don't show if there's only one buffer

	mappings = {
		cycle_prev_next = true,
	},

	default_hl = {
		fg = function(buffer)
			return
				buffer.is_focused and nil or get_hex("Comment", "fg")
		end,
		bg = get_hex("NormalFloat", "bg")
	},

	sidebar = {
		filetype = 'NvimTree',
		components = {
			{
				text = '           NvimTree',
				fg = get_hex("Boolean", "fg"),
				bg = get_hex("NormalFloat", "bg"),
				style = 'bold',
			},
		}
	},

	components = {
		{ text = " " }, -- Adjust the padding here
		{
			text = function(buffer)
				return buffer.devicon.icon
			end,
			fg = function(buffer)
				return buffer.devicon.color
			end
		},
		{
			-- Unique prefix is for when you have multiple buffers with the same name, so you print the parent directory beforehand
			text = function(buffer)
				return buffer.unique_prefix
			end,
			fg = function(buffer)
				if buffer.is_focused then
					return get_hex("Comment", "fg")
				else
					return get_hex("Comment", "fg")
				end
			end,
			style = "italic",
		},
		{
			text = function(buffer)
				return buffer.filename
			end,
			fg = function(buffer)
				if buffer.is_focused then
					return get_hex("Boolean", "fg")
				else
					return get_hex("Comment", "fg")
				end
			end,
			style = function(buffer)
				if buffer.is_focused then
					return "bold,underline" -- Can be "underline,bold", for example
				end
				return nil
			end
		},
		{
			text = function(buffer)
				if buffer.is_modified then
					return ""
				else
					return " "
				end
			end,
			fg = get_hex("Warnings", "fg")
		},
		{
			text = function(buffer)
				if buffer.is_readonly then
					return ""
				end
				return ""
			end,
			fg = get_hex("Warnings", "fg")
		},
		{ text = " " },
	}
})
@willothy
Copy link
Owner

willothy commented Sep 8, 2023

Thanks for reporting! Mind providing some more info such as the version of Neovim are you using?

@stankovictab
Copy link
Author

Of course. I'm on Nobara Linux (Fedora basically), installed through standard dnf.

NVIM v0.9.1
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilation: /usr/bin/gcc -O2 -g -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wvla -Wdouble-promotion -Wmissing-noreturn -Wmissing-format-attribute -Wmissing-prototypes -fno-common -Wno-unused-result -Wimplicit-fallthrough -fdiagnostics-color=auto -fstack-protector-strong -DUNIT_TESTING -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -I/usr/include/luajit-2.1 -I/usr/include -I/usr/include/luv -I/builddir/build/BUILD/neovim-0.9.1/redhat-linux-build/src/nvim/auto -I/builddir/build/BUILD/neovim-0.9.1/redhat-linux-build/include -I/builddir/build/BUILD/neovim-0.9.1/redhat-linux-build/cmake.config -I/builddir/build/BUILD/neovim-0.9.1/src -I/usr/include -I/usr/include -I/usr/include -I/usr/include -I/usr/include -I/usr/include -I/usr/include

@willothy
Copy link
Owner

willothy commented Sep 8, 2023

Thanks! This is super weird because the function called on that line exists, looking into it right now.

@stankovictab
Copy link
Author

Thanks for trying to fix this so quickly.
I guess it might have something to do with other parts of my config, so if you need it, here's my entire neovim config.
https://github.com/stankovictab/.dotfiles/tree/main/.config/nvim

@willothy
Copy link
Owner

willothy commented Sep 8, 2023

Sure! Thanks, I'll look at that as well.

Also, just a note, get_hex is deprecated, you should use require("cokeline.hlgroups").get_hl(group) and require("cokeline.hlgroups").get_hl_attr(group, attr), as these are built with the nvim API instead of vimscript calls and work more consistently.

@willothy
Copy link
Owner

willothy commented Sep 8, 2023

I know the docs may say otherwise in some places, I'm still working on getting everything updated. Sorry about that!

@willothy
Copy link
Owner

willothy commented Sep 8, 2023

I'm quite confused to be honest, cant repro with your minimal config

@stankovictab
Copy link
Author

Yeah, I've tried replacing it with that function, still the same.
Another error I just found - when changing the colorscheme, I have an autocommand that resources the cokeline config file, maybe this traceback helps.
I've installed nvim on a clean system so this is pretty weird to see :/

Screenshot_20230908_135321

@willothy
Copy link
Owner

willothy commented Sep 8, 2023

You don't need to re-source the file on colorscheme change anymore, as of #150. All highlights are cached and the cache is cleared using the ColorScheme autocmd.

And I wasn't saying that not using get_hex would fix this error, but you shouldn't use it either way, it will be removed soon as it is not as reliable as the nvim API and uses string values for gui attributes.

@willothy
Copy link
Owner

willothy commented Sep 8, 2023

I will keep looking into this later, but given that that function exists and I can't reproduce with your minimal config, I'm almost positive that the issue is related to your nvim config.

@stankovictab
Copy link
Author

Completely understandable! I'll keep digging, if I find out I'll close this issue, but in the meantime I'll keep it open in case someone else had it too.

@willothy
Copy link
Owner

willothy commented Sep 8, 2023

Totally! If I find anything I'll update here as well.

@willothy
Copy link
Owner

willothy commented Oct 3, 2023

Closing as this doesn't seem to be an issue with cokeline.

@willothy willothy closed this as completed Oct 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants