$shibayu36->blog;

クラスター株式会社のソフトウェアエンジニアです。エンジニアリングや読書などについて書いています。

emacsでinit-loaderを導入してみた

 これまでは.emacs.d/init.elで自分の分割したinit-*ファイルをロードしていたが、init-loader.el(http://coderepos.org/share/browser/lang/elisp/init-loader/init-loader.el)というのがあったので、こちらを導入してみた。

インストール

install-elisp.elを使って、インストールします。install-elisp.elの導入に関してはEmacs ビギナーに贈る、これからバリバリ使い隊!!人のための設定講座 その1。 - 日々、とんは語る。あたりを見ればいいような気がします。

次のコマンドを使ってinit-loader.elをインストールします。

M-x install-elisp http://coderepos.org/share/browser/lang/elisp/init-loader/init-loader.el?format=txt

その次に.emacs.d/init.elに次のように書きます。今回は.emacs.d/inits/以下に設定ファイルを置くようにしました。ロードパスはinit.elで設定しています。

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;ロードパス追加設定;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq load-path
      (append
       (list
        (expand-file-name "~/.emacs.d/")
        (expand-file-name "~/.emacs.d/elisp/")
        (expand-file-name "~/.emacs.d/elisp/anything/")
        (expand-file-name "~/.emacs.d/elisp/abbrev/")
        (expand-file-name "~/.emacs.d/elisp/pymacs/")
        (expand-file-name "~/.emacs.d/elisp/yasnippet")
        (expand-file-name "~/.emacs.d/elisp/moccur")
        (expand-file-name "~/.emacs.d/elisp/apel")
        (expand-file-name "~/.emacs.d/elisp/mode/")
        (expand-file-name "~/.emacs.d/elisp/mode/html/")
        (expand-file-name "~/.emacs.d/elisp/mode/nxhtml/")
        (expand-file-name "~/.emacs.d/elisp/mode/css/")
        (expand-file-name "~/.emacs.d/elisp/mode/php-mode/")
        (expand-file-name "~/.emacs.d/elisp/mode/python-mode/")
        (expand-file-name "~/.emacs.d/elisp/mode/perl/")
        (expand-file-name "~/.emacs.d/elisp/mode/psgml/")
        (expand-file-name "~/.emacs.d/elisp/mode/yml/")
        (expand-file-name "~/.emacs.d/elisp/mode/javascript/")
        (expand-file-name "~/.emacs.d/elisp/mode/yatex/")
        (expand-file-name "~/.emacs.d/elisp/auto-complete/")
        (expand-file-name "~/.emacs.d/elisp/mode/hatena/")
        (expand-file-name "~/.emacs.d/elisp/mode/ruby/")
        (expand-file-name "~/.emacs.d/elisp/mode/magit/share/emacs/site-lisp/")
        (expand-file-name "~/.emacs.d/elisp/mode/git/")
        (expand-file-name "~/.emacs.d/elisp/mode/evernote/")
        )
       load-path))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;   init-loader   ;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;設定ファイルはinits以下に置いていて、init-loaderによって読み込まれる
(require 'init-loader)
(init-loader-load "~/.emacs.d/inits")

構成

以下のように、もともとあったファイルから適当に順番をつけて構成してみました。かなり適当です。

inits
├── 00-init.el
├── 01-keybinds.el
├── 10-dired.el
├── 11-search-buffer.el
├── 20-edit-mode.el
├── 30-anything.el
├── 31-anything-git.el
├── 32-anything-display.el
├── 40-abbrev.el
├── 40-eldoc.el
├── 40-elscreen.el
├── 40-flymake.el
├── 40-git.el
├── 40-grep.el
├── 40-migemo.el
├── 40-shell.el
├── 40-term.el
├── 40-view-mode.el
├── 40-yasnippet.el
├── 50-pymacs.el
├── 60-myfuncs.el
├── 70-mymacros.el
└── 90-other-extension.el

その他設定

init-loader-re-loadに次のような変更を加えておけば、エラーが起きたときにどのファイルにエラーがあるか特定できます。http://d.hatena.ne.jp/kitokitoki/20101205/p1を参考にしました。

(defun init-loader-re-load (re dir &optional sort)
  (let ((load-path (cons dir load-path)))
    (dolist (el (init-loader--re-load-files re dir sort))
      (condition-case e
          (let ((time (car (benchmark-run (load (file-name-sans-extension el))))))
            (init-loader-log (format "loaded %s. %s" (locate-library el) time)))
        (error
         ;; (init-loader-error-log (error-message-string e)) ;削除
         (init-loader-error-log (format "%s. %s" (locate-library el) (error-message-string e))) ;追加
         )))))