Recently, I'd wanted to commit to my git repository from within emacs. Instead of running some git mode commands, I opened up a terminal buffer and run git commit inside. This works fine, except that the commit message editor is, of course, emacs. Out of habit, I tried to save-close the editor after inserting the commit message, but that closed my parent emacs...

Since I run emacs in client/server mode, I can simply reconnect and have all the buffers still open. But how do I close the child emacs (apart from killing it from within another terminal)?

In general, how do I send ctrl/meta to a program running in the terminal buffer?

  • Not sure I understand, but are you looking for C-x # (server-edit) (see manual)? – Dan Feb 1 '17 at 12:38
  • Since you're already running in server mode, you can set your git to use emacsclient as your commit editor. The arrangement you're using sounds unnecessarily convoluted. – Tyler Feb 1 '17 at 14:17

If you're in term buffer in char mode, you have to escape C-c. So, if you're running a terminal Emacs instance inside the term buffer, running save-buffers-kill-terminal requires an extra C-c: C-x C-c C-c.

If you're running an Emacs instance in a term buffer in line mode, I don't think there's a direct way to kill the nested Emacs. You have to switch back to char mode first, via C-c C-k. Then you can call C-x C-c C-c as above.

That said, rather than staring an Emacs instance from your term buffer, you should call emacsclient instead. That will open up your file in a regular Emacs buffer in the current Emacs instance, without all the confusing nesting of Emacs-inside-term-inside-Emacs.

  • You are of course right, the whole thing happened out of old habit and wasn't intentional. – choeger Feb 1 '17 at 20:05

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.