lukoshkin / highlight-whitespace

Highlight unwanted whitespace and more in Vim/Neovim
MIT License
10 stars 3 forks source link

Bugs in the commit b736461ad6d4ec3fa718d13d3c872a1f7ec5b75c #3

Open stevenxxiu opened 1 month ago

stevenxxiu commented 1 month ago

The latest commit b736461ad6d4ec3fa718d13d3c872a1f7ec5b75c broke my config quite a bit.

I have a custom background color for Markdown files, set by:

vim.opt_local.winhighlight = winhighlight

Now this no longer works, as highlight-whitespace is overriding it. Instead I have to do:

vim.api.nvim_set_hl(0, 'Normal', MARKDOWN_NORMAL)
vim.api.nvim_set_hl(0, 'WinSeparator', MARKDOWN_SEPARATOR)

Another bug is when I use bufferline, picking a tab to jump to sometimes causes errors:

Error executing Lua callback: ...re/nvim/lazy/bufferline.nvim/lua/bufferline/commands.lua:25: BufLeave Autocommands for "*": Vim(append):Error executing lua callback: ...y/highlight-whitespace/lua/highlight-whitespace/core.lua:43: Error ex
ecuting lua: Vim:E803: ID not found: 1230
stack traceback:
        [C]: in function 'matchdelete'
        ...y/highlight-whitespace/lua/highlight-whitespace/core.lua:47: in function <...y/highlight-whitespace/lua/highlight-whitespace/core.lua:43>
        [C]: in function 'nvim_win_call'
        ...y/highlight-whitespace/lua/highlight-whitespace/core.lua:43: in function 'clear_uws_match'
        ...y/highlight-whitespace/lua/highlight-whitespace/init.lua:22: in function <...y/highlight-whitespace/lua/highlight-whitespace/init.lua:21>
        [C]: in function 'nvim_set_current_buf'
        ...re/nvim/lazy/bufferline.nvim/lua/bufferline/commands.lua:25: in function 'func'
        .../share/nvim/lazy/bufferline.nvim/lua/bufferline/pick.lua:28: in function 'choose_then'
        ...re/nvim/lazy/bufferline.nvim/lua/bufferline/commands.lua:101: in function 'pick'
        ...local/share/nvim/lazy/bufferline.nvim/lua/bufferline.lua:158: in function <...local/share/nvim/lazy/bufferline.nvim/lua/bufferline.lua:158>
stack traceback:
        [C]: in function 'nvim_win_call'
        ...y/highlight-whitespace/lua/highlight-whitespace/core.lua:43: in function 'clear_uws_match'
        ...y/highlight-whitespace/lua/highlight-whitespace/init.lua:22: in function <...y/highlight-whitespace/lua/highlight-whitespace/init.lua:21>
        [C]: in function 'nvim_set_current_buf'
        ...re/nvim/lazy/bufferline.nvim/lua/bufferline/commands.lua:25: in function 'func'
        .../share/nvim/lazy/bufferline.nvim/lua/bufferline/pick.lua:28: in function 'choose_then'
        ...re/nvim/lazy/bufferline.nvim/lua/bufferline/commands.lua:101: in function 'pick'
        ...local/share/nvim/lazy/bufferline.nvim/lua/bufferline.lua:158: in function <...local/share/nvim/lazy/bufferline.nvim/lua/bufferline.lua:158>
stack traceback:
        [C]: in function 'nvim_set_current_buf'
        ...re/nvim/lazy/bufferline.nvim/lua/bufferline/commands.lua:25: in function 'func'
        .../share/nvim/lazy/bufferline.nvim/lua/bufferline/pick.lua:28: in function 'choose_then'
        ...re/nvim/lazy/bufferline.nvim/lua/bufferline/commands.lua:101: in function 'pick'
        ...local/share/nvim/lazy/bufferline.nvim/lua/bufferline.lua:158: in function <...local/share/nvim/lazy/bufferline.nvim/lua/bufferline.lua:158>
stevenxxiu commented 1 month ago

The bufferline issue seems to go away if I use clear_on_bufleave = false, but now I get errors in Neogit when I quit a diff view:

E5108: Error executing lua vim/_editor.lua:0: nvim_exec2()..BufHidden Autocommands for "*": Vim(append):Error executing lua callback: Vim:E957: Invalid window number
stack traceback:
        [C]: in function 'getmatches'
        ...y/highlight-whitespace/lua/highlight-whitespace/core.lua:103: in function 'save_matches_to_cache_and_clear'
        ...y/highlight-whitespace/lua/highlight-whitespace/init.lua:37: in function <...y/highlight-whitespace/lua/highlight-whitespace/init.lua:36>
        [C]: in function 'nvim_exec2'
        vim/_editor.lua: in function 'cmd'
        ...re/nvim/lazy/neogit/lua/neogit/integrations/diffview.lua:20: in function 'close'
        [string ":lua"]:1: in main chunk
stack traceback:
        [C]: in function 'nvim_exec2'
        vim/_editor.lua: in function 'cmd'
        ...re/nvim/lazy/neogit/lua/neogit/integrations/diffview.lua:20: in function 'close'
        [string ":lua"]:1: in main chunk
lukoshkin commented 1 month ago

Hello @stevenxxiu! I'm glad you continue using the plugin and helping to improve it! Currently, I'm on my full vacation: it means I am going hiking tomorrow and won't be accessible till Aug 6th (No wifi, no mobile network). So until then I won't be able to help you. However, we will definitely try to fix it later.

If you are familiar with the code enough, you can suggest your changes on how to fix the issues above. By the way, clear_on_bufleave = true should remove HWS highlighting in a window user leaves, when jumping to another one. You can check the code related this part and try to correlate with your traceback

stevenxxiu commented 1 month ago

Thanks to you too. I'll see if I can fix some of those issues.

I just realized that the reason my custom background for Markdown files doesn't work anymore, is since vim.api.nvim_win_set_hl_ns() overrides winhighlight. This means buffers can no longer have custom highlights.

I'm not sure what the best solution is here. I can't find anything on Treesitter setting a different background color per syntax.

What do you think about having a separate namespace for each syntax, so this is possible?

I also thought of the https://github.com/folke/styler.nvim plugin, but I'm not sure how easy it is to make a syntax that inherits another (I use catppuccin).

stevenxxiu commented 1 month ago

I suppose I got the custom highlights to work just by reusing vim.api.nvim_win_set_hl_ns():

local highlight_whitespace_core = require('highlight-whitespace.core')
-- ...
vim.api.nvim_set_hl(highlight_whitespace_core.ns_id, 'Normal', { fg = C.text, bg = MARKDOWN_BG })