diff options
| author | Chong Yidong | 2011-03-06 10:54:36 -0500 |
|---|---|---|
| committer | Chong Yidong | 2011-03-06 10:54:36 -0500 |
| commit | 120d9389bf24bd04e6eb25e52a8b43faeb77dad4 (patch) | |
| tree | c7e72c1ad7975e4263f25a3b643f15f34195bb44 | |
| parent | 5f349a895b72500a6a33d6610195f7141cf8252f (diff) | |
| download | emacs-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/ChangeLog | 6 | ||||
| -rw-r--r-- | doc/lispref/elisp.texi | 1 | ||||
| -rw-r--r-- | doc/lispref/package.texi | 290 |
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 @@ | |||
| 1 | 2011-03-06 Chong Yidong <cyd@stupidchicken.com> | 1 | 2011-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 | ||
| 5 | 2011-03-05 Chong Yidong <cyd@stupidchicken.com> | 11 | 2011-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 | ||
| 1403 | Starting Up Emacs | 1404 | Starting 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 |
| 11 | to users. This approach lets users easily download, install, | 11 | users. A @dfn{package} is a collection of one or more files, |
| 12 | uninstall, and upgrade Lisp code that they might want to use. | 12 | formatted and bundled in such a way that users can easily download, |
| 13 | install, 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 |
| 15 | in a particular way. Typically a package includes primarily Emacs | 16 | put it in a @dfn{package archive} for others to download. |
| 16 | Lisp code, but it is possible to create other kinds of packages as | ||
| 17 | well. | ||
| 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 | ||
| 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 | |||
| 32 | @table @asis | 44 | @table @asis |
| 33 | @item Name | 45 | @item Name |
| 34 | A string, the name of the package. This attribute is mandatory. If | 46 | A short word (e.g. @samp{auctex}). This is usually also the symbol |
| 35 | it does not exist, the package cannot be installed by the package | 47 | prefix used in the program (@pxref{Coding Conventions}). |
| 36 | manager. | ||
| 37 | 48 | ||
| 38 | @item Version | 49 | @item Version |
| 39 | A version number, which is anything that can be parsed by | 50 | A 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 | 51 | understands (e.g. @samp{11.86}). Each release of a package should be |
| 41 | exist, the package cannot be installed by the package manager. | 52 | accompanied by an increase in the version number. |
| 42 | 53 | ||
| 43 | @item Brief description | 54 | @item Brief description |
| 44 | This is shown to the user in the package menu buffer. It is just a | 55 | This is shown when the package is listed in the Package Menu. It |
| 45 | single line. On a terminal with 80 characters per line, there are | 56 | should occupy a single line, ideally in 36 characters or less. |
| 46 | only 36 characters available in the package menu mode for showing the | ||
| 47 | brief description, so it is best to keep it very brief. If no brief | ||
| 48 | name is given, an empty string is used. | ||
| 49 | 57 | ||
| 50 | @item Long description | 58 | @item Long description |
| 51 | This can be a @file{README} file or the like. This is available to | 59 | This is shown in the buffer created by @kbd{C-h P} |
| 52 | the user before the package is installed, via the package menu. It | 60 | (@code{describe-package}), following the package's brief description |
| 53 | should more fully describe the package and its capabilities, so a user | 61 | and installation status. It normally spans multiple lines, and should |
| 54 | can read it to decide whether he wants to install the package. This | 62 | fully describe the package and its capabilities. |
| 55 | attribute is optional. | ||
| 56 | 63 | ||
| 57 | @item Dependencies | 64 | @item Dependencies |
| 58 | This is a list of other packages and their minimal acceptable | 65 | A list of other packages (possibly including minimal acceptable |
| 59 | versions. This is used both at download time (to make sure all the | 66 | version numbers) on which this package depends. The list may be |
| 60 | needed code is available) and at activation time (to ensure a package | 67 | empty, meaning this package has no dependencies. Otherwise, |
| 61 | is only activated if all its dependencies have been successfully | 68 | installing this package also automatically installs its dependencies; |
| 62 | activated). This attribute is optional. | 69 | if any dependency cannot be found, the package cannot be installed. |
| 63 | |||
| 64 | @item Manual | ||
| 65 | A 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 |
| 69 | reality some of these transitions are grouped together): | 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. | ||
| 70 | 98 | ||
| 71 | @table @asis | 99 | @node Simple Packages |
| 72 | @item Download | 100 | @section Simple Packages |
| 73 | Fetch 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 |
| 76 | Unpack the package, or write a @file{.el} file into the appropriate | 104 | file must conform to the Emacs Lisp library header conventions |
| 77 | install directory. This step also includes extracting autoloads and | 105 | (@pxref{Library Headers}). The package's attributes are taken from |
| 78 | byte-compiling the Emacs Lisp code. | 106 | the various headers, as illustrated by the following example: |
| 79 | 107 | ||
| 80 | @item Activate | 108 | @example |
| 81 | Update @code{load-path} and @code{Info-directory-list} and evaluate | 109 | @group |
| 82 | the 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. |
| 86 | activation time. The best approach is to have activation consist of | 113 | @end group |
| 87 | some 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{} |
| 94 | In this case, all the attributes of the package (@pxref{Packaging | ||
| 95 | Basics}) are taken from this file. | ||
| 96 | 121 | ||
| 97 | The package system expects this @file{.el} file to conform to the | 122 | ;;; Commentary: |
| 98 | Emacs 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 |
| 102 | given 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 | ||
| 108 | the package name will be @samp{superfrobnicator}. | 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}. | ||
| 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 |
| 111 | line of the file. | 137 | is @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 |
| 114 | description. | 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. | ||
| 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 |
| 117 | header, if it exists, or from the ``Version'' header. A package is | 144 | used as the long description. (When displaying the description, Emacs |
| 118 | required to have a version number. Each release of a package must be | 145 | omits the @samp{;;; Commentary:} line, as well as the leading comment |
| 119 | accompanied by an increase in the version number. | 146 | characters 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 |
| 122 | the package dependencies. Otherwise, the package is assumed not to | 149 | the package dependencies. In the above example, the package depends |
| 123 | have any dependencies. | 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. | ||
| 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, |
| 155 | as explained in @ref{Packaging Basics}. In the above example, a magic | ||
| 156 | comment 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}. | 159 | single-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 |
| 135 | convenient to create than a single-file package, a multi-file package | 166 | package, but it offers more features: it can include multiple Emacs |
| 136 | also offers more features: it can include an Info manual, multiple | 167 | Lisp files, an Info manual, and other file types (such as images). |
| 137 | Emacs 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 | 170 | archive as a tar file. The tar file must be named |
| 140 | single directory, named after the package and version. Files can | 171 | @file{@var{name}-@var{version}.tar}, where @var{name} is the package |
| 141 | appear in subdirectories of this top-most directory, but Emacs Lisp | 172 | name and @var{version} is the version number. Its contents, once |
| 142 | code will only be found (and thus byte-compiled) at the top-most | 173 | extracted, must all appear in a directory named |
| 143 | level. Also, the @file{.tar} file is typically also given this same | 174 | @file{@var{name}-@var{version}}, the @dfn{content directory} |
| 144 | name. For example, if you are distributing version 1.3 of the | 175 | (@pxref{Packaging Basics}). Files may also extract into |
| 145 | superfrobnicator, the package file would be named | 176 | subdirectories of the content directory. |
| 146 | ``superfrobnicator-1.3.tar'' and the contents would all appear in the | 177 | |
| 147 | directory @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 | 180 | consisting of a call to the function @code{define-package}, described |
| 150 | package. In our example above, this file would be called | 181 | below. This defines the package's version, brief description, and |
| 151 | @file{superfrobnicator-pkg.el}. This file must have a single form in | 182 | requirements. |
| 152 | it, a call to @code{define-package}. The package dependencies and | 183 | |
| 153 | brief description are taken from this form. | 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}. | ||
| 154 | 189 | ||
| 155 | @defun define-package name version &optional docstring requirements | 190 | @defun define-package name version &optional docstring requirements |
| 156 | Define a package. @var{name} is the name of the package, a string. | 191 | This 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 | 192 | string. @var{version} is the version, as a string of a form that can |
| 158 | form that can be understood by @code{version-to-list}. | 193 | be understood by the function @code{version-to-list}. @var{docstring} |
| 159 | @var{docstring} is the short description of the package. | 194 | is 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. |
| 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). | ||
| 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 |
| 164 | used as the long description. | 204 | file 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 |
| 167 | info files, plus a @file{dir} file made with @command{install-info}. | 207 | assumed 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 |
| 169 | install-info, texinfo, Texinfo}. | 209 | install-info, texinfo, Texinfo}. The Info files listed in this |
| 170 | 210 | directory file should also be present in the content directory. In | |
| 171 | Do not include any @file{.elc} files in the package. Those will be | 211 | this case, Emacs will automatically add the content directory to |
| 172 | created at install time. Note that there is no way to control the | 212 | @code{Info-directory-list} when the package is activated. |
| 173 | order in which files are byte-compiled; your package must be robust | ||
| 174 | here. | ||
| 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 |
| 177 | package for autoload cookies. @xref{Autoload}. They are extracted | 215 | created when the package is installed. Note that there is no way to |
| 178 | into a @file{-autoloads.el} file (e.g., | 216 | control the order in which files are byte-compiled. |
| 179 | @file{superfrobnicator-autoloads.el}), so do not include a file of | ||
| 180 | that 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 |
| 183 | package is installed. This can be useful if your package needs | 219 | file is reserved for the package's autoload definitions |
| 184 | auxiliary data files --- e.g., icons or sounds. | 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. | ||
| 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 |
| 187 | care to be location-independent. One easy way to do this is to make | 225 | images), the package's Lisp code can refer to these files via the |
| 188 | references to auxiliary data files relative to @var{load-file-name}. | 226 | variable @code{load-file-name} (@pxref{Loading}). Here is an example: |
| 189 | For 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 | |||
| 238 | To be done. | ||