Emacsのファイルローカル変数について

ファイルローカル変数とは、ファイルの1行目に以下のようなコメントを設定しておくことで、ファイル内で有効なemacsの変数を定義できる、というものです
(1行目に設定する以外の方法もあります)

# -*- mode: python; coding:utf-8; -*-


上記の設定でmajar-modeとしてpython-modeが、buffer-file-coding-systemとしてutf-8が使用されるようになります。
また任意の変数を設定することもできます。

# -*- mode: python; coding:utf-8; a:1; b:2; -*-


使いようによっては便利なのかもしれませんが、チームで開発する場合では注意が必要だと思ってます。


メンバ全員がemacsを使っていない場合、vimユーザーやtextmateのユーザーなどにとっては無用なコメントである、というのが理由のひとつです。


また、メンバがemacsを使っていたとしても、ファイルローカル変数は以下のような警告を出す場合があります。

The local variables list in main.py
contains values that may not be safe (*).

Do you want to apply it?  You can type
y  -- to apply the local variables list.
n  -- to ignore the local variables list.
!  -- to apply the local variables list, and permanently mark these
      values (*) as safe (in the future, they will be set automatically.)

  * a : 1
  * b : 2


このローカル変数は危険かもしれないけど、適用してもいいのか?という警告です。
yで適用し、nで無視します。

!で以下の様な感じで、設定ファイル(~/.emacs.d/init.elなど)に「これらの変数を安全と認め、今後は適用する」という設定を書き込みます

(custom-set-variables
  ;; custom-set-variables was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 '(safe-local-variable-values (quote ((b . 2) (a . 1))))
 )

ファイルを開くたびに警告がでるのは煩わしいですし、設定ファイルを変更しないといけないというのも、私は抵抗があります。

ほとんどの用途は個人の設定ファイルの設定で事足りると思うので、できるかぎりチーム開発ではファイルローカル変数を使わないほうがよいのではないかと思います