By convention, your choice of editor is specified by the environment variable ‘EDITOR’. If you set ‘EDITOR’ to ‘emacs’, Emacs would be invoked, but in an inconvenient way—by starting a new Emacs process. This is inconvenient because the new Emacs process doesn’t share buffers, a command history, or other kinds of information with any existing Emacs process.
You can solve this problem by setting up Emacs as an edit server, so that it “listens” for external edit requests and acts accordingly. There are various ways to start an Emacs server:
server-start
from within a process, either interactively as
‘M-x server-start’, or from within your ‘INIT’ file as (server-start)
. The
existing Emacs process is the server.
server-start
after initialization and does not open an
initial frame. It then waits for edit requests from clients (using
emacsclient
).
-daemon
--daemon[=name]
--bg-daemon[=name]
A “background” daemon disconnects from the terminal and runs in the
background (--daemon
is an alias for bg-daemon
).
To kill a daemon session, type ‘M-x kill-emacs’.
--fg-daemon[=name]
emacsclient
Once an Emacs server is started, you can use a shell command called
emacsclient
to connect to the Emacs process and tell it to visit a file.
You can then set the ‘EDITOR’ environment variable to ‘emacsclient’, so
that external programs will use the existing Emacs process for editing.
emacsclient
connects to the first server it finds.