stevearc / stickybuf.nvim

Neovim plugin for locking a buffer to a window
MIT License
246 stars 7 forks source link

Suggestion about NEOGIT_COMMIT_EDITMSG #1

Closed Shatur closed 3 years ago

Shatur commented 3 years ago

I found that Neogit commit messsage could be marked as sticky too. It opened by Neogit vertically to NeogitStatus. This is how I use it:

  bufname = {
    ['.*NEOGIT_COMMIT_EDITMSG'] = 'bufnr',
  },

I opened the issue because you may want to make it sticky by default.

stevearc commented 3 years ago

Good suggestions, thanks!

Shatur commented 3 years ago

Good suggestions, thanks!

Hm... This change triggers the following error:

Error detected while processing BufUnload Autocommands for "<buffer=52>":
E5108: Error executing lua ...vim/pack/plugins/opt/neogit/lua/neogit/popups/commit.lua:39: Vim(write):E382: Cannot write, 'buftype' option is set

Steps to reproduce

  1. Make any changes and stage changes
  2. :NeogitStatus
  3. cc
  4. :w
  5. :bdelete
Shatur commented 3 years ago

@stevearc, if you will use :close instead of :bdelete, then your commit will contain comments.

stevearc commented 3 years ago

Thanks for the report! The issue comes in here: https://github.com/TimUntersberger/neogit/blob/a859c0ddc526fafaa21e9613e11aa06ad9258e1c/lua/neogit/popups/commit.lua#L32-L40

Neogit is running g/^#/d and :w! on BufUnload. The way stickybuf works is by overriding the bufhidden option, so that changes when BufUnload will happen. What happens without stickybuf:

With stickybuf before the change I just made:

My change does fix the issue with close not removing the comments from the commit message. However, the error from bdelete remains. I believe this is because bdelete closes the window before deleting the buffer, and unlike the function inside stickybuf, it will not move the cursor back into the buffer before it deletes it. I don't have a good fix for this.

I don't want this plugin to provide any behavior by default that could cause errors under normal use, so I'm removing the pinning from the commit message. If you still want that behavior, add it back in your own config and use close instead of bdelete to avoid the error.

Shatur commented 3 years ago

Thanks! I use the following workaround for buffer deletion: https://github.com/Shatur/neovim-config/blob/998f7e61c5ffc925ebe49f9b8a4280b4fc0346c0/lua/config_utils/buffers.lua#L15