bullets-vim / bullets.vim

🔫 Bullets.vim is a Vim/NeoVim plugin for automated bullet lists.
https://doriankarter.com
Other
485 stars 35 forks source link

g:bullets_enable_in_empty_buffers keeps overwriting mappings after a filetype is set #63

Open cormacrelf opened 4 years ago

cormacrelf commented 4 years ago

Bullets adds

au Filetype markdown,text,gitcommit,etc nnoremap ... `

autocommands for all its configured mappings. If g:bullets_enable_in_empty_buffers is set, then it also adds

autocmd BufEnter * if bufname("") == "" | ' nnoremap ...

The desired effect is that :enew empty buffers will have bullets enabled even before you add a filetype. However, this affects the buffers some plugins create that they want to add their own special mappings to. Essentially, UI plugins. I am using git-messenger.vim, which does this:

  1. open a neovim popup window
  2. enew
  3. set the filetype to gitmessengerpopup
  4. add mappings

But being a popup window, you don't BufEnter immediately. You have to trigger git-messenger again to switch into the window.

Bullets.vim's unnamed-buffer autocommands use BufEnter, which fires:

After entering a buffer. Useful for setting options for a file type. Also executed when starting to edit a buffer, after the BufReadPost autocommands.

So Bullets.vim's autocommands fire twice: once after enew (step 2), and once again when you enter the popup buffer. Overwriting any configured mappings every time you enter an unnamed buffer. So Bullets.vim is forcing a race between plugins to be the last one to execute their mapping commands, and winning. This is the usual reason for plugins not working well together.

As for solutions? I don't think g:bullets_enable_in_empty_buffers should be enabled by default. I don't know if you agree. Either way, you have #4 and #44 specifically for buffers without a filetype, so it would be better not to check the buffer name (ie filename), but instead check whether filetype is empty. After all, we don't generally care whether a buffer has a filename or not when it comes to mappings. An example is in https://stackoverflow.com/a/46681816:

autocmd FileType markdown,text nnoremap <buffer> <leader>f :1,$! cat
autocmd BufNewFile,BufRead * if empty(&filetype) | execute 'nnoremap <buffer> <leader>f :1,$! cat' | endif

So git-messenger.vim buffers, having been given a filetype, would no longer trigger Bullets.vim's mapping autocommands, and could win the race to be last.

dkarter commented 4 years ago

You make some really good points and thank you for bringing this to my attention. I definitely don’t want to break other plugins or inefficiently set the mappings. I’ll look into it and see what I can do.

dkarter commented 4 years ago

Actually, @cormacrelf since you have more opinions on the matter and ways to test it works correctly and solves your problem, would you be up to drafting a PR for this? :)