如何仅在未启动的情况下启动emacs服务器?
我想使用 emacsclient 在 Mutt 中编辑电子邮件。
中添加了这个
我在 .emacs (server-start)
,在 .muttrc 中我添加了
set editor="emacsclient -nw %s"
看来它们有效。 当我启动第二个 Emacs 时,它抱怨已经有一个服务器正在运行,因此会发出错误。如何确保仅在服务器尚未启动时才执行 (server-start)
?
谢谢
I'd like to use emacsclient to edit emails in Mutt.
I added this in .emacs
(server-start)
And in .muttrc I added
set editor="emacsclient -nw %s"
It seems they work.
When I start a second Emacs, it complains there is already a server running so it issues errors. How to make sure to do (server-start)
only if the server isn't already started?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
此代码仅在服务器未运行时启动服务器:
This code starts the server only if it's not running:
emacs 守护进程可以以非常简单的方式自动启动。只需将其添加到您的 .bashrc/.zshrc/whatever
现在,当您调用
emacsclient
时(使用--tty
或--create-frame
)如果服务器尚未运行,则将启动服务器(使用emacs --daemon
)。我还发现这个 shell 别名很方便:
请注意,从 Emacs 23 开始,这是在守护进程模式下使用 Emacs 的首选方式。
(start-server)
现在大部分已被弃用。The emacs daemon can be started automatically in a very simple manner. Just add this to your .bashrc/.zshrc/whatever
Now when you invoke
emacsclient
(using either--tty
or--create-frame
) the server will be started (withemacs --daemon
) if it's not already running.I also find this shell alias handy:
Note that since Emacs 23 this is the preferred way to use Emacs in daemon mode.
(start-server)
is now mostly deprecated.答案有点晚了,但这是对我有用的解决方案。每当我启动 emacsclient 时,我都会使用
emacsclient -a '' -c
-a ''
告诉 emacsclient 尝试连接到现有服务器,如果不存在服务器,启动一个然后连接到它。A bit of a late answer, but here is the solution that works for me. Whenever I start emacsclient, I use
emacsclient -a '' -c
The-a ''
tells emacsclient to attempt to connect to an existing server, and if no server exists, start one then connect to it.通过在任何 shell 或终端中完全避免该问题,
以便 Emacs 在后台运行。这样,
emacsclient
总是很高兴,因为总是有一个 Emacs 服务器可以连接。这就是 Emacs,还有一个仅在需要时启动服务器的功能,但我现在不太记得它的名字了。我自己也很高兴地使用
--daemon
选项。Avoid the problem alltogether via
in any shell or terminal so that Emacs runs in the background. That way
emacsclient
is always happy as there is always an Emacs server to connect to.This being Emacs, there is also a function that starts the server only when needed but I can't quite recall its name right now. I use the
--daemon
option happily quite happily myself.将其添加到您的
.bashrc
/.zshrc
更新: 现在我更喜欢使用这一行:
因为进程名称将取决于您的计算机或者你安装 emacs 的方式。
现在,您的 shell 将在启动时启动守护程序,但前提是它尚未运行。首次运行
emacsclient -t
时的等待时间更少,并且比让emacs --daemon
检查它是否已在运行更快。作为替代方案,您可以简单地添加:
Add this to your
.bashrc
/.zshrc
Update: now I prefer to use this line instead:
because the process name will depend on your machine or the way you installed emacs.
Now your shell will start the deamon on startup, but only if it is not already running. Less wait time when you first run
emacsclient -t
, and it is faster than lettingemacs --daemon
check if it's already running.As an alternative you could simply add: