简体   繁体   中英

Correct Way to Exit emacsclient When Set as the Git Editor

I'd like to use emacsclient as my editor in git, ie the core.editor setting in my .gitconfig . In my .gitconfig , I have:

...
[core]
  editor = /usr/local/bin/emacsclient --tty
...

When I do something like git commit --amend , or just git commit , I get put into emacs(client) as expected, but when trying to exit with Cx Cc , I get the message:

Don’t kill this buffer #<buffer COMMIT_EDITMSG>.  Instead cancel using C-c C-k

Following the suggestion to cancel above results in an obvious error from git:

error: There was a problem with the editor '/usr/local/bin/emacsclient --tty'.
Please supply the message using either -m or -F option.

What I've discovered is that using Cx # kind of works, my changes are there. However, the next time I run something like git commit --amend , I get the message in emacsclient:

Revert buffer from file /[CONTAINING FOLDER]/.git/COMMIT_EDITMSG? (yes or no)

so I'm guessing this isn't exactly the right way to exit. I've also tried Cx k , but that doesn't seem to save anything.

Looks like the buffer is using (one of the variants of) git-commit mode.

To accept the commit message use Cc Cc (control+c twice)

https://github.com/magit/magit/blob/main/lisp/git-commit.el has this commentary:

 ;;  By making use of the `with-editor' package this package provides;; both ways of finish an editing session. In either case the file;; is saved, but Emacseditor's exit code differs. ;;  ;;  Cc Cc Finish the editing session successfully by returning;; with exit code 0. Git then creates the commit using;; the message it finds in the file. ;;  ;;  Cc Ck Aborts the edit editing session by returning with exit;;  code 1. Git then aborts the commit.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM