3

I am trying to use Emacs 25.1.1 (graphical version, Windows 10) as both the primary editor and the editor for git operations.

In my workflow, I invoke git through M-x shell-command.

I tried the following two options so far:

  1. git config --global core.editor "emacs -Q"

    With this, M-x shell-command RET git commit works just fine, as a new light-weight instance of emacs is used.

    Downside: Completion with M-/ aka dabbrev-expand is less useful than it could be.

  2. git config --global core.editor "emacsclient --no-wait --create-frame"

    With this setting, trying to execute git synchrnously as M-x shell-command RET git commit on the other hand causes the emacsclient and server emacs processes to hang indefinitely, until `emacsclient is killed, while the asynchrnous invocation M-x shell-command RET git commit & works, but this setup is too brittle, as forgetting the & causes Emacs to all but crash.

Is there some way to use emacsclient as git editor, that is compatible with M-x shell-command?

  • As a workaround (not answering your question), you could consider using magit (which is amazing) or the vc-* commands that are built-in (e.g. C-x v v). As another workaround, you could use M-x async-shell-command. – aplaice Nov 14 '17 at 20:59
  • @aplaice The first workaround seems viable, though I can't seem to figure out an equivalent of git commit -a or git commit file1 file2. Due to such issues I prefer working directly with the shell commands over learning multiple interfaces for the same action. The second workaround is equivalent to the use got shell-command with leading & and suffers from the same problems; Most of the time the synchronous version is preferable for me, so its likely I'll end up crashing emacs by forgetting to use the asynchrnous version. The downsides of using runemacs -Q are smaller than that. – kdb Nov 16 '17 at 11:12
  • Little correction: It should be emacs -Q not runemacs -Q as I had originally written. With runemacs -Q the editor is detached from git, making git think it was closed with an empty commit message. – kdb Nov 16 '17 at 15:03
  • 1
    I think you want github.com/magit/with-editor – Ista Apr 10 '18 at 17:58
0

If you run git within a posix environment (cygwin or msys, I believe git-bash uses msys), you could create a function in your ~/.profile:

function already_emacsing () {
   emacsclient --eval '(find-file-other-window $1)'
}
EDITOR="already_emacsing"

I can't test it on your setup right now, but the individual parts all work and I can't see any reason they shouldn't fit together well enough. I can't think of a way to do the same with batch scripting, but it's probable you could do the same emacsclient call with a powershell script or something as well.

  • I am running git from within the Windows version of Emacs, so it is executed through cmdproxy.exe, not through a posix shell, and thus this solution isn't applicable. – kdb Nov 16 '17 at 11:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.