如果我的系统上有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做些什么来复制这种行为吗?
发布于 2011-12-01 00:07:46
我不这么认为,但是您可以通过使用带有空字符串的emacsclient作为--alternate-editor选项来达到类似的效果吗?来自http://www.gnu.org/s/libtool/manual/emacs/emacsclient-Options.html#emacsclient-Options
-a command
--alternate-editor=command
。。。作为一个特殊的例外,如果command是空字符串,那么emacsclient将在守护进程模式下启动Emacs,然后再次尝试连接。
发布于 2021-05-01 23:27:59
你可以用emacsclient来做-a ''的事情,但是我和很多人所做的是编写某种脚本,它基本上可以在多个步骤中完成emacsclient ''所做的事情。
我的版本类似于下面的BASH脚本:您感兴趣的部分是ensure-server-is-running函数。这是脚本的“主函数”,后面是ensure-server-is-running函数,后面的部分是为了满足您的好奇心,但对回答问题没有任何帮助。
#!/bin/bash
# ec.sh
#
# [function definitions]
#
ensure-server-is-running
ensure-frame-exists
focus-current-frame确保服务器正在运行
# ec.sh function definition
# From https://emacs.stackexchange.com/a/12896/19972
function server-is-running() {
emacsclient -e '(+ 1 0)' > /dev/null 2>&1
}
function ensure-server-is-running(){
if ! server-is-running ; then
echo "Need to start daemon, press enter to continue, C-c to abort"
read
emacs --daemon
fi
}另外两个函数:
# ec.sh function definition
# From https://superuser.com/a/862809
function frame-exists() {
emacsclient -n -e "(if (> (length (frame-list)) 1) 't)" 2>/dev/null | grep -v nil >/dev/null 2>&1
}
function ensure-frame-exists() {
if ! frame-exists ; then
emacsclient -c --no-wait
fi
}
# From https://emacs.stackexchange.com/a/54139/19972
function focus-current-frame() {
# Doesn't work a frame exists and is in a terminal
emacsclient --eval "(progn (select-frame-set-input-focus (selected-frame)))"
}focus-current-frame会让操作系统把你放到当前的Emacs框架中。这是最重要的特性。对我来说,我在MacOS自动化应用程序中插入了一个经过调整的版本。当有一个emacs GUI框架时,执行Spotlight搜索"EmacsC“(通常只需输入"e”就足够了),就会进入我的emacs窗口。这是切换到emacs窗口的一种非常快速的方式。
https://stackoverflow.com/questions/8328469
复制相似问题