mcauley-penney / visual-whitespace.nvim

A Neovim plugin to reveal whitespace characters in visual mode, like VSCode
84 stars 1 forks source link

feat: support exclude buffers #14

Open nowaylifer opened 5 days ago

nowaylifer commented 5 days ago

I'd like to disable the plugin in certain buffers depending on filetype or buftype:

require('visual-whitespace').setup({
  exclude = {
    filetypes = { "neo-tree" },
    buftypes = { "quickfix" }
  }
})
mcauley-penney commented 5 days ago

Will do! I'll try and have this done by my end of day today

mcauley-penney commented 4 days ago

I just pushed a commit to main (776c970bed5539207bbee0880b7ca4df7b826d06) that implements this feature. Please try it out and let me know what you think!

nowaylifer commented 4 days ago

Works good! But getting this error when either filetypes or buftypes is omitted in config, has to manually put empty table to solve it:

Failed to run `config` for visual-whitespace.nvim

...im/lazy/visual-whitespace.nvim/lua/visual-whitespace.lua:204: attempt to get length of field 'buftypes' (a nil value)

# stacktrace:
  - /visual-whitespace.nvim/lua/visual-whitespace.lua:204 _in_ **setup**
  - lua/plugins/extras/ui/visual-whitespace.lua:13 _in_ **config**
  - vim/_editor.lua:0 _in_ **cmd**
  - /persistence.nvim/lua/persistence/init.lua:88 _in_ **load**
  - lua/:1
  - vim/_editor.lua:0 _in_ **cmd**
  - /dashboard-nvim/lua/dashboard/theme/doom.lua:24
    excluded = {
      filetypes = {},
      buftypes = { "quickfix", "terminal", "nofile" },
    },
nowaylifer commented 4 days ago

Also it seems that excluded "nofile" buftype breaks file buffer as well image

mcauley-penney commented 4 days ago

Works good! But getting this error when either filetypes or buftypes is omitted in config, has to manually put empty table to solve it:

Tbh I don't really know why this is happening. I'm not experiencing this error. I don't provided the excluded table in my config. Can you provide the version of nvim you're using?

I can confirm nofile breaks the plugin. I will work on that.

nowaylifer commented 4 days ago

Tbh I don't really know why this is happening. I'm not experiencing this error. I don't provided the excluded table in my config. Can you provide the version of nvim you're using?

I use v0.10.2. It's reproducible with this config. Try nvim --clean -u repro.lua, there'll be error. Then uncomment filetypes = {}, error is gone.

-- repro.lua
local install_path = "tmp/nvim/site/visual-whitespace"

vim.fn.system({
    "git",
    "clone",
    "--depth=1",
    "https://github.com/mcauley-penney/visual-whitespace.nvim.git",
    install_path,
})

vim.o.runtimepath = install_path .. "," .. vim.o.runtimepath

require("visual-whitespace").setup({
    excluded = {
        buftypes = { "terminal" },
        -- filetypes = {},
    },
})
mcauley-penney commented 4 days ago

Okay, so, the likely reason that the nofile issue is happening is because some buffer, perhaps a dashboard or another automatically opening plugin, is setting nofile and visual-whitespace is not checking again in the right way. I can get this with opening aerial automatically.

I have to find the right group of autocommands, or some other means of checking the file and buf types.

mcauley-penney commented 4 days ago

It's reproducible with this config. Try nvim --clean -u repro.lua, there'll be error. Then uncomment filetypes = {}, error is gone.

Yes, this reproduces it for me. I think its just a nil check that I'm missing.

mcauley-penney commented 3 days ago

@nowaylifer Okay, I think I've solved the config issue and I may have solved the nofile issue. Please try it out and let me know what you think.

nowaylifer commented 3 days ago

Yes, both issues are solved on my side. But it seems other buftypes exclusions apart from nofile stopped to work (at least quickfix, terminal and help that I checked)

nowaylifer commented 3 days ago

No, actually "nofile" also doesn't work

mcauley-penney commented 3 days ago

Yeah, this is nasty and I don't know why. I figured it would be easy to implement this via autocommands but it's really not. I feel like I'm missing something super obvious.

Anyway, I'm still working on it.

mcauley-penney commented 2 days ago

@nowaylifer I've moved the work on this feature over to branch exclude and reverted them on main. In my personal projects, I have a bad habit of just pushing to main instead of working off of feature branches. So, I will be working on this when I can over there.

mcauley-penney commented 1 day ago

@nowaylifer Please check out the exclude branch. With some help, I think I found at least a starting place for solving this neatly.