Darazaki / indent-o-matic

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

Not setting for new files #2

Closed jandamm closed 2 years ago

jandamm commented 2 years ago

The detection works quite well for existing files but doesn't work for newly created files.

One way to tackle this would be to use BufWritePost:

" Every time any Buffer is written (allows to change the indent after a file is written)
autocmd BufWritePost * lua IndentOMatic()
" Only once per new Buffer
autocmd BufNew * autocmd BufWritePost * ++once lua IndentOMatic()

What do you think of those changes?

Darazaki commented 2 years ago

I think those are some very good changes! I can see it being very useful for copy-n-pasting some code into a new file

The once per buffer way seems better imo, but shouldn't it be made local to a buffer to avoid it being executed on another buffer by mistake?:

au BufNew * au BufWritePost <buffer=abuf> ++once lua IndentOMatic()

At least that's how I understood those commands as a beginner, feel free to correct me if I'm wrong!

jandamm commented 2 years ago

That is completely true. Missed the buffer local autocmd.

What do you think of a :IndentOMatic command?

Darazaki commented 2 years ago

I don't see it as a necessity rn, I personally use :lua IndentOMatic() for testing everything

But maybe people would prefer if I provided :IndentOMatic for maybe their config? Would it be better to have this command too?

jandamm commented 2 years ago

The idea is that when the indent is incorrectly detected you can fix the first line and run a command. You can obviously run a lua function instead but command completion is faster.

Darazaki commented 2 years ago

I see, I'll add it then. Thanks a lot!