10
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ターミナル上で高速に起動するemacsclientを使う

Posted at

emacsclient

起動中の Emacs (GUI) か daemon を利用する形になるので、
起動時の長ったらしい elisp package や設定の読み込みが省け、かなり高速。

ターミナルで Emacs (CUI) を使いたい場合が多々ある人にはオススメ。

15年も使ってるのに、実は2年ほど前に初めて知った...

設定

ここでは、普段使っている起動中の Emacs (GUI) を利用する方法について記述。
いずれ daemon を利用する方法についても記述したい。

設定は至って簡単。
GUI での起動時のみ有効にする設定は、既に使っていると思われる(なければぐぐるか、コピペ...)
ので、そこに (server-start) を記述してやるだけ。

init.el
(if (eq window-system 'ns)
  (progn

    ; ここにGUIアプリとして起動した時の設定があるはず

    (server-start) ; ← こいつで server 起動
    ))

で、ターミナルから
$ emacsclient -nw hogefile
とすれば良い。

ここで、
$ emacsclient hogefile
とすると、 GUI 側でファイルを開く。これも便利。

ちなみに、 Emacs (GUI) を起動していない状態で emacsclient を起動しようとすると
can't find socket; have you started the server?
みたいなのが出る。


以下は主に OSX で、 Emacs を自力ビルドしている猛者向け。

.zprofile (bash な方は .bash_profile ?)に

.zprofile
export EDITOR=/Applications/Emacs.app/Contents/MacOS/bin/emacsclient

.zshrc (bash な方は .bashrc ?)に

.zshrc
alias emacsclient='/Applications/Emacs.app/Contents/MacOS/bin/emacsclient'

と書いておけば、前述のコマンドのまま使用可能。
自力ビルドしている猛者には、蛇足かも。

環境変数 EDITOR の後ろに -nw を付ける/付けないはお好みで。

10
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?