7

I've used git config --global core.editor emacs to set my git editor as emacs but when I do that and commit something the editor opens up a new window instead of opening emacs within the terminal. I want to use emacs as if -nw were given to it but writing this -> git config --global core.editor emacs -nw is not the solution.

I do need to use basic git for now.

  • 2
    Do you know about magit? It makes basic git operation a breeze from within Emacs. magit.vc – Tyler Mar 29 '16 at 2:04
  • 2
    Yep. Can't use it for now. After the class is over I'll level up to magit. – Lib101 Mar 29 '16 at 2:14
  • You should describe what happens when you add "-nw" instead of simply stating that it "is not the solution". It works for me, when the command is escaped properly. – asjo Mar 29 '16 at 10:55
15

When you run git config --global core.editor emacs -nw, your shell splits the command line into words before invoking git. Git thus sees "emacs -nw" as two separate arguments. It only needs one to put into the config file, so the other is ignored. (Actually, that's a lie but you can check the man page for details.) You can put quotes around a series of words to tell your shell not to break them up: git config --global core.editor "emacs -nw" will give "emacs -nw" to git as a single argument which will do what you want.

2

You do not specify what's wrong with opening a new GUI emacs window. If the problem is the long startup time you may consider using emacsclient as your editor. In a nutshell you run (server-start) in your emacs init file and keep your regular GUI emacs open, and then tell git to use an editor called emacsclient. What happens is that the edited file pops up in a new buffer in your running emacs. After you are done with it you press C-x # to finish the emacsclient session and then git (or other shell process that started the editor) knows that the editor "emacsclient" is done with the file and continues with its thing. ("emacsclient" is also one word, so it solves your immediate problem too)

Even when your editing has to be done in the terminal window you can run emacsclient -nw and eliminate the long startup time. There are more possibilities, man emacsclient is a good read.

  • 1
    (would've been better as a comment on the above answer, but not allowed to post comments ) – Ury Marshak Mar 31 '16 at 9:34
  • I've been looking everywhere for this, totally happy it's an answer :) – AER Apr 11 '18 at 3:43

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.