fnwiya's quine

自分自身を出力するブログ

emacsの設定を複数台で共有するときにバイトコンパイルで気をつけること。

複数台でemacsの環境を共有するときはgit等で設定ファイルを持って行くと思いますが、
*.elcごとgitに挙げない場合はpullした場合でもemacs起動時以前のelcが読み込まれるので新しい設定が反映されません。
これの解決策は色々悩んだのですが起動時にバイトコンパイルしなおすに落ち着きました。
若干起動に時間がかかるようになりますが、
設定ファイルのバグにも気付きやすくなったのでしばらくこれで行こうと思います。

;; 起動時にバイトコンパイル
(defun compile-inits()
  "compile my init-files"
  (interactive)
  (byte-recompile-directory (expand-file-name "~/.emacs.d/loader-init") 0) ;; init-loaderで読み込むディレクトリ
  (byte-recompile-directory (expand-file-name "~/.emacs.d/themes") 0)
  (byte-compile-file "~/.emacs.d/init.el")
  )
(save-window-excursion
  (compile-inits)
)
;; 保存時にバイトコンパイル
(add-hook 'after-save-hook
          (lambda ()
            (if (eq major-mode 'emacs-lisp-mode)
                (save-excursion
                  (byte-compile-file buffer-file-name)))))
;; emacsを落とすときにコンパイルされたファイルを削除
(add-hook 'kill-emacs-hook
          (lambda()
            (shell-command "rm -f ~/.emacs.d/init.elc")
            (shell-command "rm -f ~/.emacs.d/themes/*.elc")
            (shell-command "rm -f ~/.emacs.d/loader-init/*.elc")))