Darazaki / indent-o-matic

Dumb automatic fast indentation detection for Neovim written in Lua
MIT License
176 stars 13 forks source link

Breaks when shiftwidth=0 #8

Closed XeroOl closed 2 years ago

XeroOl commented 2 years ago

When the vim option shiftwidth is set to 0, the plugin fails to detect properly. You can reproduce with what's in my config.

vim.opt.tabstop=4
vim.opt.shiftwidth=0
vim.opt.expandtab=true

According to :help shiftwidth, if shiftwidth is set to zero, it should act the same as if it were set to the value of tabstop instead. I think this plugin uses 0 as a special value, and gets confused when detecting.

The workaround is to manually set shiftwidth to match tabstop, but this should be pretty simple to fix in the plugin.

Darazaki commented 2 years ago

Thanks a lot for submitting such a detailed bug report! You're completely right about 0 being a special value

I'll fix this bug today :)

XeroOl commented 2 years ago

For me it still isn't working correctly. I've got a file with just this in it:

{
»   "Lua.diagnostics.globals": [
»   »   "vim"
»   ]
}

where » is the tab character, and the plugin doesn't seem to set noexpandtab for me for tabstop=4 shiftwidth=0 expandtab, but it does get set with tabstop=4 shiftwidth=4 expandtab

Darazaki commented 2 years ago

Oh you're right, I went a bit too fast when testing the fix sorry :/

Since I forgot 0 isn't a falsy value in Lua, the problem is probably just this line:

https://github.com/Darazaki/indent-o-matic/blob/f7d4382d1ab511e6306b1a7daf13791ccfb317d2/lua/indent-o-matic.lua#L55

I'll fix it when I get back to my computer. Thanks for telling me!