Skip to content
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

Will not automatically start the plugin. #3

Open
danbruegge opened this issue Mar 6, 2022 · 13 comments · May be fixed by #19
Open

Will not automatically start the plugin. #3

danbruegge opened this issue Mar 6, 2022 · 13 comments · May be fixed by #19

Comments

@danbruegge
Copy link

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?

@NMAC427
Copy link
Owner

NMAC427 commented Mar 7, 2022

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.

@danbruegge
Copy link
Author

danbruegge commented Mar 7, 2022

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.

@danbruegge
Copy link
Author

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)

@NMAC427
Copy link
Owner

NMAC427 commented Apr 15, 2022

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.

@stumash
Copy link

stumash commented May 13, 2022

I have the same issue, it doesn't automatically start the plugin

@stumash
Copy link

stumash commented May 13, 2022

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" } }

@NMAC427
Copy link
Owner

NMAC427 commented May 13, 2022

Yes, it seems very likely that this might have been the culprit. Thanks!
I just pushed a commit (801ee85) 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?

@mahor1221
Copy link

mahor1221 commented Dec 13, 2022

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 c37467b.
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.

@alek3y
Copy link

alek3y commented Jun 29, 2023

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).

@tan-wei
Copy link

tan-wei commented Sep 10, 2023

Just met the same issue.

@liangkarl
Copy link

liangkarl commented Jan 5, 2024

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.

@yutkat yutkat linked a pull request Apr 1, 2024 that will close this issue
@liangkarl
Copy link

I think there are some problems behind auto_cmd, which would check editorconfig config. For now, my best way to fix it is

local default_config = {
  auto_cmd = false
}
vim.cmd([[ autocmd BufReadPost * :silent GuessIndent ]])

Then, everything is back to normal.

@Exagone313
Copy link

I think this is fixed in #20

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants