-
Notifications
You must be signed in to change notification settings - Fork 10
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
feat(colors): optionally get the cursor color from the hl group at the cursor #30
Conversation
lua/smear_cursor/color.lua
Outdated
local cursor = vim.api.nvim_win_get_cursor(0) | ||
local ts_hl_group ---@type string? | ||
for _, capture in pairs(vim.treesitter.get_captures_at_pos(0, cursor[1] - 1, cursor[2])) do | ||
ts_hl_group = "@" .. capture.capture .. "." .. capture.lang |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to loop over all captures. The last one is the one we want, so no early break
here.
} | ||
or { | ||
fg = _cursor_color, | ||
bg = "none", -- _normal_bg, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the old code, for level=0, it used to be "none" and for level>0 it was _normal_bg.
I assume this was a bug? And you always want none
here?
This comment was marked as resolved.
This comment was marked as resolved.
That issue is now fixed. |
Added support for both treesitter and extmarks |
converted to draft again. Need to optimize the code a bit first |
Thanks a lot, it works great! |
When
cursor_color = "none"
, we try using the color at the cursor's hl group as the cursor color.This is similar to how kitty does the smearing cursors, with
cursor none
, meaning it takes the color of what's at the current cell as the cursor color.When getting the color, we first try treesitter captures if treesitter highlighting is enabled in the buffer and then fallback to extmarks. Regular treesitter extmarks are ephemeral, so they can't be retrieved with the get extmarks function.
Everything is cached, so should not impact performance.
I believe you tried something similar, as there was a non-used function called
M.get_hl_group
already :)I used some metatable magic to prevent making changes in other places where the hl group lookup tables were used. Let me know if you'd rather have those places call the function directly.
Changes
Mainly changes to the color module, where hl groups are now cached and dynamically created when needed.