メインコンテンツへスキップ

2020年2月15日 / Emacs における、バイトコンパイルされたelispファイルとそのソースのロード順

    いつも忘れたころにはまるので、備忘録として note にしておきたい。

    Emacs Lisp Reference Manual (version 26.1)の「16.6 Repeated Loading」に、以下のような記述がある:

    When you load or reload files, bear in mind that the ‘load’ and
    ‘load-library’ functions automatically load a byte-compiled file rather
    than a non-compiled file of similar name. If you rewrite a file that
    you intend to save and reinstall, you need to byte-compile the new
    version; otherwise Emacs will load the older, byte-compiled file instead
    of your newer, non-compiled file! If that happens, the message
    displayed when loading the file includes, ‘(compiled; note, source is
    newer)’, to remind you to recompile it.

    つまり、(拡張子以外)同じ名前の .el ファイルと .elc ファイルがあったとき、emacs は .elc ファイルをロードするということだ。このとき、.el ファイルを編集してそれをバイトコンパイルするのを忘れると、混乱してしまう。

    この場合普通は、たとえば file.el を編集しているとき、 

    Warning: /home/taro/file.el is newer than /home/taro/file.elc

    というメッセージが minibuffer に表示され、気づくのである。

    ところが、.emacs.el を編集していて emacs を再起動してチェックしているとき、上記の warning はスタートアップメッセージ:

    For information about GNU Emacs and the GNU system, type C-h C-a.
    

    に上書きされてしまって、気づかない。これで毎回はまるのである。

    バイトコンパイルファイルをup-to-dateにするには、たとえば以下のページが参考になる:

    皆同じようなところではまるもんだなと思うとともに、対策を取るのは面倒くさい。

    上に書いたような状況のみ回避するのであれば、`inhibit-startup-echo-area-message' を non-nil に設定するのが一番単純ではある。

    どうしたもんかな。うーん。


    あなたへのおすすめ