]> code.delx.au - gnu-emacs/blob - doc/lispref/package.texi
* lisp/progmodes/gud.el (gdb-script-syntax-propertize-function):
[gnu-emacs] / doc / lispref / package.texi
1 @c -*-texinfo-*-
2 @c This is part of the GNU Emacs Lisp Reference Manual.
3 @c Copyright (C) 2010-2011 Free Software Foundation, Inc.
4 @c See the file elisp.texi for copying conditions.
5 @setfilename ../../info/package
6 @node Packaging, Antinews, System Interface, Top
7 @chapter Preparing Lisp code for distribution
8 @cindex packaging
9
10 Emacs provides a standard way to distribute Emacs Lisp code to
11 users. A @dfn{package} is a collection of one or more files,
12 formatted and bundled in such a way that users can easily download,
13 install, uninstall, and upgrade it.
14
15 The following sections describe how to create a package, and how to
16 put it in a @dfn{package archive} for others to download.
17
18 @menu
19 * Packaging Basics:: The basic concepts of Emacs Lisp packages.
20 * Simple Packages:: How to package a single .el file.
21 * Multi-file Packages:: How to package multiple files.
22 * Package Archives:: Maintaining package archives.
23 @end menu
24
25 @node Packaging Basics
26 @section Packaging Basics
27 @cindex packaging basics
28 @cindex package attributes
29
30 A package is either a @dfn{simple package} or a @dfn{multi-file
31 package}. A simple package is stored in a package archive as a single
32 Emacs Lisp file, while a multi-file package is stored as a tar file
33 (containing multiple Lisp files, and possibly non-Lisp files such as a
34 manual).
35
36 In ordinary usage, the difference between simple packages and
37 multi-file packages is relatively unimportant; the Package Menu
38 interface makes no distinction between them. However, the procedure
39 for creating them differs, as explained in the following sections.
40
41 Each package (whether simple or multi-file) has certain
42 @dfn{attributes}:
43
44 @table @asis
45 @item Name
46 A short word (e.g. @samp{auctex}). This is usually also the symbol
47 prefix used in the program (@pxref{Coding Conventions}).
48
49 @item Version
50 A version number, in a form that the function @code{version-to-list}
51 understands (e.g. @samp{11.86}). Each release of a package should be
52 accompanied by an increase in the version number.
53
54 @item Brief description
55 This is shown when the package is listed in the Package Menu. It
56 should occupy a single line, ideally in 36 characters or less.
57
58 @item Long description
59 This is shown in the buffer created by @kbd{C-h P}
60 (@code{describe-package}), following the package's brief description
61 and installation status. It normally spans multiple lines, and should
62 fully describe the package and its capabilities.
63
64 @item Dependencies
65 A list of other packages (possibly including minimal acceptable
66 version numbers) on which this package depends. The list may be
67 empty, meaning this package has no dependencies. Otherwise,
68 installing this package also automatically installs its dependencies;
69 if any dependency cannot be found, the package cannot be installed.
70 @end table
71
72 Installing a package, either via the Package Menu, or via the
73 command @code{package-install-file}, creates a subdirectory of
74 @code{package-user-dir} named @file{@var{name}-@var{version}}, where
75 @var{name} is the package's name and @var{version} its version
76 (e.g. @file{~/.emacs.d/elpa/auctex-11.86/}). We call this the
77 package's @dfn{content directory}. It is where Emacs puts the
78 package's contents (the single Lisp file for a simple package, or the
79 files extracted from a multi-file package).
80
81 Emacs then searches every Lisp file in the content directory for
82 autoload magic comments (@pxref{Autoload}). These autoload
83 definitions are saved to a file named @file{@var{name}-autoloads.el}
84 in the content directory. They are typically used to autoload the
85 principal user commands defined in the package, but they can also
86 perform other tasks, such as adding an element to
87 @code{auto-mode-alist} (@pxref{Auto Major Mode}). During this time,
88 Emacs will also byte-compile the Lisp files.
89
90 After installation, and (by default) each time Emacs is started, the
91 installed package is @dfn{activated}. During activation, Emacs adds
92 the package's content directory to @code{load-path}, and evaluates the
93 autoload definitions in @file{@var{name}-autoloads.el}.
94
95 Note that a package typically does @emph{not} autoload every
96 function and variable defined within it---only the handful of commands
97 typically called to begin using the package.
98
99 @node Simple Packages
100 @section Simple Packages
101 @cindex single file packages
102
103 A simple package consists of a single Emacs Lisp source file. The
104 file must conform to the Emacs Lisp library header conventions
105 (@pxref{Library Headers}). The package's attributes are taken from
106 the various headers, as illustrated by the following example:
107
108 @example
109 @group
110 ;;; superfrobnicator.el --- Frobnicate and bifurcate flanges
111
112 ;; Copyright (C) 2011 Free Software Foundation, Inc.
113 @end group
114
115 ;; Author: J. R. Hacker <jrh@@example.com>
116 ;; Version: 1.3
117 ;; Package-Requires: ((flange "1.0"))
118 ;; Keywords: frobnicate
119
120 @dots{}
121
122 ;;; Commentary:
123
124 ;; This package provides a minor mode to frobnicate and/or
125 ;; bifurcate any flanges you desire. To activate it, just type
126 @dots{}
127
128 ;;;###autoload
129 (define-minor-mode superfrobnicator-mode
130 @dots{}
131 @end example
132
133 The name of the package is the same as the base name of the file, as
134 written on the first line. Here, it is @samp{superfrobnicator}.
135
136 The brief description is also taken from the first line. Here, it
137 is @samp{Frobnicate and bifurcate flanges}.
138
139 The version number comes from the @samp{Package-Version} header, if
140 it exists, or from the @samp{Version} header otherwise. One or the
141 other @emph{must} be present. Here, the version number is 1.3.
142
143 If the file has a @samp{;;; Commentary:} section, this section is
144 used as the long description. (When displaying the description, Emacs
145 omits the @samp{;;; Commentary:} line, as well as the leading comment
146 characters in the commentary itself.)
147
148 If the file has a @samp{Package-Requires} header, that is used as
149 the package dependencies. In the above example, the package depends
150 on the @samp{flange} package, version 1.0 or higher. @xref{Library
151 Headers}, for a description of the @samp{Package-Requires} header. If
152 the header is omitted, the package has no dependencies.
153
154 The file ought to also contain one or more autoload magic comments,
155 as explained in @ref{Packaging Basics}. In the above example, a magic
156 comment autoloads @code{superfrobnicator-mode}.
157
158 @xref{Package Archives}, for a explanation of how to add a
159 single-file package to a package archive.
160
161 @node Multi-file Packages
162 @section Multi-file Packages
163 @cindex multi-file packages
164
165 A multi-file package is less convenient to create than a single-file
166 package, but it offers more features: it can include multiple Emacs
167 Lisp files, an Info manual, and other file types (such as images).
168
169 Prior to installation, a multi-file package is stored in a package
170 archive as a tar file. The tar file must be named
171 @file{@var{name}-@var{version}.tar}, where @var{name} is the package
172 name and @var{version} is the version number. Its contents, once
173 extracted, must all appear in a directory named
174 @file{@var{name}-@var{version}}, the @dfn{content directory}
175 (@pxref{Packaging Basics}). Files may also extract into
176 subdirectories of the content directory.
177
178 One of the files in the content directory must be named
179 @file{@var{name}-pkg.el}. It must contain a single Lisp form,
180 consisting of a call to the function @code{define-package}, described
181 below. This defines the package's version, brief description, and
182 requirements.
183
184 For example, if we distribute version 1.3 of the superfrobnicator as
185 a multi-file package, the tar file would be
186 @file{superfrobnicator-1.3.tar}. Its contents would extract into the
187 directory @file{superfrobnicator-1.3}, and one of these would be the
188 file @file{superfrobnicator-pkg.el}.
189
190 @defun define-package name version &optional docstring requirements
191 This function defines a package. @var{name} is the package name, a
192 string. @var{version} is the version, as a string of a form that can
193 be understood by the function @code{version-to-list}. @var{docstring}
194 is the brief description.
195
196 @var{requirements} is a list of required packages and their versions.
197 Each element in this list should have the form @code{(@var{dep-name}
198 @var{dep-version})}, where @var{dep-name} is a symbol whose name is
199 the dependency's package name, and @var{dep-version} is the
200 dependency's version (a string).
201 @end defun
202
203 If the content directory contains a file named @file{README}, this
204 file is used as the long description.
205
206 If the content directory contains a file named @file{dir}, this is
207 assumed to be an Info directory file made with @command{install-info}.
208 @xref{Invoking install-info, Invoking install-info, Invoking
209 install-info, texinfo, Texinfo}. The Info files listed in this
210 directory file should also be present in the content directory. In
211 this case, Emacs will automatically add the content directory to
212 @code{Info-directory-list} when the package is activated.
213
214 Do not include any @file{.elc} files in the package. Those are
215 created when the package is installed. Note that there is no way to
216 control the order in which files are byte-compiled.
217
218 Do not include any file named @file{@var{name}-autoloads.el}. This
219 file is reserved for the package's autoload definitions
220 (@pxref{Packaging Basics}). It is created automatically when the
221 package is installed, by searching all the Lisp files in the package
222 for autoload magic comments.
223
224 If the multi-file package contains auxiliary data files (such as
225 images), the package's Lisp code can refer to these files via the
226 variable @code{load-file-name} (@pxref{Loading}). Here is an example:
227
228 @smallexample
229 (defconst superfrobnicator-base (file-name-directory load-file-name))
230
231 (defun superfrobnicator-fetch-image (file)
232 (expand-file-name file superfrobnicator-base))
233 @end smallexample
234
235 @node Package Archives
236 @section Creating and Maintaining Package Archives
237
238 To be done.