
Emacs 22.3。
23.1じゃなくってスイマセン。
起動が遅い遅いゆうてる人もいますが、せっかくautoloadに対応してるマクロ群をしょっぱな load とか require したらそりゃ遅くもなりますって。勿体ない。
正しく autoload を使ったり、hook関数内で設定を行う手法に切り替えれば、起動は格段に高速化されると思うんだけど、どーなんでしょう。
部長のEmacs環境、色々手を入れてますが、起動は一瞬です。一秒以内。その代わり、はじめて dired やorg-modeを使う時、一瞬読み込待ちが入りますが。
ま、どっちを取るかは…本人次第ですけど、起動時間にイライラしてる人は設定を見直してみる価値はあるんじゃないかな。
ただ、部長は有名どころの拡張機能を使っておりませんのであしからず。
そんなEmacs 22.3 の設定もだいぶ極まってきました(といっても先人の方々のには遠く及びませんが)。ネットには古い情報と新しい情報が混在してて取捨選択が手間です。でも、いつまでも古い設定のまんまじゃいかんもんね。
ので、途中経過的にメモするよ(そんでながいよ)
・設定ファイル名を変更。Emacs22以降のトレンドにあわせた。
~/.emacs → ~/.emacs.d/init.el
・で、常用している機能拡張の設定も ~/.emacs.d/ 以下から読み込むように変更。
(setq abbrev-file-name "~/.emacs.d/.abbrev_defs")
(setq save-place-file "~/.emacs.d/.emacs-places")
(setq revive:configuration-file "~/.emacs.d/.revive.el")
・Windows依存とMac依存の設定を別ファイル化。init.elから読み込むようにした。
(cond
((eq window-system 'w32)
(load "~/.emacs.d/init-windows"))
((or (eq window-system 'ns) (eq window-system 'mac))
(load "~/.emacs.d/init-macos")))
・Windowsのシェル設定を変更。bashの初期設定ファイルを引数渡しにした(Macも同じ感じにできる)
(setenv "PATH" "C:\\cygwin\\bin;")
(setq explicit-shell-file-name "bash")
(setq explicit-bash-args '("--noediting" "--rcfile" "~/.emacs.d/.bashrc" "-i"))
・Macのフォント設定を変更(init-macos.elに書いた)
(create-fontset-from-mac-roman-font "-apple-menlo-medium-r-normal--12-*-*-*-*-*-iso10646-1" nil "myfont")
(set-fontset-font "fontset-myfont" 'japanese-jisx0208 '("Hiragino kaku Gothic ProN W3" . "jisx0208-sjis"))
(set-fontset-font "fontset-myfont" 'katakana-jisx0201 '("Hiragino kaku Gothic ProN W3" . "jisx0201-katakana"))
(setq default-frame-alist
(append
(list
'(font . "fontset-myfont")
) default-frame-alist)))
・WinとMacでdiredの振る舞いを揃えるために、init-macos.elでこうした。
(load-library "ls-lisp")
(setq ls-lisp-use-insert-directory-program nil)
・bs-showの色分けが気に入らんのでfaceを作成。ディレクトリの行を青色で表示。あと、マウスカーソルが当たってハイライトしないようにも設定。
(defface bs-directory
'((t (:inherit font-lock-function-name-face :foreground "#0020e0")))
"Face used for Directory."
:group 'bs-faces
:version "22.1")
(add-hook 'bs-mode-hook
'(lambda ()
(make-local-variable 'mouse-highlight)
(setq mouse-highlight nil)
(font-lock-add-keywords nil '(("^..\\(.*Dired .*\\)$" 1 'bs-directory t)))
))
・diredで、ディレクトリを選ぶ度にバッファが作られるのを抑制。マウスカーソルが当たってハイライトしないようにも設定。
(put 'dired-find-alternate-file 'disabled nil)
(add-hook 'dired-mode-hook
'(lambda ()
(make-local-variable 'mouse-highlight)
(setq mouse-highlight nil)
(local-set-key (kbd "RET") 'dired-find-alternate-file)
(local-set-key (kbd "C-<return>") 'dired-advertised-find-file)
))
・Windowsでdiffを使おうとすると、空白を含んだディレクトリを扱えないので、ちょっと無茶して標準関数を上書き。Emacsの深い関数なので、危険度高し(どこに手が入ってるかは、subr.elの同名の関数と比べてみて)
;; 引数をクオートする関数を再定義
(defun shell-quote-argument (argument)
"Quote an argument for passing as argument to an inferior shell."
(if (or (eq system-type 'ms-dos) (eq system-type 'windows-nt))
;; Quote using double quotes, but escape any existing quotes in
;; the argument with backslashes.
(let ((result "")
(start 0)
end)
(if (or (null (string-match "[^\"]" argument))
(< (match-end 0) (length argument)))
(while (string-match "[\"]" argument start)
(setq end (match-beginning 0)
result (concat result (substring argument start end)
"\\" (substring argument end (1+ end)))
start (1+ end))))
(concat "\"" result (substring argument start) "\""))
(if (equal argument "")
"''"
;; Quote everything except POSIX filename characters.
;; This should be safe enough even for really weird shells.
(let ((result "") (start 0) end)
(while (string-match "[^-0-9a-zA-Z_./]" argument start)
(setq end (match-beginning 0)
result (concat result (substring argument start end)
"\\" (substring argument end (1+ end)))
start (1+ end)))
(concat result (substring argument start))))))
・設定ファイルを読み込むだけのマクロを作った。毎回操作するのがめんどいだもん(笑)
(global-set-key (kbd "C-x l") 'my-load-init-file)
(defun my-load-init-file()
"init.elを読み込む"
(interactive)
(find-file "~/.emacs.d/init.el"))
だいたいこんな感じかな?
設定と自分用lispを無事 ~/.emacs.d/ 以下にまとめられたし、WindowsでもMacでも同じ設定内容でEmacsが動くようになったし、とりあえずバンザーイ!
ホントは設定ファイル(.emacs.d以下)をzipで固めてサーバに上げれば済む話なんだけど、キーバインドが独自変態仕様なんだよね。お恥ずかしい。だからちょっとためらってます。
どーしてもって言うのなら(笑)