GNU Info

Info Node: (efaq)Using an already running Emacs process

(efaq)Using an already running Emacs process


Next: Compiler error messages Prev: Changing load-path Up: Common requests
Enter node , (file) or (file)node

How do I use an already running Emacs from another window?
==========================================================

   `emacsclient', which comes with Emacs, is for editing a file using
an already running Emacs rather than starting up a new Emacs.  It does
this by sending a request to the already running Emacs, which must be
expecting the request.

   * Setup:

     Emacs must have executed the `server-start' function for
     `emacsclient' to work.  This can be done either by a command line
     option:

          emacs -f server-start

     or by invoking `server-start' from `.emacs':

          (if (SOME CONDITIONS ARE MET) (server-start))

     When this is done, Emacs starts a subprocess running a program
     called `emacsserver'.  `emacsserver' creates a Unix domain socket.
     The socket is either named `.emacs_server', in the user's home
     directory, or `esrv-USERID-SYSTEMNAME', in the `/tmp' directory,
     depending on how `emacsserver' was compiled.

     To get your news reader, mail reader, etc., to invoke
     `emacsclient', try setting the environment variable `EDITOR' (or
     sometimes `VISUAL') to the value `emacsclient'.  You may have to
     specify the full pathname of the `emacsclient' program instead.
     Examples:

          # csh commands:
          setenv EDITOR emacsclient
          
          # using full pathname
          setenv EDITOR /usr/local/emacs/etc/emacsclient
          
          # sh command:
          EDITOR=emacsclient ; export EDITOR

   * Normal use:

     When `emacsclient' is run, it connects to the `.emacs_server'
     socket and passes its command line options to `server'.  When
     `server' receives these requests, it sends this information to the
     the Emacs process, which at the next opportunity will visit the
     files specified.  (Line numbers can be specified just like with
     Emacs.)  The user will have to switch to the Emacs window by hand.
     When the user is done editing a file, the user can type `C-x #'
     (or `M-x server-edit') to indicate this.  If there is another
     buffer requested by `emacsclient', Emacs will switch to it;
     otherwise `emacsclient' will exit, signaling the calling program
     to continue.

     `emacsclient' and `server' must be running on machines which share
     the same filesystem for this to work.  The pathnames that
     `emacsclient' specifies should be correct for the filesystem that
     the Emacs process sees.  The Emacs process should not be suspended
     at the time `emacsclient' is invoked.  On Unix and GNU/Linux
     systems, `emacsclient' should either be invoked from another X
     window, or from a shell window inside Emacs itself, or from
     another interactive session, e.g., by means of a `screen' program.

     There is an enhanced version of `emacsclient'/server called
     `gnuserv', written by Andy Norman <ange@hplb.hpl.hp.com> which is
     available in the Emacs Lisp Archive (Note: Packages that do not
     come with Emacs).  `gnuserv' uses Internet domain sockets, so it
     can work across most network connections.  It also supports the
     execution of arbitrary Emacs Lisp forms and does not require the
     client program to wait for completion.

     The alpha version of an enhanced `gnuserv' is available at

     `ftp://ftp.wellfleet.com/netman/psmith/emacs/gnuserv-2.1alpha.tar.gz'



automatically generated by info2www version 1.2.2.9