id:yaottiさんが便利な関数を書かれていた.
ところで,ElScreenのアドオンで,ElScreen-serverというのがあって,これを使うと,emacsclientからファイルを開く際に,既にそのファイルが開かれたscreenがあればそれを使い,新たに開くファイルならscreenを作ってそこで開く,ということをしてくれる.
ElScreen-serverはElScreenのサイトからダウンロードできる.
これをEmacs側でロードしていれば(設定とかは特になし),以下だけで済む.短くなったし,挙動もこっちのほうが妥当な感じ.
function e() { emacsclient -n $* 2>/dev/null || open -a /Applications/Emacs.app $* }
ついでに,引数を与えないとき,カレントディレクトリを開くようにした.
function e() { emacsclient -n ${*:-.} 2>/dev/null || open -a /Applications/Emacs.app ${*:-.} }
openコマンドの仕様が微妙で,存在しないファイルを開こうとするとエラーが出る.
% e poem.txt emacsclient: connected to remote socket at 255.255.255.255 The file /Users/fkd/poem.txt does not exist.
openコマンドではEmacs.appを開くだけにして,起動を待った後にファイルを開くようにすればよさそう.