你可以用它来做这-a ''
件事,emacsclient
但我和很多人所做的是拥有某种脚本,它基本上可以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 Automator 应用程序中。当有一个 emacs GUI 框架时,执行 Spotlight Search“EmacsC”(通常只需输入“e”就足够了),将我放在我的 emacs 窗口中。这是切换到 emacs 窗口的超快速方式。