magit/with-editor

Why can I not kill the buffer?

Closed this issue · 3 comments

I have EDITOR="emacsclient -c" and this works with most applications no problem. When I use git commit this mode is enabled on the result, I assume because magit sees that I'm doing git things (and also helpfully opens a diff in a second frame).

My normal workflow involves doing stuff in the opened buffer+frame, then closing the buffer and frame and back to my ansi-term. But with this mode it refuses to kill the buffer, leaving it as a zombie in the background and not correctly returning control. If I use the mode-specific "all done" key sequence everything works as expected (both frames close and git knows to continue) but I'm wondering why it couldn't detect buffer kill and do the same?

When I use git commit this mode is enabled on the result, I assume because magit sees that I'm doing git things (and also helpfully opens a diff in a second frame).

That's right. Ultimately its because global-git-commit-mode adds something to ind-file-hook. Turning off the mode should disable all of this.

But with this mode it refuses to kill the buffer, leaving it as a zombie in the background and not correctly returning control.

It's not refusing to kill the buffer I think. Its just asking you to use a different command, which performs additional cleanup. Are you saying that with-editor-finish and/or with-editor-cancel fail to kill the buffer? Or are you simply seeing the user-error: Don't kill this buffer #<buffer COMMIT_EDITMSG>. Instead cancel using C-c C-k and have come to the incorrect conclusion that you cannot kill the buffer? Cancelling involves killing.

I am seeing that error, but IME the buffer does not die unless I use one of the special cancel/finish keys. Any of my normal kill keys don't work, and since in my normal workflow I kill the buffer and frame simultaneously, it actually causes the buffer to dissappear from view but not be killed (and the error to be displayed in the minibuffer of another frame).

Mainly I'm curious why the "additional cleanup" could not happen in a buffer-kill hook of some kind instead of disabling normal buffer kill keys and requiring different keys? Orgmode capture, for a related example, has cancel/continue keys also, but using my normal "save and kill" keys also does the right thing in that case. And, of course, with magit disabled save-and-kill does the right thing with git also, since the file is saved, emacsclient terminates, and git proceeds as usual.

Any of my normal kill keys don't work, and since in my normal workflow I kill the buffer and frame simultaneously,

I don't know what commands and key bindings you use to do this, but if you setup remappings like those that already exist in with-editor-mode-map, then you should be able to use the keys that you are used to. If the with-editor commands fail to do certain things that you would like them to do, then you might be able to teach them to do it using the with-editor-*-*-hook hooks.

Mainly I'm curious why the "additional cleanup" could not happen in a buffer-kill hook of some kind instead of disabling normal buffer kill keys and requiring different keys?

Of course I tried that first. It did not work. I don't remember the details but it most have something to do with things not happening in the correct order when we don't take complete control over the necessary steps.

I'm afraid there's nothing I can do about this. You will have to use the with-editor commands and in your case doing so might involve manually overwriting certain key bindings.