Various programs such as
EDITOR to specify which editor to run. If you set
EDITOR to `emacs', they invoke Emacs--but in an
inconvenient fashion, by starting a new, separate Emacs process. This
is inconvenient because it takes time and because the new Emacs process
doesn't share the buffers in the existing Emacs process.
You can arrange to use your existing Emacs process as the editor for
First, the preparation. Within Emacs, call the function
server-start. (Your `.emacs' file can do this automatically
if you add the expression
(server-start) to it.) Then, outside
Emacs, set the
EDITOR environment variable to `emacsclient'.
(Note that some programs use a different environment variable; for
example, to make TeX use `emacsclient', you should set the
TEXEDIT environment variable to `emacsclient +%d %s'.)
Then, whenever any program invokes your specified
program, the effect is to send a message to your principal Emacs telling
it to visit a file. (That's what the program
Emacs displays the buffer immediately and you can immediately begin
When you've finished editing that buffer, type C-x #
server-edit). This saves the file and sends a message back to
emacsclient program telling it to exit. The programs that
EDITOR wait for the "editor" (actually,
to exit. C-x # also checks for other pending external requests
to edit various files, and selects the next such file.
You can switch to a server buffer manually if you wish; you don't have to arrive at it with C-x #. But C-x # is the only way to say that you are "finished" with one.
If you set the variable
server-window to a window or a frame,
C-x # displays the server buffer in that window or in that frame.
emacsclient to finish,
emacsclient does not read terminal
input. So the terminal that
emacsclient, the window where it was running is blocked, but you can use Emacs by switching windows.
emacsclientblocks only the subshell under Emacs, and you can still use Emacs to edit the file.
Some programs write temporary files for you to edit. After you edit
the temporary file, the program reads it back and deletes it. If the
Emacs server is later asked to edit the same file name, it should assume
this has nothing to do with the previous occasion for that file name.
The server accomplishes this by killing the temporary file's buffer when
you finish with the file. Use the variable
server-temp-file-regexp to specify which files are temporary in
this sense; its value should be a regular expression that matches file
names that are temporary.
If you run
emacsclient with the option `--no-wait', it
returns immediately without waiting for you to "finish" the buffer in
Go to the first, previous, next, last section, table of contents.