三界:天地人(xgfone)的专栏

我的GNU/Linux--开源世界!

Using Emacs as a server

The new Emacs process doesn't share buffers, a command history, orother kinds of information with any existing Emacs process. You cansolve this problem by setting up Emacs as an edit server, so that it"listens" for external edit requests and acts accordingly.

There are two ways to start an Emacs server.  The first is to run the command server-start in an existing Emacs process:either type M-x server-start, or put the expression (server-start) in your initialization file. The existing Emacs process is the server;  when you exit Emacs, the server dies with the Emacs process.  The second way to start an Emacs server is to run Emacs as a daemon,  using the '--daemon' command-line option.

Oncean Emacs server is set up, you can use a shell command called emacsclient to connect to the existing Emacs process and tell it to
visita file. If you set the EDITOR environment variable to 'emacsclient',programs such as mail will use the existing Emacs process for editting.

Youcan run multiple Emacs servers on the same machine by giving each  onea unique "server name", using the variable server-name. For example, M-x set-variable RET server-name RET foo RET sets the server name to 'foo'. The emacsclient program can specify a server by name, using the '-s' option.

1. Invoking emacsclient
The simplest way to use the emacsclient program is to run the shell command 'emacsclient file', where file is a file name.

Ifthere is no Emacs server, the emacsclient program halts with an errormessage. If the Emacs process has no existing frame---which can happenif it was started as a daemon---then Emacs opens a frame on theterminal in which you called emacsclient. You can also forceemacsclient to open a new frame on a graphical display, or on atext-only terminal,  using the '-c' or '-t' options.

When you finish editing file in the Emacs server, type C-x #(server-edit) in its buffer. This saves the file and sends a message back to the
emacsclient program, telling it to exit.

EachC-x # checks for other pending external requests to edit various files,and selects the next such file. You can switch to a server buffermanually if you wish; you don't have to arrive at it with C-x #. ButC-x # is the way to tell emacsclient that you are finished.

NOTE: This article comes from GNU Emacs Manual.
阅读更多
个人分类: emacs
想对作者说点什么? 我来说一句

emacs 24 hours PDF

2011年02月16日 1.92MB 下载

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭