I'm using M-x ansi-term within emacs, and a lot of the tools I use (not only git) are opening editors using $EDITOR.

Because running emacs within itself is kind of annoying, I'd like to configure my $EDITOR variable such that it opens a new buffer in the emacs session that's running the current instance of ansi-term.

Is there any way to do this?


This has been asked before on stackoverflow. Here is the accepted answer:

You can attach to an Emacs session through emacsclient. First, start the emacs server with

M-x server-start or add (server-start) to your .emacs. Then,

export VISUAL=emacsclient Edit away.


  1. The versions of emacs and emacsclient must agree. If you have multiple versions of Emacs installed, make sure you invoke the version of emacsclient corresponding to the version of Emacs running the server.
  2. If you start the server in multiple Emacs processes/frames (e.g., because (server-start) is in your .emacs), the buffer will be created in the last frame to start the server.
  • 1
    Works perfectly! If you're running ansi-term, the $EMACS variable will be set, so I can figure out which editor to use on my various systems really nicely. Here's my setup for anyone curious. – Stefano Palazzo Jul 2 '13 at 9:09
  • @StefanoPalazzo: or you could just use the ALTERNATE_EDITOR approach, leave (server-start) out of your init file, and let emacsclient worry about whether an emacs needs to be started... – SamB Jan 2 '14 at 6:16

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.