首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Emacs -不使用emacsclient连接到守护进程(如果存在)

Emacs -不使用emacsclient连接到守护进程(如果存在)
EN

Stack Overflow用户
提问于 2011-11-30 23:32:32
回答 2查看 1.1K关注 0票数 4

如果我的系统上有emacs作为守护进程运行,我可以使用emacsclient轻松地连接到它。这是我知道的。然而,我想知道的是,如果守护进程已经在运行,是否有一种方法可以告诉emacs (而不是emacsclient)表现得像emacsclient?

例如:

代码语言:javascript
复制
# 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做些什么来复制这种行为吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 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,然后再次尝试连接。

票数 11
EN

Stack Overflow用户

发布于 2021-05-01 23:27:59

你可以用emacsclient来做-a ''的事情,但是我和很多人所做的是编写某种脚本,它基本上可以在多个步骤中完成emacsclient ''所做的事情。

我的版本类似于下面的BASH脚本:您感兴趣的部分是ensure-server-is-running函数。这是脚本的“主函数”,后面是ensure-server-is-running函数,后面的部分是为了满足您的好奇心,但对回答问题没有任何帮助。

代码语言:javascript
复制
#!/bin/bash
# ec.sh
#
# [function definitions]
#

ensure-server-is-running
ensure-frame-exists

focus-current-frame

确保服务器正在运行

代码语言:javascript
复制
# 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
}

另外两个函数:

代码语言:javascript
复制
# 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窗口的一种非常快速的方式。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8328469

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档