LoginSignup
4
4

More than 5 years have passed since last update.

コマンドラインから emacs (emacsclient) を read-only で開く

Last updated at Posted at 2012-06-19

emacs 立ちあげてる状態なら C-xC-r (コマンド経由なら C-xfind-file-read-only) ってやれば、read-only でファイル開ける。じゃーそれをコマンドラインからやる時はどうするかって話。

emacs ならこんな感じ

function read_only_emacs() {
    [ -f "$1" ] || (echo "ファイルが見つかりませんでした: $1" >&2; exit 1)
    emacs "$1" --eval '(setq buffer-read-only t)'
}

ファイル見つからなくても emacs が立ち上がってしまうので、実行前に存在チェックしてる。

emacsclient ならこんな感じ

function read_only_emacsclient() {
    emacsclient -e "(find-file-read-only \"$1\")"
}

ただ、emacsclient -n で普段から使ってない人は、ちょっと違和感のある挙動かも。

4
4
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
4
4