Emacs Server: GUI or Terminal?

Menu

Emacs can also be run as a server, with some advantages: editing sessions open faster and all edits take place in the same instance.

There are different ways to start an Emacs server.

From Emacs, with M-x server-start or by putting the following code in the init file (e.g., .emacs):

(require 'server)
(unless (server-running-p)
  (server-start))

From the command line:

emacs --daemon

By enabling the emacs service, on systems with systemctl:

systemctl --user enable --now emacs

Once a server is started, Emacs sits in memory, ready to open with the command emacsclient. The interesting part, at least for me, is that emacsclient can open editing session in a terminal or in a GUI window.

Open Emacs in a terminal with:

emacsclient -t

Use the -c option to open Emacs as a GUI window:

emacsclient -c

Emacs can thus serve multiple editing sessions at the same time, some in terminals and others as GUI:

emacsclient -c . &
emacsclient -t .emacs &

The buffers are shared among all the instances, that is, a file opened in a GUI instance can be accessed from another instance opened in a terminal. Supercool.

Resources: