Difference between revisions of "Emacs server"

From WikEmacs
Jump to: navigation, search
(With server-start)
m (Adding To OS Starup)
 
(10 intermediate revisions by 8 users not shown)
Line 2: Line 2:
  
 
== Starting the Server ==
 
== Starting the Server ==
=== With {{Command|server-start} ===
+
 
 +
=== With <code>server-start</code> ===
 
To start a server in an existing Emacs session, run {{Command|server-start}}. A server started in this manner will close when the last visible Emacs frame closes. If you want Emacs to automatically run a server on startup, add the following to your configuration file.
 
To start a server in an existing Emacs session, run {{Command|server-start}}. A server started in this manner will close when the last visible Emacs frame closes. If you want Emacs to automatically run a server on startup, add the following to your configuration file.
  
Line 10: Line 11:
  
 
=== With <tt>--daemon</tt> ===
 
=== With <tt>--daemon</tt> ===
Emacs 24 and higher provide the <tt>--daemon</tt> command-line argument, which will cause Emacs to immediately start a server and fork into the background. A server started in this manner is fully daemonized and will remain running even with no visible Emacs frames and after its parent terminal has closed (for example, after an SSH session has disconnected).
+
Emacs 23 and higher provide the <tt>--daemon</tt> command-line argument, which will cause Emacs to immediately start a server and fork into the background. A server started in this manner is fully daemonized and will remain running even with no visible Emacs frames and after its parent terminal has closed (for example, after an SSH session has disconnected).  
  
 
Note that, if using <tt>--daemon</tt>, your configuration file will be run while Emacs is still in a terminal. This may affect your theming if you usually use graphical Emacs.
 
Note that, if using <tt>--daemon</tt>, your configuration file will be run while Emacs is still in a terminal. This may affect your theming if you usually use graphical Emacs.
 +
 +
{{Note}}This option is not supported on [[Windows]].
  
 
== Using Clients ==
 
== Using Clients ==
Line 19: Line 22:
  
 
If the server was started using <tt>--daemon</tt>, you should run <tt>emacsclient -t</tt> or <tt>emacsclient -nc</tt> to create a visible frame to interact with.
 
If the server was started using <tt>--daemon</tt>, you should run <tt>emacsclient -t</tt> or <tt>emacsclient -nc</tt> to create a visible frame to interact with.
 
 
== Finishing Up ==
 
== Finishing Up ==
  
Once you have finished with a buffer that was opened via <tt>emacsclient</tt> you should use the {{Keys|C-x #}} or {{Command|server-edit}} to properly close the loop. Killing the buffer normally will not send the signal to <tt>emacsclient</tt> that Emacs has finished with the file.
+
Once you have finished with a buffer that was opened via <tt>emacsclient</tt> you should use the {{CommandKeys|C-x #|server-edit}} to properly close the loop. Killing the buffer normally will not send the signal to <tt>emacsclient</tt> that Emacs has finished with the file.
  
If you're in an Emacs session that was started using <tt>--daemon</tt>, <code>C-x C-c</code> will only close the frame that it was invoked in. It will also signal to the client that owns the frame that its editing job is done, so <tt>emacsclient -c</tt> or <tt>emacsclient -t</tt> as <tt>EDITOR</tt> will behave much like a full <tt>emacs</tt> or <tt>emacs -nw</tt>.
+
If you're in an Emacs session that was started using <tt>--daemon</tt>, {{Keys|C-x C-c}} will only close the frame that it was invoked in. It will also signal to the client that owns the frame that its editing job is done, so <tt>emacsclient -c</tt> or <tt>emacsclient -t</tt> as <tt>EDITOR</tt> will behave much like a full <tt>emacs</tt> or <tt>emacs -nw</tt>.
  
 
To entirely close a server started with <tt>--daemon</tt>, run {{Command|save-buffers-kill-emacs}} in a frame.
 
To entirely close a server started with <tt>--daemon</tt>, run {{Command|save-buffers-kill-emacs}} in a frame.
 +
= Adding To OS Startup =
 +
== Debian/Ubuntu ==
 +
== Arch ==
 +
== Gentoo ==
 +
== In OS X ==
 +
[[Category: Server]]

Latest revision as of 06:38, 23 January 2013

Emacs includes an optional client-server architecture.

Starting the Server[edit]

With server-start[edit]

To start a server in an existing Emacs session, run M-x server-start. A server started in this manner will close when the last visible Emacs frame closes. If you want Emacs to automatically run a server on startup, add the following to your configuration file.

(server-start)

With --daemon[edit]

Emacs 23 and higher provide the --daemon command-line argument, which will cause Emacs to immediately start a server and fork into the background. A server started in this manner is fully daemonized and will remain running even with no visible Emacs frames and after its parent terminal has closed (for example, after an SSH session has disconnected).

Note that, if using --daemon, your configuration file will be run while Emacs is still in a terminal. This may affect your theming if you usually use graphical Emacs.

Note Note: This option is not supported on Windows.

Using Clients[edit]

Once the server is started you may use the emacsclient command outside of Emacs to send a file to Emacs for editing, e.g. emacsclient ~/.emacs.d/init.el to modify your init file. On a GNU/Linux system it might be a good idea to set your EDITOR environment variable to emacsclient or emacsclient -t. Using emacsclient without any arguments will cause the calling process to simply pause and wait for the Emacs server to report that it's done editing. Using emacsclient -t will cause the calling process to put up a text-mode frame in the same terminal.

If the server was started using --daemon, you should run emacsclient -t or emacsclient -nc to create a visible frame to interact with.

Finishing Up[edit]

Once you have finished with a buffer that was opened via emacsclient you should use the [C-x #] (or M-x server-edit) to properly close the loop. Killing the buffer normally will not send the signal to emacsclient that Emacs has finished with the file.

If you're in an Emacs session that was started using --daemon, [C-x C-c] will only close the frame that it was invoked in. It will also signal to the client that owns the frame that its editing job is done, so emacsclient -c or emacsclient -t as EDITOR will behave much like a full emacs or emacs -nw.

To entirely close a server started with --daemon, run M-x save-buffers-kill-emacs in a frame.

Adding To OS Startup[edit]

Debian/Ubuntu[edit]

Arch[edit]

Gentoo[edit]

In OS X[edit]