created: 2019-06-16 24:00, tags: emacs,

.emacs.d 以下の .el ファイルを全てコンパイルする関数を作る

elisp はコンパイルしておく事で後の実行を速く処理する事が出来る機能があるが、何らかの都合でコンパイルしたくなる。 やり方は色々あるけど M-x からのコマンドで実行できるようにしておけば helm や ivy で補完候補として出てくれるので名前を覚えきれてなくても再利用し易くなるし便利。

僕はこういう感じで init.d が読む場所に登録している。

(defun core/all-elisp-byte-compile ()
  (interactive)
  (let ((elisp-paths (split-string (shell-command-to-string "find $HOME/.emacs.d/ -name '*.el'"))))
    (dolist (elisp-path elisp-paths)
      (byte-compile-file elisp-path)
      (message "compiled %s file." elisp-path))))
M-x core/all-elisp-byte-compile

あとは上記を実行するだけで好きな時に、少ない手間で実行できる (.emacs.d 以下を全てコンパイルするため入れたパッケージの数が多いと時間がかかる)。