如何启动emacs服务器?

时间:2011-04-06 17:24:51

标签: emacs configuration mutt

我想使用emacsclient编辑Mutt中的电子邮件。

我在.emacs中添加了这个

(server-start)

在.muttrc中我添加了

set editor="emacsclient -nw %s"

它们似乎有效。 当我启动第二个Emacs时,它抱怨已经有一个服务器正在运行,因此它会发出错误。如何确保仅在服务器尚未启动时执行(server-start)

由于

5 个答案:

答案 0 :(得分:57)

此代码仅在服务器未运行时启动服务器:

(load "server")
(unless (server-running-p) (server-start))

答案 1 :(得分:46)

可以以非常简单的方式自动启动emacs守护程序。只需将其添加到.bashrc / .zshrc /无论

export ALTERNATE_EDITOR=""

现在,当您调用emacsclient时(使用--tty--create-frame),服务器将启动(使用emacs --daemon),如果它尚未运行。

我也发现这个shell别名很方便:

alias e='emacsclient --tty'

请注意,由于Emacs 23,这是在守护进程模式下使用Emacs的首选方法。 (start-server)现在大部分已被弃用。

答案 2 :(得分:10)

有点迟到的答案,但这是适用于我的解决方案。每当我启动emacsclient时,我都使用emacsclient -a '' -c -a ''告诉emacsclient尝试连接到现有服务器,如果没有服务器,则启动一个然后连接到它。

答案 3 :(得分:7)

通过

完全避免这个问题
emacs --daemon

在任何shell或终端中,以便Emacs在后台运行。这样emacsclient总是很高兴,因为总有一台Emacs服务器要连接。

这是Emacs,还有一个只在需要时启动服务器的功能,但我现在还不记得它的名字。我自己很高兴地使用--daemon选项。

答案 4 :(得分:0)

将此添加到您的 .bashrc/.zshrc

if ! ps -e -o args | grep -q '^emacs --daemon$'; then
  emacs --daemon
else
  echo "Emacs server Online"
fi

现在您的 shell 将在启动时启动守护进程,但前提是它尚未运行。首次运行 emacsclient -t 时等待时间更短,而且比让 emacs --daemon 检查它是否已经在运行要快。

作为替代,您可以简单地添加:

eval 'emacsclient -e "(server-running-p)"'
相关问题