4

システムで 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 に対してできることはありますか?

4

2 に答える 2

11

私はそうは思いませんがemacsclient、オプションとして空の文字列を使用することで同様の効果を達成でき--alternate-editorますか?http://www.gnu.org/s/libtool/manual/emacs/emacsclient-Options.html#emacsclient-Optionsから:

-a command

--alternate-editor=command

。。。特別な例外として、コマンドが空の文字列の場合、emacsclientはEmacsをデーモンモードで起動してから、接続を再試行します。

于 2011-11-30T16:07:46.483 に答える
0

あなたはそれを行うことができます-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
}

他の 2 つの機能は次のとおりです。

# 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-frameOSがあなたを現在のEmacsフレームに入れるものです。これが最も重要な機能です。私にとっては、これを適応させたバージョンを MacOS Automator アプリに挿入します。emacs GUI フレームがある場合、Spotlight Search "EmacsC" を実行すると (通常は "e" と入力するだけで十分です)、emacs ウィンドウが表示されます。これは、emacs ウィンドウに切り替える超高速の方法です。

于 2021-05-01T15:27:59.450 に答える