パッケージフォーマット

Author: syohex
Published: 2013-10-11
Last Modified: 2013-10-12
GitHub Source: md

概要

Emacs Lispのパッケージを配布する際は, 公式のパッケージフォーマットに 従うべきです. ここではパッケージのフォーマットについて示します.

1行目はパッケージファイル名とパッケージの説明を書く

1行目には, パッケージ名とパッケージの説明を書きます. バッファローカル変数を 1行目に書いているものが稀にありますが, それは誤りです(ただし lexical-bindingのみ例外).

以下に anzu.elを例として示します.

;;; anzu.el --- Show number of matches in mode-line while searching

パッケージ名と説明の間のハイフンは 3つです. 2つや 4つではありませんので 注意してください. パッケージの説明は package-list-packagesで表示される パッケージの概要となりますので, 手抜きせずわかりやすい説明を考えてつけましょう.

メタ情報

メタ情報は Author, Version, (依存があれば)Package-Requiresを必ず書くように しましょう(あとは URLもあると良いです).

以下に helm-gtags.elを例として示します

;; Author: Syohei YOSHIDA <syohex@gmail.com>
;; URL: https://github.com/syohex/emacs-helm-gtags
;; Version: 0.9.9
;; Package-Requires: ((helm "1.0"))

Commentaryセクション

Commentaryセクションはパッケージの説明, 簡単な利用方法, 設定方法について示します. このセクションの情報は package-list-packages?で見ることができます. 以下に deferred.elの Commentaryセクションの内容を示します.

;;; Commentary:

;; 'deferred.el' is a simple library for asynchronous tasks.
;; [https://github.com/kiwanami/emacs-deferred]

;; The API is almost the same as JSDeferred written by cho45. See the
;; JSDeferred and Mochikit.Async web sites for further documentations.
;; [https://github.com/cho45/jsdeferred]
;; [http://mochikit.com/doc/html/MochiKit/Async.html]

;; A good introduction document (JavaScript)
;; [http://cho45.stfuawsc.com/jsdeferred/doc/intro.en.html]

バッファローカル変数の宣言

上述の lexical-bindingを除いたものについては, 後述のファイルの末尾を示すコメントの 前に宣言すると良いでしょう. 以下に helm-mode.elを例として示します.

;; Local Variables:
;; byte-compile-warnings: (not cl-functions obsolete)
;; coding: utf-8
;; indent-tabs-mode: nil
;; End:

;;; helm-mode.el ends here

lexical-bindingを定義する場合

lexical-bindingは現在のところ, 1行目に定義しなければ意味がありません. そのため lexical-bindingを設定する場合は, 1行目のパッケージの説明に続けて書くように してください. 以下は flycheck.elの例です.

;;; flycheck.el --- On-the-fly syntax checking (Flymake done right) -*- lexical-binding: t; -*-

ファイル末尾

ファイルの最後は ;;; ファイル名 ends hereとします. 以下に例を示します

;;; quickrun.el ends here

補足

これらをいちいち気にして書くのは大変なので, パッケージを書く際はyasnippetautoinsert機能を使い, ひな形から 作成するのが良いでしょう.