Indiana University
University Information Technology Services
  
What are archived documents?
Login>>
Login

Login is for authorized groups (e.g., UITS, OVPIT, and TCC) that need access to specialized Knowledge Base documents. Otherwise, simply use the Knowledge Base without logging in.

Close

In Emacs, how do I use an already running session from another window?

The Emacsclient program can let you edit a file using an already running Emacs session rather than starting up a new one. It does this by sending a request to the already running Emacs, which must be expecting the request.

Setup

In order for Emacsclient to work, you must first execute the Server-start function. You can do this by entering the following command line option: emacs -f server-start

Another way to invoke Server-start is from the .emacs file: (if (some conditions are met) (server-start))

When you do this, Emacs starts a subprocess running a program called Server. Server creates a Unix domain socket in the user's home directory named .emacs_server.

To invoke Emacsclient from your newsreader, mail reader, etc., 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, for example: # csh commands: setenv EDITOR emacsclient setenv EDITOR /usr/local/emacs/etc/emacsclient # using full pathname # 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 on the Emacs process, which at the next opportunity will visit the files specified. (You can specify line numbers just like with Emacs.) You will have to switch to the Emacs window by hand. After editing a file, you can type C-x # to indicate this. This will switch to another buffer created at the request of Emacsclient if there are any. When you have invoked C-x # on all of the files that Emacsclient requested to be edited, Emacs will send notification of this to Server which will pass this on to Emacsclient, which will then exit.

Note: Emacsclient and Server must be running on computers 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 you invoke Emacsclient. You should invoke Emacsclient either from another window or from a shell window inside Emacs itself.

There is an enhanced version of Emacsclient/Server called Gnuserv which is available in the Emacs Lisp Archive. Gnuserv uses Internet domain sockets, so it can work across most network connections. It also supports the execution of arbitrary Emacs Lisp forms and also does not require the client program to wait for completion. It is available via anonymous FTP from the Emacs Lisp Archive, in the directory packages/gnuserv.shar.

This information comes from the Emacs FAQ.

At Indiana University, for personal or departmental Linux or Unix systems support, see At IU, how do I get support for Linux or Unix?

This is document abun in domain all.
Last modified on August 22, 2008.

Comments/Questions/Corrections

Use this form to offer suggestions, corrections, and additions to the Knowledge Base. We welcome your input!

If you are affiliated with Indiana University and would like assistance with a specific computing problem, please use the Ask a Consultant form, or contact your campus Support Center.

Contact Information

Note: We will reply to your comment at this address. If your message concerns a problem receiving email, please enter an alternate email address.