emacsclient Options
You can pass some optional arguments to the emacsclient program, such as:
emacsclient -c +12 @var{file1} +4:3 @var{file2}
@noindent 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. Action Arguments. The other optional arguments recognized by emacsclient are listed below:
- -a command, –alternate-editor=/command/
- Specify a shell command to run if
emacsclientfails to contact Emacs. This is useful when runningemacsclientin a script. The command may include arguments, which may be quoted "like this". Currently, escaping of quotes is not supported. As a special exception, if command is the empty string, thenemacsclientstarts Emacs in daemon mode (asemacs --daemon) and then tries connecting again. The environment variableALTERNATE_EDITORhas the same effect as the-aoption. If both are present, the latter takes precedence. - -c, –create-frame
- Create a new graphical client frame, instead of using an existing Emacs frame. See below for the special behavior of
C-x C-cin a client frame. If Emacs cannot create a new graphical frame (e.g., if it cannot connect to the X server), it tries to create a text terminal client frame, as though you had supplied the-toption instead. On MS-Windows, a single Emacs session cannot display frames on both graphical and text terminals, nor on multiple text terminals. Thus, if the Emacs server is running on a text terminal, the-coption, like the-toption, creates a new frame in the server's current text terminal. Windows Startup. If you omit a filename argument while supplying the-coption, the new frame displays the*scratch*buffer by default. You can customize this behavior with the variableinitial-buffer-choice(Entering Emacs). - -r, –reuse-frame
- Create a new graphical client frame if none exists, otherwise use an existing Emacs frame.
- -F alist, –frame-parameters=/alist/
- Set the parameters for a newly-created graphical frame (Frame Parameters).
- -d display, –display=/display/
- Tell Emacs to open the given files on the X display display (assuming there is more than one X display available).
- -e, –eval
- Tell Emacs to evaluate some Emacs Lisp code, instead of visiting some files. When this option is given, the arguments to
emacsclientare interpreted as a list of expressions to evaluate, not as a list of files to visit. Passing complex Lisp expression via the--evalcommand-line option sometimes requires elaborate escaping of characters special to the shell. To avoid this, you can pass arguments to Lisp functions in your expression as additional separate arguments toemacsclient, and use server-eval-args-left in the expression to access those arguments. Be careful to have your expression remove the processed arguments from server-eval-args-left regardless of whether your code succeeds, for example by usingpop, otherwise Emacs will attempt to evaluate those arguments as separate Lisp expressions. - -f server-file, –server-file=/server-file/
- Specify a server file (TCP Emacs server) for connecting to an Emacs server via TCP. Alternatively, you can set the
EMACS_SERVER_FILEenvironment variable to point to the server file. (The command-line option overrides the environment variable.) An Emacs server usually uses a local socket to listen for connections, but also supports connections over TCP. To connect to a TCP Emacs server,emacsclientneeds to read a server file containing the connection details of the Emacs server. The name of this file is specified with this option, either as a file name relative to~/.emacs.d/serveror as an absolute file name. TCP Emacs server. - -n, –no-wait
- Let
emacsclientexit immediately, instead of waiting until all server buffers are finished. You can take as long as you like to edit the server buffers within Emacs, and they are not killed when you typeC-x #in them. - -w, –timeout=/N/
- Wait for a response from Emacs for N seconds before giving up. If there is no response within that time,
emacsclientwill display a warning and exit. The default is0, which means to wait forever. - –parent-id=/id/
- Open an
emacsclientframe as a client frame in the parent X window with id id, via the XEmbed protocol. Currently, this option is mainly useful for developers. - -q, –quiet
- Do not let
emacsclientdisplay messages about waiting for Emacs or connecting to remote server sockets. - -u, –suppress-output
- Do not let
emacsclientdisplay results returned from the server. Mostly useful in combination with-ewhen the evaluation performed is for side-effect rather than result. - -s server-name, –socket-name=/server-name/
- Connect to the Emacs server named server-name. (This option is not supported on MS-Windows.) The server name is given by the variable
server-nameon the Emacs server. If this option is omitted,emacsclientconnects to the default socket. If you setserver-nameof the Emacs server to an absolute file name, give the same absolute file name as server-name to this option to instructemacsclientto connect to that server. You need to use this option if you started Emacs as daemon (Initial Options) and specified the name for the server started by the daemon. Alternatively, you can set theEMACS_SOCKET_NAMEenvironment variable to point to the server socket. (The command-line option overrides the environment variable.) - -t, –tty, -nw, –no-window-system
- Create a new client frame on the current text terminal, instead of using an existing Emacs frame. This behaves just like the
-coption, described above, except that it creates a text terminal frame (Text Terminals). On MS-Windows,-tbehaves just like-cif the Emacs server is using the graphical display, but if the Emacs server is running on a text terminal, it creates a new frame in the current text terminal. - -T tramp-prefix, –tramp=/tramp-prefix/
- Set the prefix to add to filenames for Emacs to locate files on remote machines (Remote Files) using TRAMP (The Tramp Manual). This is mostly useful in combination with using the Emacs server from a remote host. By ssh-forwarding the listening socket, or ssh-forwarding the listening port TCP Emacs server and making the server-file available on a remote machine, programs on the remote machine can use
emacsclientas the value for theEDITORand similar environment variables, but instead of talking to an Emacs server on the remote machine, the files will be visited in the local Emacs session using TRAMP. Setting the environment variableEMACSCLIENT_TRAMPhas the same effect as using the-Toption. If both are specified, the command-line option takes precedence. For example, assume two hosts,localandremote. @example local$ ssh -R "/home/%r/.emacs.socket":"$@{XDG_RUNTIME_DIR:-$@{TMPDIR:-/tmp@}/emacs%i@}$@{XDG_RUNTIME_DIR:+/emacs@}/server" remote remote$ export EMACS_SOCKET_NAME=$HOME/.emacs.socket remote$ export EMACSCLIENT_TRAMP=/ssh:remote: remote$ export EDITOR=emacsclient remote$ $EDITOR tmp/foo.txt #Should open in local emacs. @end example If you are using a platform whereemacsclientdoes not use Unix domain sockets (i.e., MS-Windows), or your SSH implementation is not able to forward them (e.g., OpenSSH before version 6.7), you can forward a TCP port instead. In this example, assume that the local Emacs listens on tcp port 12345. Assume further that/homeis on a shared file system, so that the server file =~.emacs.d/server/server= is readable on both hosts. @example local$ ssh -R12345:localhost:12345 remote remote$ export EMACS_SERVER_FILE=server remote$ export EMACSCLIENT_TRAMP=/ssh:remote: remote$ export EDITOR=emacsclient remote$ $EDITOR /tmp/foo.txt #Should open in local emacs. @end example - -V, –version
- Print version information and exit.
- -H, –help
- Print usage information message and exit.
The new graphical or text terminal frames created by the -c or -t options are considered client frames. Any new frame that you create from a client frame is also considered a client frame. If you type C-x C-c (save-buffers-kill-terminal) in a client frame, that command does not kill the Emacs session as it normally does (Exiting). Instead, Emacs deletes the client frame; furthermore, if the client frame has an emacsclient waiting to regain control (i.e., if you did not supply the -n option), Emacs deletes all other frames of the same client, and marks the client's server buffers as finished, as though you had typed C-x # in all of them. If it so happens that there are no remaining frames after the client frame(s) are deleted, the Emacs session exits. As an exception, when Emacs is started as a daemon, all frames are considered client frames, and C-x C-c never kills Emacs. To kill a daemon session, type M-x kill-emacs. Note that the -t and -n options are contradictory: -t says to take control of the current text terminal to create a new client frame, while -n says not to take control of the text terminal. If you supply both options, Emacs visits the specified files(s) in an existing frame rather than a new client frame, negating the effect of -t.