guess-indent.nvim
guess-indent.nvim copied to clipboard
Will not automatically start the plugin.
Hi,
use({
"nmac427/guess-indent.nvim",
config = function()
require("guess-indent").setup({})
end,
})
Trying out this plugin with the config from the readme.
Sadly the autostart is not working. Even with auto_cmd=true
.
I need to manually call GuessIndent
to get it work. :(
Any idea? Do you need more info? Do i need to setup the plugin in an specific order?
Hello. I just did some tests using a super minimal init.lua config, but for me it worked perfectly.
To help me understand what's going on, could you check and see if it works when you use this barebones configuration? To check if it is working you can open any file that is indented using spaces and then press the tab key and see if it inserts spaces (in which case the plugin is working) or not.
local fn = vim.fn
local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim'
if fn.empty(fn.glob(install_path)) > 0 then
packer_bootstrap = fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path})
end
return require('packer').startup(function(use)
use({
"nmac427/guess-indent.nvim",
config = function()
require("guess-indent").setup({})
end,
})
if packer_bootstrap then
require('packer').sync()
end
end)
Additionally can you try running nvim in verbose mode (nvim -V100out.txt some_file.cpp
) and then check the output (if you use the previous command it should be in the out.txt
file) for the string GuessIndent
and Guess Indent
(maybe even guess-indent
)? If the plugin works properly you should expect to see something like this:
Executing: command! GuessIndent :lua require("guess-indent").set_from_buffer()
Executing:
Executing: augroup GuessIndent
Executing: autocmd!
Executing: autocmd BufReadPost * :silent lua require("guess-indent").set_from_buffer(true)
Executing: augroup END
Executing:
Autokommando :silent lua require("guess-indent").set_from_buffer(true)
Executing: :silent lua require("guess-indent").set_from_buffer(true)
File type: lua
Buffer type:
Guess Indent
Lines using tabs: 0
Lines using spaces: 9
1 space: 3
2 space: 6
Lines loaded: 24
Lines iterated: 24
Did set indentation to 2 spaces.
My workaround is:
vim.api.nvim_exec([[ autocmd BufReadPost * :silent GuessIndent ]], false)
// Edit Sorry didn't saw your comment before posting. Will check it later.
Hi, sorry for the late reply.
I get the output, but it is still not working.
Executing: command! GuessIndent :lua require("guess-indent").set_from_buffer()
Executing:
Executing: augroup GuessIndent
Executing: autocmd!
Executing: autocmd BufReadPost * :silent lua require("guess-indent").set_from_buffer(true)
Executing: augroup END
Executing:
I tried your version with my workaround. So I think the lua call itself is not working?
exec([[ autocmd BufReadPost * :silent lua require("guess-indent").set_from_buffer(true) ]], false)
So for now, the best for me to get it working is:
exec([[ autocmd BufReadPost * :silent GuessIndent ]], false)
Hmm... That's weird. Can you try cloning the repository and making some local changes (you also need to modify your packer config so that it uses your local clone)?
The first change I'm interested in: What happens if you change the autocmd on line 16 of init.lua to :lua require("guess-indent").set_from_buffer()
(which would be equivalent to :GuessIndent
) and see if it makes a difference (if it doesn't, what happens if you replace it with :GuessIndent
which makes it equivalent to your workaround).
The second change: If you change the autocmd on the same line to autocmd BufReadPost * :1verbose unsilent lua require("guess-indent").set_from_buffer(true)
and then open a file, do you see any output similar to this?
File type: lua
Buffer type:
Guess Indent
Lines using tabs: 0
Lines using spaces: 128
2 space: 128
Lines loaded: 256
Lines iterated: 196
Did set indentation to 2 spaces.
I have the same issue, it doesn't automatically start the plugin
I figured out that the issue for me is that GuessIndent
doesn't run when the filetype is unknown because of
https://github.com/NMAC427/guess-indent.nvim/blob/main/lua/guess-indent/config.lua#L8
local default_config = {
auto_cmd = true,
filetype_exclude = {
"netrw",
"tutor",
"",
},
-- ...
So I'm just gonna go and override that
require'guess-indent'.setup { filetype_exclude = { "netrw", "tutor" } }
Yes, it seems very likely that this might have been the culprit. Thanks! I just pushed a commit (https://github.com/NMAC427/guess-indent.nvim/commit/801ee85b9c55af2950eff201a306e14cdd5a69b5) that removes the empty string from the default list of excluded file types.
@danbruegge can you pull the latest version and check if this finally fixed your issue?
The plugin works out of the box when I use the minimal config mentioned above, but when I switch to my customized init.lua
it doesn't start automatically. I get the same output with nvim -V100out.txt
.
Also neither of theses alternative configs work for me:
vim.api.nvim_exec([[ autocmd BufReadPost * :silent lua require("guess-indent").set_from_buffer(true) ]], false)
vim.api.nvim_exec([[ autocmd BufReadPost * :silent GuessIndent ]], false)
My weird workaround is:
vim.api.nvim_create_autocmd("VimEnter", {
group = vim.api.nvim_create_augroup("GuessIndent", { clear = true }),
command = "autocmd BufReadPost * :silent lua require('guess-indent').set_from_buffer(true)"
})
I have neovim 0.8.1
and guess-indent c37467baa1a51b74ed767cbe0540fce44e03d828.
I think my situation is special because I have a poorly maintained and messy init.lua
with 1200 LoC. I leave this comment here just in case.
Same here. Running nvim -V100out.txt tabs.py
results in the following log:
File type:
Buffer type:
Guess Indent
Lines using tabs: 1
Lines using spaces: 0
Lines loaded: 3
Lines iterated: 3
Did set indentation to tabs.
I don't know if it's my setup that's broken or not, but around 30 lines later nvim starts searching python ftplugins.
This would explain why my log shows empty filetype and why I get spaces when first opening tabs.py
.
Apparently, changing BufReadPost
to FileType
here seems to somewhat work around it, since the FileType
autocommands get executed right after ftplugins are loaded (inside my out.txt
as well as for this guy).
However, it seems like it doesn't really work when the filetype does not get set on existing files (e.g. in spaces.asdf
file).
Just met the same issue.
In my case, it seems like guess-indent settings were overridden by editorconfig, making nvim look like guess-indent wasn't executed. Once I disabled editorconfig or ensured that editorconfig was executed before guess-indent, the problem was solved.