Previous: Invoking emacsclient, Up: Emacs Server
emacsclient OptionsYou can pass some optional arguments to the emacsclient program, such as:
emacsclient -c +12 file1 +4:3 file2
The ‘+line’ or ‘+line:column’ arguments specify line numbers, or line and column numbers, for the next file argument. These behave like the command line arguments for Emacs itself. See Action Arguments.
The other optional arguments recognized by emacsclient are listed below:
emacsclient fails to contact Emacs.
This is useful when running emacsclient in a script. For
example, the following setting for the EDITOR environment
variable will always give you an editor, even if no Emacs server is
running:
EDITOR="emacsclient --alternate-editor emacs +%d %s"
As a special exception, if command is the empty string, then
emacsclient starts Emacs in daemon mode and then tries
connecting again.
The environment variable ALTERNATE_EDITOR has the same effect as
the ‘-a’ option. If both are present, the latter takes
precedence.
An Emacs server usually uses an operating system feature called a “local socket” to listen for connections. Some operating systems, such as Microsoft Windows, do not support local sockets; in that case, Emacs uses TCP instead. When you start the Emacs server, Emacs creates a server file containing some TCP information that emacsclient needs for making the connection. By default, the server file is in ~/.emacs.d/server/. On Microsoft Windows, if emacsclient does not find the server file there, it looks in the .emacs.d/server/ subdirectory of the directory pointed to by the APPDATA environment variable. You can tell emacsclient to use a specific server file with the ‘-f’ or ‘--server-file’ option, or by setting the EMACS_SERVER_FILE environment variable.
Even if local sockets are available, you can tell Emacs to use TCP by
setting the variable server-use-tcp to t. One advantage
of TCP is that the server can accept connections from remote machines.
For this to work, you must (i) set the variable server-host to
the hostname or IP address of the machine on which the Emacs server
runs, and (ii) provide emacsclient with the server file.
(One convenient way to do the latter is to put the server file on a
networked file system such as NFS.)
server-name on the Emacs server. If
this option is omitted, emacsclient connects to the first
server it finds. (This option is not supported on MS-Windows.)
If you type C-x C-c (save-buffers-kill-terminal) in an
Emacs frame created with emacsclient, via the ‘-c’ or
‘-t’ options, Emacs deletes the frame instead of killing the
Emacs process itself. On a text-only terminal frame created with the
‘-t’ option, this returns control to the terminal. Emacs also
marks all the server buffers for the client as finished, as though you
had typed C-x # in all of them.
When Emacs is started as a daemon, all frames are considered client frames, so C-x C-c will never kill Emacs. To kill the Emacs process, type M-x kill-emacs.