Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion about NEOGIT_COMMIT_EDITMSG #1

Closed
Shatur opened this issue Jul 12, 2021 · 5 comments
Closed

Suggestion about NEOGIT_COMMIT_EDITMSG #1

Shatur opened this issue Jul 12, 2021 · 5 comments

Comments

@Shatur
Copy link
Contributor

Shatur commented Jul 12, 2021

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
Copy link
Owner

Good suggestions, thanks!

@Shatur
Copy link
Contributor Author

Shatur commented Jul 13, 2021

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
Copy link
Contributor Author

Shatur commented Jul 13, 2021

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

stevearc added a commit that referenced this issue Jul 14, 2021
Now we switch to the buffer in question *before* calling bunload/bdelete/bwipe. This more closely mimics the behavior of `bufhidden`
Addresses #1. We're rolling back the defaul pinning of neogit commit message. See issue for discussion.
@stevearc
Copy link
Owner

stevearc commented Jul 14, 2021

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:

  • close or bdelete
  • This triggers bufhidden, which fires the BufUnload autocmd before leaving the buffer/window
  • Comments are stripped, and the commit message is saved

With stickybuf before the change I just made:

  • close
  • Window is closed. After a delay, stickybuf deletes the commit message buffer
  • BufUnload autocmd fires, but the cursor is now back in the Neogit status window
  • The autocmd tries to delete comments & save the status window, which 1) leaves the comments in the commit message and 2) fails because you can't write the status window (has buftype=nofile)

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
Copy link
Contributor Author

Shatur commented Jul 14, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants