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.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值