Emacs - 连接到守护进程(如果存在)而不使用 emacsclient
如果我的系统上有 emacs 作为守护进程运行,我可以使用 emacsclient 轻松连接到它。这我知道。但是,我想知道的是,如果守护进程已经在运行,有没有办法告诉 emacs(不是 emacsclient)表现得像 emacsclient ?
例如,
# emacs daemon is not running
emacs # should start a new frame
# ...
# emacs daemon IS running
emacs # should actually behave like emacsclient, i.e. connect to my daemon
我可以对 init.el 做些什么来复制这种行为吗?
If I have emacs running as a daemon on my system, I can connect to it easily using emacsclient. This I know. However, what I would like to know is, is there a way to tell emacs (not emacsclient) to behave like emacsclient if a daemon is already running?
e.g.
# emacs daemon is not running
emacs # should start a new frame
# ...
# emacs daemon IS running
emacs # should actually behave like emacsclient, i.e. connect to my daemon
Is there anything I can do to my init.el to replicate this kind of behaviour?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不这么认为,但是您可以通过使用带有空字符串的
emacsclient
作为--alternate-editor
选项来实现类似的效果吗?来自 http://www.gnu.org/ s/libtool/manual/emacs/emacsclient-Options.html#emacsclient-Options:I don't think so, but can you achieve a similar effect by using
emacsclient
with an empty string as the the--alternate-editor
option? From http://www.gnu.org/s/libtool/manual/emacs/emacsclient-Options.html#emacsclient-Options:您可以使用
emacsclient
执行-a ''
操作,但我和很多人所做的就是使用某种脚本来基本上执行emacsclient 的操作''
分多个步骤进行。我的版本类似于这个 BASH 脚本:您感兴趣的部分是
ensure-server-is-running
函数。这是脚本的“主要函数”,接下来是ensure-server-is-running
函数,其余部分出于您的好奇心而存在,但对回答问题没有帮助。确保服务器正在运行
另外两个函数:
focus-current-frame
将使操作系统将您置于当前的 Emacs Frame 中。这是最重要的特征。对我来说,我将其改编版本插入到 MacOS Automator 应用程序中。当有 emacs GUI 框架时,执行 Spotlight 搜索“EmacsC”(通常只需键入“e”就足够了),将我置于 emacs 窗口中。这是切换到 emacs 窗口的超快速方法。You can do the
-a ''
thing withemacsclient
but what I do and a lot of people do is to have some kind of script that basically does whatemacsclient ''
does in multiple steps.My version is something like this BASH script: The part you are interested in is the
ensure-server-is-running
function. This is the "main function" of the script, what follows is theensure-server-is-running
function and the rest is there after that for your curiosity but does not contribute to answering the question.Ensuring that the server is running
And the other two function:
focus-current-frame
is something that will make the OS put you in the current Emacs Frame. This is the most important feature. For me I insert an adapted version of this into a MacOS Automator app. When there is an emacs GUI frame, doing Spotlight Search "EmacsC" (usually just typing the "e" is enough), puts me in my emacs window. It's a super fast way of switching to an emacs window.这就是我所做的。这就像 @philippe-carpin 的解决方案,从某种意义上说,它是一个执行多个步骤的脚本:
将打开的文件名。
另外,我的脚本只尝试运行一段 elisp 一次,如果没有守护进程,它不会启动 emacs 进程来运行该 elisp。所以应该会稍微快一些。
Here's what I do. It's like the solution by @philippe-carpin, in the sense that it's a script that does multiple steps:
In all cases you can pass filename(s) that will be opened.
In addition, my script only tries to run a piece of elisp just once and if there's no daemon it will not start an emacs process to run that elisp. So it should be slightly faster.