aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChong Yidong2011-03-06 10:54:36 -0500
committerChong Yidong2011-03-06 10:54:36 -0500
commit120d9389bf24bd04e6eb25e52a8b43faeb77dad4 (patch)
treec7e72c1ad7975e4263f25a3b643f15f34195bb44
parent5f349a895b72500a6a33d6610195f7141cf8252f (diff)
downloademacs-120d9389bf24bd04e6eb25e52a8b43faeb77dad4.tar.gz
emacs-120d9389bf24bd04e6eb25e52a8b43faeb77dad4.zip
Improve packaging documentation.
* package.texi (Packaging, Packaging Basics, Simple Packages) (Multi-file Packages): Expand and clarify. (Package Archives): Temporary placeholder node. * elisp.texi (Top): Update node listing.
-rw-r--r--doc/lispref/ChangeLog6
-rw-r--r--doc/lispref/elisp.texi1
-rw-r--r--doc/lispref/package.texi290
3 files changed, 173 insertions, 124 deletions
diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog
index 7bb1919b837..5d28a90136e 100644
--- a/doc/lispref/ChangeLog
+++ b/doc/lispref/ChangeLog
@@ -1,5 +1,11 @@
12011-03-06 Chong Yidong <cyd@stupidchicken.com> 12011-03-06 Chong Yidong <cyd@stupidchicken.com>
2 2
3 * package.texi (Packaging, Packaging Basics, Simple Packages)
4 (Multi-file Packages): Expand and clarify.
5 (Package Archives): Temporary placeholder node.
6
7 * elisp.texi (Top): Update node listing.
8
3 * Makefile.in (srcs): Add package.texi. 9 * Makefile.in (srcs): Add package.texi.
4 10
52011-03-05 Chong Yidong <cyd@stupidchicken.com> 112011-03-05 Chong Yidong <cyd@stupidchicken.com>
diff --git a/doc/lispref/elisp.texi b/doc/lispref/elisp.texi
index cc3ceb8003c..fc066526614 100644
--- a/doc/lispref/elisp.texi
+++ b/doc/lispref/elisp.texi
@@ -1399,6 +1399,7 @@ Preparing Lisp code for distribution
1399* Packaging Basics:: The basic concepts of Emacs Lisp packages. 1399* Packaging Basics:: The basic concepts of Emacs Lisp packages.
1400* Simple Packages:: How to package a single .el file. 1400* Simple Packages:: How to package a single .el file.
1401* Multi-file Packages:: How to package multiple files. 1401* Multi-file Packages:: How to package multiple files.
1402* Package Archives:: Maintaining package archives.
1402 1403
1403Starting Up Emacs 1404Starting Up Emacs
1404 1405
diff --git a/doc/lispref/package.texi b/doc/lispref/package.texi
index 373e1e2b5c7..4de44fe165d 100644
--- a/doc/lispref/package.texi
+++ b/doc/lispref/package.texi
@@ -7,186 +7,223 @@
7@chapter Preparing Lisp code for distribution 7@chapter Preparing Lisp code for distribution
8@cindex packaging 8@cindex packaging
9 9
10 Emacs provides a standard way for Emacs Lisp code to be distributed 10 Emacs provides a standard way to distribute Emacs Lisp code to
11to users. This approach lets users easily download, install, 11users. A @dfn{package} is a collection of one or more files,
12uninstall, and upgrade Lisp code that they might want to use. 12formatted and bundled in such a way that users can easily download,
13install, uninstall, and upgrade it.
13 14
14 A @dfn{package} is simply one or more files, formatted and bundled 15 The following sections describe how to create a package, and how to
15in a particular way. Typically a package includes primarily Emacs 16put it in a @dfn{package archive} for others to download.
16Lisp code, but it is possible to create other kinds of packages as
17well.
18 17
19@menu 18@menu
20* Packaging Basics:: The basic concepts of Emacs Lisp packages. 19* Packaging Basics:: The basic concepts of Emacs Lisp packages.
21* Simple Packages:: How to package a single .el file. 20* Simple Packages:: How to package a single .el file.
22* Multi-file Packages:: How to package multiple files. 21* Multi-file Packages:: How to package multiple files.
22* Package Archives:: Maintaining package archives.
23@end menu 23@end menu
24 24
25@node Packaging Basics 25@node Packaging Basics
26@section Packaging Basics 26@section Packaging Basics
27@cindex packaging basics 27@cindex packaging basics
28
29 A package has a few attributes:
30@cindex package attributes 28@cindex package attributes
31 29
30 A package is either a @dfn{simple package} or a @dfn{multi-file
31package}. A simple package is stored in a package archive as a single
32Emacs 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
34manual).
35
36 In ordinary usage, the difference between simple packages and
37multi-file packages is relatively unimportant; the Package Menu
38interface makes no distinction between them. However, the procedure
39for creating them differs, as explained in the following sections.
40
41 Each package (whether simple or multi-file) has certain
42@dfn{attributes}:
43
32@table @asis 44@table @asis
33@item Name 45@item Name
34A string, the name of the package. This attribute is mandatory. If 46A short word (e.g. @samp{auctex}). This is usually also the symbol
35it does not exist, the package cannot be installed by the package 47prefix used in the program (@pxref{Coding Conventions}).
36manager.
37 48
38@item Version 49@item Version
39A version number, which is anything that can be parsed by 50A version number, in a form that the function @code{version-to-list}
40@code{version-to-list}. This attribute is mandatory. If it does not 51understands (e.g. @samp{11.86}). Each release of a package should be
41exist, the package cannot be installed by the package manager. 52accompanied by an increase in the version number.
42 53
43@item Brief description 54@item Brief description
44This is shown to the user in the package menu buffer. It is just a 55This is shown when the package is listed in the Package Menu. It
45single line. On a terminal with 80 characters per line, there are 56should occupy a single line, ideally in 36 characters or less.
46only 36 characters available in the package menu mode for showing the
47brief description, so it is best to keep it very brief. If no brief
48name is given, an empty string is used.
49 57
50@item Long description 58@item Long description
51This can be a @file{README} file or the like. This is available to 59This is shown in the buffer created by @kbd{C-h P}
52the user before the package is installed, via the package menu. It 60(@code{describe-package}), following the package's brief description
53should more fully describe the package and its capabilities, so a user 61and installation status. It normally spans multiple lines, and should
54can read it to decide whether he wants to install the package. This 62fully describe the package and its capabilities.
55attribute is optional.
56 63
57@item Dependencies 64@item Dependencies
58This is a list of other packages and their minimal acceptable 65A list of other packages (possibly including minimal acceptable
59versions. This is used both at download time (to make sure all the 66version numbers) on which this package depends. The list may be
60needed code is available) and at activation time (to ensure a package 67empty, meaning this package has no dependencies. Otherwise,
61is only activated if all its dependencies have been successfully 68installing this package also automatically installs its dependencies;
62activated). This attribute is optional. 69if any dependency cannot be found, the package cannot be installed.
63
64@item Manual
65A package can optionally include an Info manual.
66@end table 70@end table
67 71
68 Conceptually, a package goes through several state transitions (in 72 Installing a package, either via the Package Menu, or via the
69reality some of these transitions are grouped together): 73command @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
77package's @dfn{content directory}. It is where Emacs puts the
78package's contents (the single Lisp file for a simple package, or the
79files extracted from a multi-file package).
80
81 Emacs then searches every Lisp file in the content directory for
82autoload magic comments (@pxref{Autoload}). These autoload
83definitions are saved to a file named @file{@var{name}-autoloads.el}
84in the content directory. They are typically used to autoload the
85principal user commands defined in the package, but they can also
86perform other tasks, such as adding an element to
87@code{auto-mode-alist} (@pxref{Auto Major Mode}). During this time,
88Emacs will also byte-compile the Lisp files.
89
90 After installation, and (by default) each time Emacs is started, the
91installed package is @dfn{activated}. During activation, Emacs adds
92the package's content directory to @code{load-path}, and evaluates the
93autoload definitions in @file{@var{name}-autoloads.el}.
94
95 Note that a package typically does @emph{not} autoload every
96function and variable defined within it---only the handful of commands
97typically called to begin using the package.
70 98
71@table @asis 99@node Simple Packages
72@item Download 100@section Simple Packages
73Fetch the package from somewhere. 101@cindex single file packages
74 102
75@item Install 103 A simple package consists of a single Emacs Lisp source file. The
76Unpack the package, or write a @file{.el} file into the appropriate 104file must conform to the Emacs Lisp library header conventions
77install directory. This step also includes extracting autoloads and 105(@pxref{Library Headers}). The package's attributes are taken from
78byte-compiling the Emacs Lisp code. 106the various headers, as illustrated by the following example:
79 107
80@item Activate 108@example
81Update @code{load-path} and @code{Info-directory-list} and evaluate 109@group
82the autoloads, so that the package is ready for the user to use. 110;;; superfrobnicator.el --- Frobnicate and bifurcate flanges
83@end table
84 111
85 It is best for users if packages do not do too much work at 112;; Copyright (C) 2011 Free Software Foundation, Inc.
86activation time. The best approach is to have activation consist of 113@end group
87some autoloads and little more.
88 114
89@node Simple Packages 115;; Author: J. R. Hacker <jrh@@example.com>
90@section Simple Packages 116;; Version: 1.3
91@cindex single file packages 117;; Package-Requires: ((flange "1.0"))
118;; Keywords: frobnicate
92 119
93 The simplest package consists of a single Emacs Lisp source file. 120@dots{}
94In this case, all the attributes of the package (@pxref{Packaging
95Basics}) are taken from this file.
96 121
97 The package system expects this @file{.el} file to conform to the 122;;; Commentary:
98Emacs Lisp library header conventions. @xref{Library Headers}.
99 123
100 The name of the package is the same as the base name of the 124;; This package provides a minor mode to frobnicate and/or
101@file{.el} file, as written in the first comment line. For example, 125;; bifurcate any flanges you desire. To activate it, just type
102given the header line: 126@dots{}
103 127
104@smallexample 128;;;###autoload
105;;; superfrobnicator.el --- frobnicate and bifurcate flanges 129(define-minor-mode superfrobnicator-mode
106@end smallexample 130@dots{}
131@end example
107 132
108the package name will be @samp{superfrobnicator}. 133 The name of the package is the same as the base name of the file, as
134written on the first line. Here, it is @samp{superfrobnicator}.
109 135
110 The short description of the package is also taken from the first 136 The brief description is also taken from the first line. Here, it
111line of the file. 137is @samp{Frobnicate and bifurcate flanges}.
112 138
113 If the file has a ``Commentary'' header, then it is used as the long 139 The version number comes from the @samp{Package-Version} header, if
114description. 140it exists, or from the @samp{Version} header otherwise. One or the
141other @emph{must} be present. Here, the version number is 1.3.
115 142
116 The version of the package comes either from the ``Package-Version'' 143 If the file has a @samp{;;; Commentary:} section, this section is
117header, if it exists, or from the ``Version'' header. A package is 144used as the long description. (When displaying the description, Emacs
118required to have a version number. Each release of a package must be 145omits the @samp{;;; Commentary:} line, as well as the leading comment
119accompanied by an increase in the version number. 146characters in the commentary itself.)
120 147
121 If the file has a ``Package-Requires'' header, then that is used as 148 If the file has a @samp{Package-Requires} header, that is used as
122the package dependencies. Otherwise, the package is assumed not to 149the package dependencies. In the above example, the package depends
123have any dependencies. 150on the @samp{flange} package, version 1.0 or higher. @xref{Library
151Headers}, for a description of the @samp{Package-Requires} header. If
152the header is omitted, the package has no dependencies.
124 153
125 A single-file package cannot have an Info manual. 154 The file ought to also contain one or more autoload magic comments,
155as explained in @ref{Packaging Basics}. In the above example, a magic
156comment autoloads @code{superfrobnicator-mode}.
126 157
127 The file will be scanned for autoload cookies at install time. 158 @xref{Package Archives}, for a explanation of how to add a
128@xref{Autoload}. 159single-file package to a package archive.
129 160
130@node Multi-file Packages 161@node Multi-file Packages
131@section Multi-file Packages 162@section Multi-file Packages
132@cindex multi-file packages 163@cindex multi-file packages
133 164
134 A multi-file package is just a @file{.tar} file. While less 165 A multi-file package is less convenient to create than a single-file
135convenient to create than a single-file package, a multi-file package 166package, but it offers more features: it can include multiple Emacs
136also offers more features: it can include an Info manual, multiple 167Lisp files, an Info manual, and other file types (such as images).
137Emacs Lisp files, and also other data files needed by a package. 168
138 169 Prior to installation, a multi-file package is stored in a package
139 The contents of the @file{.tar} file must all appear beneath a 170archive as a tar file. The tar file must be named
140single directory, named after the package and version. Files can 171@file{@var{name}-@var{version}.tar}, where @var{name} is the package
141appear in subdirectories of this top-most directory, but Emacs Lisp 172name and @var{version} is the version number. Its contents, once
142code will only be found (and thus byte-compiled) at the top-most 173extracted, must all appear in a directory named
143level. Also, the @file{.tar} file is typically also given this same 174@file{@var{name}-@var{version}}, the @dfn{content directory}
144name. For example, if you are distributing version 1.3 of the 175(@pxref{Packaging Basics}). Files may also extract into
145superfrobnicator, the package file would be named 176subdirectories of the content directory.
146``superfrobnicator-1.3.tar'' and the contents would all appear in the 177
147directory @file{superfrobnicator-1.3} in that @file{.tar}. 178 One of the files in the content directory must be named
148 179@file{@var{name}-pkg.el}. It must contain a single Lisp form,
149 The package must include a @file{-pkg.el} file, named after the 180consisting of a call to the function @code{define-package}, described
150package. In our example above, this file would be called 181below. This defines the package's version, brief description, and
151@file{superfrobnicator-pkg.el}. This file must have a single form in 182requirements.
152it, a call to @code{define-package}. The package dependencies and 183
153brief description are taken from this form. 184 For example, if we distribute version 1.3 of the superfrobnicator as
185a multi-file package, the tar file would be
186@file{superfrobnicator-1.3.tar}. Its contents would extract into the
187directory @file{superfrobnicator-1.3}, and one of these would be the
188file @file{superfrobnicator-pkg.el}.
154 189
155@defun define-package name version &optional docstring requirements 190@defun define-package name version &optional docstring requirements
156Define a package. @var{name} is the name of the package, a string. 191This function defines a package. @var{name} is the package name, a
157@var{version} is the package's version, a string. It must be in a 192string. @var{version} is the version, as a string of a form that can
158form that can be understood by @code{version-to-list}. 193be understood by the function @code{version-to-list}. @var{docstring}
159@var{docstring} is the short description of the package. 194is the brief description.
195
160@var{requirements} is a list of required packages and their versions. 196@var{requirements} is a list of required packages and their versions.
197Each 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
199the dependency's package name, and @var{dep-version} is the
200dependency's version (a string).
161@end defun 201@end defun
162 202
163 If a @file{README} file exists in the content directory, then it is 203 If the content directory contains a file named @file{README}, this
164used as the long description. 204file is used as the long description.
165 205
166 If the package has an Info manual, you should distribute the needed 206 If the content directory contains a file named @file{dir}, this is
167info files, plus a @file{dir} file made with @command{install-info}. 207assumed to be an Info directory file made with @command{install-info}.
168@xref{Invoking install-info, Invoking install-info, Invoking 208@xref{Invoking install-info, Invoking install-info, Invoking
169install-info, texinfo, Texinfo}. 209install-info, texinfo, Texinfo}. The Info files listed in this
170 210directory file should also be present in the content directory. In
171 Do not include any @file{.elc} files in the package. Those will be 211this case, Emacs will automatically add the content directory to
172created at install time. Note that there is no way to control the 212@code{Info-directory-list} when the package is activated.
173order in which files are byte-compiled; your package must be robust
174here.
175 213
176 The installation process will scan all the @file{.el} files in the 214 Do not include any @file{.elc} files in the package. Those are
177package for autoload cookies. @xref{Autoload}. They are extracted 215created when the package is installed. Note that there is no way to
178into a @file{-autoloads.el} file (e.g., 216control the order in which files are byte-compiled.
179@file{superfrobnicator-autoloads.el}), so do not include a file of
180that name in your package.
181 217
182 Any other files in the @file{.tar} file are simply unpacked when the 218 Do not include any file named @file{@var{name}-autoloads.el}. This
183package is installed. This can be useful if your package needs 219file is reserved for the package's autoload definitions
184auxiliary data files --- e.g., icons or sounds. 220(@pxref{Packaging Basics}). It is created automatically when the
221package is installed, by searching all the Lisp files in the package
222for autoload magic comments.
185 223
186 Emacs Lisp code installed via the package manager must take special 224 If the multi-file package contains auxiliary data files (such as
187care to be location-independent. One easy way to do this is to make 225images), the package's Lisp code can refer to these files via the
188references to auxiliary data files relative to @var{load-file-name}. 226variable @code{load-file-name} (@pxref{Loading}). Here is an example:
189For example:
190 227
191@smallexample 228@smallexample
192(defconst superfrobnicator-base (file-name-directory load-file-name)) 229(defconst superfrobnicator-base (file-name-directory load-file-name))
@@ -194,3 +231,8 @@ For example:
194(defun superfrobnicator-fetch-image (file) 231(defun superfrobnicator-fetch-image (file)
195 (expand-file-name file superfrobnicator-base)) 232 (expand-file-name file superfrobnicator-base))
196@end smallexample 233@end smallexample
234
235@node Package Archives
236@section Creating and Maintaining Package Archives
237
238To be done.