ここでは、私の Emacs の設定についてまとめています。 基本方針は以下の通り:
Emacs のパケージは El-Get で管理する.
以前はイロイロ書いていましたが。
さすが tarao (INA Lintaro) です。すごい。
はい、個人の我侭ですね。 Emacsに関連するDebianパッケージを幾つかメンテナンスしているので、 可能であれば El-Get でパッケージをインストールする前にDebianパッケージを使うことにしています。
自分が root 持っていない場合にはしょうがないですけれどね。
設定は Org mode で書きたい
以前こんなブログ記事を書きました: Emacsの設定ファイルをorgで書く というわけで、設定は Babel: Introduction で書きます。
本ファイル(README.org) から,
Makefile 内の以下のスクリプトで ~/init.el を生成し,byte-compile します。
%.elc: %.el
$(EMACS) -l $< -batch -f batch-byte-compile $<
init.el: README.org
emacs -Q --batch -l "ob-tangle" \
--eval "(org-babel-tangle-file \"$<\" \"$@\" \"emacs-lisp\"))"以前は ~/.emacs に設定を書いていましたが、
最近は ~/.emacs.d/init.el を使うのが主流ですね。
さらに、適切な設定を行なうことで、Emacs 起動時に読み込んだ elisp ファイルのある
ディレクトリを user-emacs-directory として扱えます。
分割した設定ファイル群や El-Get で install したパッケージの置き場所も
user-emacs-directory 以下にまとめています。
ディレクトリ構成は以下のようにしました:
~/.emacs.d/ |-- Makefile ← byte-compile 用の rule |-- README.org ← 本ファイル.`org-babel-tangle' で init.el を生成 |-- config/ ← 分割された設定ファイル群 |-- packages/ ← el-get で install されるパッケージの置き場所 |-- share/ ← Emacs lisp が使用する(いじらない)ソースなど `-- tmp/ ← 一次ファイル置き場
上記ディレクトリ構成を設定ファイルで使用するためにディレクトリ配置を宣言しておきます.
(when load-file-name
(setq user-emacs-directory (file-name-directory load-file-name)))
(defconst my:share-dir
(expand-file-name "share/" user-emacs-directory))
(defconst my:config-dir
(expand-file-name "config/" user-emacs-directory))
(defconst my:temp-dir
(expand-file-name "tmp/" user-emacs-directory))(setq debug-on-error nil)(when (boundp 'load-prefer-newer)
(setq load-prefer-newer t))(eval-and-compile (require 'cl))(let ((win (get-buffer-window "*Compile-Log*")))
(when win (delete-window win)))(setq byte-compile-warnings
'(not
free-vars
unresolved
callargs
redefine
obsolete
noruntime
cl-functions
interactive-only
make-local
))El-Get 関連は ~/.emacs.d/packages/el-get 、
パッケージ関連は ~/.emacs.d/packages/elpa に置かれる様にする。
(let ((my:package-dir (locate-user-emacs-file "packages")))
(setq el-get-dir (expand-file-name "el-get" my:package-dir))
(setq package-user-dir (expand-file-name "el-get" my:package-dir)))(add-to-list 'load-path
(expand-file-name "packages/el-get/el-get" user-emacs-directory) t)
(unless (require 'el-get nil 'noerror)
(with-current-buffer
(url-retrieve-synchronously
"https://raw.githubusercontent.com/dimitri/el-get/master/el-get-install.el")
(goto-char (point-max))
(eval-print-last-sexp)))(setq el-get-verbose t)(setq el-get-github-default-url-type 'https)(el-get-bundle tarao/with-eval-after-load-feature-el)(defun my:dpkg-status (package)
"Return the package status from dpkg --get-selections."
(string-match "^ii" (shell-command-to-string (format "dpkg -l %s" package))))Emacsの設定ファイルをorgで書く なんかを参考のこと。
(require 'org)org ファイルを引数で渡すと、
timestamp を比較し、必要に応じて org-babel-tangle で “.el” を抽出
→ byte-compile した後に load する関数の定義
設定ファイルは <user-emacs-directory>/config 以下に置くことに決め打ち。
(defun my:org-babel-tangle-and-compile-file (file)
(interactive "fFile to load: ")
(let* ((base-name file) ; (file-name-sans-extension file))
(exported-file (concat base-name ".el"))
(compiled-file (concat base-name ".elc")))
(unless (and (file-exists-p compiled-file)
(file-newer-than-file-p exported-file base-name))
(org-babel-tangle-file (concat file ".org") exported-file "emacs-lisp")
(byte-compile-file exported-file))))
(defun my:load-org-file (file)
(interactive "fFile to load: ")
(let* ((config (expand-file-name file my:config-dir)))
(my:org-babel-tangle-and-compile-file config)
(load (file-name-sans-extension config))))設定の詳細は Emacsの設定 - 主に org ファイルの読み込み集 を参照
(my:load-org-file "index")This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. . This package is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. . You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.