chomosuke / typst-preview.nvim

Low latency typst preview for Neovim
GNU General Public License v3.0
218 stars 14 forks source link

fix buffer autocommands bug? #13

Closed m4cey closed 4 months ago

m4cey commented 6 months ago

fixes #12 apparently, removing vim.defer_fn from create_autocmds fixes this for me, but not sure if it's acceptable as I don't know the original purpose of using a defer here.

pynappo commented 4 months ago

I'm running into a similar buffer autocommands issue and this PR also fixes it. I do not call setup() from outside of my lazy.nvim plugin spec so I'm thinking this PR (and/or extra error checking with vim.api.nvim_buf_is_valid) is needed.

The error seems to happen whenever a new typst buffer is made and then deleted very quickly. For me this is caused by ultimate-autopair.nvim on <CR> in typst files for some reason. So by the time the deferred nvim_create_autocmd function is run the buffer is gone and registering the autocmd fails.

From reading the neovim docs, it seems like the wrapper is unnecessary anyways because nvim_create_autocmd is already deferred, so vim.defer_fn(func, 0) (which I believe is the same as vim.schedule(func)) just delays it further.

chomosuke commented 4 months ago

Thank you for fixing this. I forgot the reason why it's wrapped in a vim.defer_fn though it might just be precautionary as sometimes certain functions can't run in certain context.