[ < ] [ > ]   [ << ] [Plus haut] [ >> ]         [Top] [Table des matières] [Index] [ ? ]

42.1 Invoking emacsclient

To run the emacsclient program, specify file names as arguments, and optionally line numbers as well, like this:

 
emacsclient {[+line[column]] filename}

This tells Emacs to visit each of the specified files; if you specify a line number for a certain file, Emacs moves to that line in the file. If you specify a column number as well, Emacs puts point on that column in the line.

Ordinarily, emacsclient does not return until you use the C-x # command on each of these buffers. When that happens, Emacs sends a message to the emacsclient program telling it to return.

If you invoke emacsclient for more than one file, the additional client buffers are buried at the bottom of the buffer list (voir la section Using Multiple Buffers). If you call C-x # after you are done editing a client buffer, the next client buffer is automatically selected.

But if you use the option ‘-n’ or ‘--no-wait’ when running emacsclient, then it returns immediately. (You can take as long as you like to edit the files in Emacs.)

The option ‘-a command’ or ‘--alternate-editor=command’ specifies a command to run if 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"

The environment variable ALTERNATE_EDITOR has the same effect, with the value of the ‘--alternate-editor’ option taking precedence.

If you use several displays, you can tell Emacs on which display to open the given files with the ‘-d display’ or ‘--display=display’ option to emacsclient. This is handy when connecting from home to an Emacs session running on your machine at your workplace.

If there is more than one Emacs server running, you can specify a server name with the ‘-s name’ or ‘--socket-name=name’ option to emacsclient. (This option is not supported on MS-Windows.)

You can also use emacsclient to execute any piece of Emacs Lisp code, using the ‘-e’ or ‘--eval’ option. When this option is given, the rest of the arguments is interpreted as a list of expressions to evaluate, not a list of files to visit.

When you start the Emacs server (by calling server-start), Emacs creates a file with information about TCP connection to the server: the host where Emacs is running, the port where it is listening, and an authentication string. emacsclient uses this information if it needs to connect to the server via TCP. By default, the file goes in the ‘~/.emacs.d/server/’ directory(19). You can specify the file name to use with the ‘-f file’ or ‘--server-file=file’ options, or by setting EMACS_SERVER_FILE environment variable to the file name.


[ < ] [ > ]   [ << ] [Plus haut] [ >> ]         [Top] [Table des matières] [Index] [ ? ]

Ce document a été généré par Eric Reinbold le 23 Février 2009 en utilisant texi2html 1.78.