Kentaro Kuribayashi's blog

Software Engineering, Management, Books, and Daily Journal.

シンプルEmacs

極小ネタ。

Emacsに慣れきってしまって、ちょっとしたものを書くのですらVimとかまったく使えない体に成り果ててしまったので、なんでもEmacsでやりたい!!!とか思ったりする。しかし、Emacsをもう一個立ち上げるのも重いし、とりあえず設定ファイルをちょっと修正するぐらいなら、素のEmacsでもなんとかなりそうなので、jedを入れたりするのはおおげさだ。んじゃ、emacs -Q的な感じで起動すればよいじゃないかということになった。

しかし、一個だけ問題があって、デフォルトではC-hでバックスペースにならず、それだけはかなり耐えがたい感じなので、そこんとこだけちょっとどうにかしたものを、id:elimさんと相談の上、というかid:elimさんに教えてもらって、semacsとかいう名前でaliasした。

alias -g semacs="emacs -Q --eval '(keyboard-translate ?\C-h ?\C-?))'"

追記:

僕は普段、multi-ttyが有効なEmacsを使っていて、かつ、EDITOR=emacsclientしてるので、自分のユーザ権限で編集できるものについてはemacsclientで不便がなかったりするのだけど、上記のようなことをしたいと思ったのは、emacsclientじゃsudoできないと思っていたからなのだった。んで、「emacsclient / gnuclientを使えばシェルから既存のEmacsを呼べる - ’(rubikitch wanna be (a . lisper))」を読んだ後に、気になってぐぐってみたら、あー!!!sudoeditあるいはsudo -eでいいのかー。じゃぁ、上記のsemacsとかいらないじゃんw

man sudoeditより引用。

The -e (edit) option indicates that, instead of running a command, the user wishes to edit one or more files. In lieu of a command, the string "sudoedit" is used when consulting the sudoers file. If the user is authorized by sudoers the following steps are taken:

1. Temporary copies are made of the files to be edited with the owner set to the invoking user.

2. The editor specified by the VISUAL or EDITOR environment variables is run to edit the temporary files. If neither VISUAL nor EDITOR are set, the program listed in the editor sudoers variable is used.

3. If they have been modified, the temporary files are copied back to their original location and the temporary versions are removed.

If the specified file does not exist, it will be created. Note that unlike most commands run by sudo, the editor is run with the invoking user's environment unmodified. If, for some reason, sudo is unable to update a file with its edited version, the user will receive a warning and the edited copy will remain in a temporary file.

常識ですか><