iamcco / markdown-preview.nvim

markdown preview plugin for (neo)vim
MIT License
6.82k stars 284 forks source link

cache bufnr to prevent error while processing autoclose autocmd #576

Open ribru17 opened 1 year ago

ribru17 commented 1 year ago

Problem: I would frequently get errors while closing previewing markdown buffers saying:

Error detected while processing BufHidden Autocommands for "<buffer=1>"..function mkdp#rpc#preview_close[11]..mkdp#autocmd#clear_buf:
line    1:
E216: No such group or event: MKDP_REFRESH_INIT10

This was because the auto-close autocmd would run after the buffer was already closed, and the plugin thought it needed to close my next opened buffer (some other non-markdown file) which of course was incorrect behavior.

Solution: I fixed this by caching the buffer number of the actual markdown buffer I needed and then passing it down to each function that needed the buffer number to close it. I would really love to see this merged as this issue was quite annoying to me. Thanks for the great plugin

ribru17 commented 1 year ago

By the way I have tested this a good deal and I believe it closes #316.