* simple.el (shell-command-to-string): Use `process-file'.
[bpt/emacs.git] / lisp / emacs-lisp / package.el
CommitLineData
44198b6e
CY
1;;; package.el --- Simple package system for Emacs
2
73b0cd50 3;; Copyright (C) 2007-2011 Free Software Foundation, Inc.
44198b6e
CY
4
5;; Author: Tom Tromey <tromey@redhat.com>
6;; Created: 10 Mar 2007
7;; Version: 0.9
8;; Keywords: tools
9
10;; This file is part of GNU Emacs.
11
12;; GNU Emacs is free software; you can redistribute it and/or modify
13;; it under the terms of the GNU General Public License as published by
14;; the Free Software Foundation; either version 3, or (at your option)
15;; any later version.
16
17;; GNU Emacs is distributed in the hope that it will be useful,
18;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20;; GNU General Public License for more details.
21
22;; You should have received a copy of the GNU General Public License
23;; along with GNU Emacs; see the file COPYING. If not, write to the
24;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25;; Boston, MA 02110-1301, USA.
26
27;;; Change Log:
28
29;; 2 Apr 2007 - now using ChangeLog file
30;; 15 Mar 2007 - updated documentation
31;; 14 Mar 2007 - Changed how obsolete packages are handled
32;; 13 Mar 2007 - Wrote package-install-from-buffer
33;; 12 Mar 2007 - Wrote package-menu mode
34
35;;; Commentary:
36
37;; The idea behind package.el is to be able to download packages and
38;; install them. Packages are versioned and have versioned
39;; dependencies. Furthermore, this supports built-in packages which
40;; may or may not be newer than user-specified packages. This makes
41;; it possible to upgrade Emacs and automatically disable packages
42;; which have moved from external to core. (Note though that we don't
43;; currently register any of these, so this feature does not actually
44;; work.)
45
44198b6e
CY
46;; A package is described by its name and version. The distribution
47;; format is either a tar file or a single .el file.
48
49;; A tar file should be named "NAME-VERSION.tar". The tar file must
50;; unpack into a directory named after the package and version:
51;; "NAME-VERSION". It must contain a file named "PACKAGE-pkg.el"
52;; which consists of a call to define-package. It may also contain a
53;; "dir" file and the info files it references.
54
bc44bef7 55;; A .el file is named "NAME-VERSION.el" in the remote archive, but is
44198b6e
CY
56;; installed as simply "NAME.el" in a directory named "NAME-VERSION".
57
bc44bef7
PH
58;; The downloader downloads all dependent packages. By default,
59;; packages come from the official GNU sources, but others may be
60;; added by customizing the `package-archives' alist. Packages get
61;; byte-compiled at install time.
44198b6e
CY
62
63;; At activation time we will set up the load-path and the info path,
64;; and we will load the package's autoloads. If a package's
65;; dependencies are not available, we will not activate that package.
66
67;; Conceptually a package has multiple state transitions:
68;;
69;; * Download. Fetching the package from ELPA.
70;; * Install. Untar the package, or write the .el file, into
71;; ~/.emacs.d/elpa/ directory.
72;; * Byte compile. Currently this phase is done during install,
73;; but we may change this.
74;; * Activate. Evaluate the autoloads for the package to make it
75;; available to the user.
76;; * Load. Actually load the package and run some code from it.
77
78;; Other external functions you may want to use:
79;;
015eea59 80;; M-x list-packages
44198b6e
CY
81;; Enters a mode similar to buffer-menu which lets you manage
82;; packages. You can choose packages for install (mark with "i",
83;; then "x" to execute) or deletion (not implemented yet), and you
84;; can see what packages are available. This will automatically
85;; fetch the latest list of packages from ELPA.
86;;
87;; M-x package-list-packages-no-fetch
88;; Like package-list-packages, but does not automatically fetch the
89;; new list of packages.
90;;
91;; M-x package-install-from-buffer
92;; Install a package consisting of a single .el file that appears
93;; in the current buffer. This only works for packages which
94;; define a Version header properly; package.el also supports the
95;; extension headers Package-Version (in case Version is an RCS id
96;; or similar), and Package-Requires (if the package requires other
97;; packages).
98;;
99;; M-x package-install-file
100;; Install a package from the indicated file. The package can be
101;; either a tar file or a .el file. A tar file must contain an
102;; appropriately-named "-pkg.el" file; a .el file must be properly
103;; formatted as with package-install-from-buffer.
104
105;;; Thanks:
106;;; (sorted by sort-lines):
107
108;; Jim Blandy <jimb@red-bean.com>
109;; Karl Fogel <kfogel@red-bean.com>
110;; Kevin Ryde <user42@zip.com.au>
111;; Lawrence Mitchell
112;; Michael Olson <mwolson@member.fsf.org>
113;; Sebastian Tennant <sebyte@smolny.plus.com>
114;; Stefan Monnier <monnier@iro.umontreal.ca>
115;; Vinicius Jose Latorre <viniciusjl@ig.com.br>
116;; Phil Hagelberg <phil@hagelb.org>
117
118;;; ToDo:
119
120;; - putting info dirs at the start of the info path means
121;; users see a weird ordering of categories. OTOH we want to
122;; override later entries. maybe emacs needs to enforce
123;; the standard layout?
124;; - put bytecode in a separate directory tree
125;; - perhaps give users a way to recompile their bytecode
126;; or do it automatically when emacs changes
127;; - give users a way to know whether a package is installed ok
128;; - give users a way to view a package's documentation when it
129;; only appears in the .el
130;; - use/extend checkdoc so people can tell if their package will work
131;; - "installed" instead of a blank in the status column
132;; - tramp needs its files to be compiled in a certain order.
133;; how to handle this? fix tramp?
134;; - on emacs 21 we don't kill the -autoloads.el buffer. what about 22?
135;; - maybe we need separate .elc directories for various emacs versions
136;; and also emacs-vs-xemacs. That way conditional compilation can
137;; work. But would this break anything?
138;; - should store the package's keywords in archive-contents, then
139;; let the users filter the package-menu by keyword. See
140;; finder-by-keyword. (We could also let people view the
141;; Commentary, but it isn't clear how useful this is.)
142;; - William Xu suggests being able to open a package file without
143;; installing it
144;; - Interface with desktop.el so that restarting after an install
145;; works properly
146;; - Implement M-x package-upgrade, to upgrade any/all existing packages
147;; - Use hierarchical layout. PKG/etc PKG/lisp PKG/info
148;; ... except maybe lisp?
149;; - It may be nice to have a macro that expands to the package's
150;; private data dir, aka ".../etc". Or, maybe data-directory
151;; needs to be a list (though this would be less nice)
152;; a few packages want this, eg sokoban
153;; - package menu needs:
154;; ability to know which packages are built-in & thus not deletable
155;; it can sometimes print odd results, like 0.3 available but 0.4 active
156;; why is that?
157;; - Allow multiple versions on the server...?
158;; [ why bother? ]
159;; - Don't install a package which will invalidate dependencies overall
160;; - Allow something like (or (>= emacs 21.0) (>= xemacs 21.5))
161;; [ currently thinking, why bother.. KISS ]
162;; - Allow optional package dependencies
163;; then if we require 'bbdb', bbdb-specific lisp in lisp/bbdb
164;; and just don't compile to add to load path ...?
165;; - Have a list of archive URLs? [ maybe there's no point ]
166;; - David Kastrup pointed out on the xemacs list that for GPL it
167;; is friendlier to ship the source tree. We could "support" that
168;; by just having a "src" subdir in the package. This isn't ideal
169;; but it probably is not worth trying to support random source
170;; tree layouts, build schemes, etc.
171;; - Our treatment of the info path is somewhat bogus
172;; - perhaps have an "unstable" tree in ELPA as well as a stable one
173
174;;; Code:
175
176(defgroup package nil
177 "Manager for Emacs Lisp packages."
178 :group 'applications
179 :version "24.1")
180
181;;;###autoload
182(defcustom package-enable-at-startup t
183 "Whether to activate installed packages when Emacs starts.
184If non-nil, packages are activated after reading the init file
185and before `after-init-hook'. Activation is not done if
186`user-init-file' is nil (e.g. Emacs was started with \"-q\").
187
188Even if the value is nil, you can type \\[package-initialize] to
189activate the package system at any time."
190 :type 'boolean
191 :group 'package
192 :version "24.1")
193
194(defcustom package-load-list '(all)
195 "List of packages for `package-initialize' to load.
196Each element in this list should be a list (NAME VERSION), or the
197symbol `all'. The symbol `all' says to load the latest installed
198versions of all packages not specified by other elements.
199
200For an element (NAME VERSION), NAME is a package name (a symbol).
201VERSION should be t, a string, or nil.
202If VERSION is t, all versions are loaded, though obsolete ones
203 will be put in `package-obsolete-alist' and not activated.
204If VERSION is a string, only that version is ever loaded.
205 Any other version, even if newer, is silently ignored.
206 Hence, the package is \"held\" at that version.
207If VERSION is nil, the package is not loaded (it is \"disabled\")."
208 :type '(repeat symbol)
bc44bef7 209 :risky t
44198b6e
CY
210 :group 'package
211 :version "24.1")
212
213(defvar Info-directory-list)
44198b6e
CY
214(declare-function info-initialize "info" ())
215(declare-function url-http-parse-response "url-http" ())
216(declare-function lm-header "lisp-mnt" (header))
217(declare-function lm-commentary "lisp-mnt" (&optional file))
cb6c4991 218(defvar url-http-end-of-headers)
44198b6e 219
bc44bef7
PH
220(defcustom package-archives '(("gnu" . "http://elpa.gnu.org/packages/"))
221 "An alist of archives from which to fetch.
222The default value points to the GNU Emacs package repository.
f561e49a
CY
223
224Each element has the form (ID . LOCATION).
225 ID is an archive name, as a string.
226 LOCATION specifies the base location for the archive.
227 If it starts with \"http:\", it is treated as a HTTP URL;
228 otherwise it should be an absolute directory name.
229 (Other types of URL are currently not supported.)"
bc44bef7 230 :type '(alist :key-type (string :tag "Archive name")
f561e49a 231 :value-type (string :tag "URL or directory name"))
bc44bef7
PH
232 :risky t
233 :group 'package
234 :version "24.1")
44198b6e
CY
235
236(defconst package-archive-version 1
237 "Version number of the package archive understood by this file.
238Lower version numbers than this will probably be understood as well.")
239
240(defconst package-el-version "1.0"
241 "Version of package.el.")
242
243;; We don't prime the cache since it tends to get out of date.
244(defvar package-archive-contents nil
245 "Cache of the contents of the Emacs Lisp Package Archive.
246This is an alist mapping package names (symbols) to package
247descriptor vectors. These are like the vectors for `package-alist'
bc44bef7
PH
248but have extra entries: one which is 'tar for tar packages and
249'single for single-file packages, and one which is the name of
250the archive from which it came.")
251(put 'package-archive-contents 'risky-local-variable t)
44198b6e
CY
252
253(defcustom package-user-dir (locate-user-emacs-file "elpa")
254 "Directory containing the user's Emacs Lisp packages.
255The directory name should be absolute.
256Apart from this directory, Emacs also looks for system-wide
257packages in `package-directory-list'."
258 :type 'directory
bc44bef7 259 :risky t
44198b6e
CY
260 :group 'package
261 :version "24.1")
262
263(defcustom package-directory-list
264 ;; Defaults are subdirs named "elpa" in the site-lisp dirs.
265 (let (result)
266 (dolist (f load-path)
0be01d2c
CY
267 (and (stringp f)
268 (equal (file-name-nondirectory f) "site-lisp")
269 (push (expand-file-name "elpa" f) result)))
44198b6e
CY
270 (nreverse result))
271 "List of additional directories containing Emacs Lisp packages.
272Each directory name should be absolute.
273
274These directories contain packages intended for system-wide; in
275contrast, `package-user-dir' contains packages for personal use."
276 :type '(repeat directory)
bc44bef7 277 :risky t
44198b6e
CY
278 :group 'package
279 :version "24.1")
280
96ae4c8f
CY
281;; The value is precomputed in finder-inf.el, but don't load that
282;; until it's needed (i.e. when `package-intialize' is called).
283(defvar package--builtins nil
284 "Alist of built-in packages.
015eea59
CY
285The actual value is initialized by loading the library
286`finder-inf'; this is not done until it is needed, e.g. by the
287function `package-built-in-p'.
288
96ae4c8f
CY
289Each element has the form (PKG . DESC), where PKG is a package
290name (a symbol) and DESC is a vector that describes the package.
96ae4c8f
CY
291The vector DESC has the form [VERSION REQS DOCSTRING].
292 VERSION is a version list.
293 REQS is a list of packages (symbols) required by the package.
294 DOCSTRING is a brief description of the package.")
bc44bef7 295(put 'package--builtins 'risky-local-variable t)
44198b6e 296
96ae4c8f 297(defvar package-alist nil
44198b6e 298 "Alist of all packages available for activation.
96ae4c8f
CY
299Each element has the form (PKG . DESC), where PKG is a package
300name (a symbol) and DESC is a vector that describes the package.
44198b6e 301
96ae4c8f
CY
302The vector DESC has the form [VERSION REQS DOCSTRING].
303 VERSION is a version list.
304 REQS is a list of packages (symbols) required by the package.
305 DOCSTRING is a brief description of the package.
306
307This variable is set automatically by `package-load-descriptor',
308called via `package-initialize'. To change which packages are
309loaded and/or activated, customize `package-load-list'.")
bc44bef7 310(put 'package-archive-contents 'risky-local-variable t)
44198b6e 311
96ae4c8f 312(defvar package-activated-list nil
44198b6e 313 "List of the names of currently activated packages.")
bc44bef7 314(put 'package-activated-list 'risky-local-variable t)
44198b6e
CY
315
316(defvar package-obsolete-alist nil
317 "Representation of obsolete packages.
318Like `package-alist', but maps package name to a second alist.
319The inner alist is keyed by version.")
bc44bef7 320(put 'package-obsolete-alist 'risky-local-variable t)
44198b6e
CY
321
322(defconst package-subdirectory-regexp
323 "^\\([^.].*\\)-\\([0-9]+\\(?:[.][0-9]+\\)*\\)$"
324 "Regular expression matching the name of a package subdirectory.
325The first subexpression is the package name.
326The second subexpression is the version string.")
327
328(defun package-version-join (l)
329 "Turn a list of version numbers into a version string."
330 (mapconcat 'int-to-string l "."))
331
44198b6e
CY
332(defun package-strip-version (dirname)
333 "Strip the version from a combined package name and version.
334E.g., if given \"quux-23.0\", will return \"quux\""
335 (if (string-match package-subdirectory-regexp dirname)
336 (match-string 1 dirname)))
337
338(defun package-load-descriptor (dir package)
4b99edf2
CY
339 "Load the description file in directory DIR for package PACKAGE.
340Here, PACKAGE is a string of the form NAME-VER, where NAME is the
341package name and VER is its version."
bc44bef7
PH
342 (let* ((pkg-dir (expand-file-name package dir))
343 (pkg-file (expand-file-name
344 (concat (package-strip-version package) "-pkg")
345 pkg-dir)))
346 (when (and (file-directory-p pkg-dir)
347 (file-exists-p (concat pkg-file ".el")))
348 (load pkg-file nil t))))
44198b6e
CY
349
350(defun package-load-all-descriptors ()
351 "Load descriptors for installed Emacs Lisp packages.
352This looks for package subdirectories in `package-user-dir' and
353`package-directory-list'. The variable `package-load-list'
354controls which package subdirectories may be loaded.
355
356In each valid package subdirectory, this function loads the
357description file containing a call to `define-package', which
358updates `package-alist' and `package-obsolete-alist'."
359 (let ((all (memq 'all package-load-list))
360 name version force)
361 (dolist (dir (cons package-user-dir package-directory-list))
362 (when (file-directory-p dir)
363 (dolist (subdir (directory-files dir))
364 (when (and (file-directory-p (expand-file-name subdir dir))
365 (string-match package-subdirectory-regexp subdir))
366 (setq name (intern (match-string 1 subdir))
367 version (match-string 2 subdir)
368 force (assq name package-load-list))
369 (when (cond
370 ((null force)
371 all) ; not in package-load-list
372 ((null (setq force (cadr force)))
373 nil) ; disabled
374 ((eq force t)
375 t)
376 ((stringp force) ; held
148cef8e
CY
377 (version-list-= (version-to-list version)
378 (version-to-list force)))
44198b6e
CY
379 (t
380 (error "Invalid element in `package-load-list'")))
381 (package-load-descriptor dir subdir))))))))
382
383(defsubst package-desc-vers (desc)
384 "Extract version from a package description vector."
385 (aref desc 0))
386
387(defsubst package-desc-reqs (desc)
388 "Extract requirements from a package description vector."
389 (aref desc 1))
390
391(defsubst package-desc-doc (desc)
392 "Extract doc string from a package description vector."
393 (aref desc 2))
394
395(defsubst package-desc-kind (desc)
396 "Extract the kind of download from an archive package description vector."
397 (aref desc 3))
398
015eea59
CY
399(defun package--dir (name version)
400 "Return the directory where a package is installed, or nil if none.
401NAME and VERSION are both strings."
402 (let* ((subdir (concat name "-" version))
44198b6e 403 (dir-list (cons package-user-dir package-directory-list))
cced7584 404 pkg-dir)
44198b6e 405 (while dir-list
cced7584
CY
406 (let ((subdir-full (expand-file-name subdir (car dir-list))))
407 (if (file-directory-p subdir-full)
408 (setq pkg-dir subdir-full
409 dir-list nil)
44198b6e 410 (setq dir-list (cdr dir-list)))))
cced7584
CY
411 pkg-dir))
412
413(defun package-activate-1 (package pkg-vec)
414 (let* ((name (symbol-name package))
415 (version-str (package-version-join (package-desc-vers pkg-vec)))
416 (pkg-dir (package--dir name version-str)))
44198b6e 417 (unless pkg-dir
015eea59 418 (error "Internal error: unable to find directory for `%s-%s'"
cced7584
CY
419 name version-str))
420 ;; Add info node.
ebf662f4
CY
421 (when (file-exists-p (expand-file-name "dir" pkg-dir))
422 ;; FIXME: not the friendliest, but simple.
423 (require 'info)
424 (info-initialize)
425 (push pkg-dir Info-directory-list))
cced7584 426 ;; Add to load path, add autoloads, and activate the package.
ebf662f4 427 (push pkg-dir load-path)
cced7584 428 (load (expand-file-name (concat name "-autoloads") pkg-dir) nil t)
ebf662f4 429 (push package package-activated-list)
44198b6e
CY
430 ;; Don't return nil.
431 t))
432
4b99edf2
CY
433(defun package-built-in-p (package &optional version)
434 "Return true if PACKAGE, of VERSION or newer, is built-in to Emacs."
435 (require 'finder-inf nil t) ; For `package--builtins'.
44198b6e 436 (let ((elt (assq package package--builtins)))
4b99edf2 437 (and elt (version-list-<= version (package-desc-vers (cdr elt))))))
44198b6e 438
4b99edf2
CY
439;; This function goes ahead and activates a newer version of a package
440;; if an older one was already activated. This is not ideal; we'd at
441;; least need to check to see if the package has actually been loaded,
442;; and not merely activated.
44198b6e 443(defun package-activate (package version)
4b99edf2
CY
444 "Activate package PACKAGE, of version VERSION or newer.
445If PACKAGE has any dependencies, recursively activate them.
44198b6e 446Return nil if the package could not be activated."
4b99edf2
CY
447 (let ((pkg-vec (cdr (assq package package-alist)))
448 available-version found)
449 ;; Check if PACKAGE is available in `package-alist'.
450 (when pkg-vec
451 (setq available-version (package-desc-vers pkg-vec)
452 found (version-list-<= version available-version)))
453 (cond
454 ;; If no such package is found, maybe it's built-in.
455 ((null found)
456 (package-built-in-p package version))
457 ;; If the package is already activated, just return t.
458 ((memq package package-activated-list)
459 t)
460 ;; Otherwise, proceed with activation.
461 (t
462 (let ((fail (catch 'dep-failure
463 ;; Activate its dependencies recursively.
464 (dolist (req (package-desc-reqs pkg-vec))
465 (unless (package-activate (car req) (cadr req))
466 (throw 'dep-failure req))))))
467 (if fail
468 (warn "Unable to activate package `%s'.
015eea59 469Required package `%s-%s' is unavailable"
4b99edf2
CY
470 package (car fail) (package-version-join (cadr fail)))
471 ;; If all goes well, activate the package itself.
472 (package-activate-1 package pkg-vec)))))))
44198b6e
CY
473
474(defun package-mark-obsolete (package pkg-vec)
475 "Put package on the obsolete list, if not already there."
476 (let ((elt (assq package package-obsolete-alist)))
477 (if elt
478 ;; If this obsolete version does not exist in the list, update
479 ;; it the list.
480 (unless (assoc (package-desc-vers pkg-vec) (cdr elt))
481 (setcdr elt (cons (cons (package-desc-vers pkg-vec) pkg-vec)
482 (cdr elt))))
483 ;; Make a new association.
ebf662f4
CY
484 (push (cons package (list (cons (package-desc-vers pkg-vec)
485 pkg-vec)))
486 package-obsolete-alist))))
44198b6e 487
4b99edf2 488(defun define-package (name-string version-string
187d3296
CY
489 &optional docstring requirements
490 &rest extra-properties)
44198b6e 491 "Define a new package.
4b99edf2
CY
492NAME-STRING is the name of the package, as a string.
493VERSION-STRING is the version of the package, as a list of
494integers of the form produced by `version-to-list'.
495DOCSTRING is a short description of the package, a string.
496REQUIREMENTS is a list of dependencies on other packages.
187d3296
CY
497Each requirement is of the form (OTHER-PACKAGE \"VERSION\").
498
499EXTRA-PROPERTIES is currently unused."
4b99edf2
CY
500 (let* ((name (intern name-string))
501 (version (version-to-list version-string))
44198b6e
CY
502 (new-pkg-desc
503 (cons name
4b99edf2 504 (vector version
44198b6e
CY
505 (mapcar
506 (lambda (elt)
507 (list (car elt)
148cef8e 508 (version-to-list (car (cdr elt)))))
44198b6e 509 requirements)
4b99edf2
CY
510 docstring)))
511 (old-pkg (assq name package-alist)))
512 (cond
513 ;; If there's no old package, just add this to `package-alist'.
514 ((null old-pkg)
515 (push new-pkg-desc package-alist))
516 ((version-list-< (package-desc-vers (cdr old-pkg)) version)
517 ;; Remove the old package and declare it obsolete.
518 (package-mark-obsolete name (cdr old-pkg))
519 (setq package-alist (cons new-pkg-desc
520 (delq old-pkg package-alist))))
521 ;; You can have two packages with the same version, e.g. one in
522 ;; the system package directory and one in your private
523 ;; directory. We just let the first one win.
524 ((not (version-list-= (package-desc-vers (cdr old-pkg)) version))
525 ;; The package is born obsolete.
526 (package-mark-obsolete name (cdr new-pkg-desc))))))
44198b6e
CY
527
528;; From Emacs 22.
529(defun package-autoload-ensure-default-file (file)
530 "Make sure that the autoload file FILE exists and if not create it."
531 (unless (file-exists-p file)
532 (write-region
533 (concat ";;; " (file-name-nondirectory file)
534 " --- automatically extracted autoloads\n"
535 ";;\n"
536 ";;; Code:\n\n"
537 "\f\n;; Local Variables:\n"
538 ";; version-control: never\n"
539 ";; no-byte-compile: t\n"
540 ";; no-update-autoloads: t\n"
541 ";; End:\n"
542 ";;; " (file-name-nondirectory file)
543 " ends here\n")
544 nil file))
545 file)
546
547(defun package-generate-autoloads (name pkg-dir)
548 (let* ((auto-name (concat name "-autoloads.el"))
549 (ignore-name (concat name "-pkg.el"))
550 (generated-autoload-file (expand-file-name auto-name pkg-dir))
551 (version-control 'never))
552 (require 'autoload)
553 (unless (fboundp 'autoload-ensure-default-file)
554 (package-autoload-ensure-default-file generated-autoload-file))
555 (update-directory-autoloads pkg-dir)))
556
557(defun package-untar-buffer ()
558 "Untar the current buffer.
559This uses `tar-untar-buffer' if it is available.
560Otherwise it uses an external `tar' program.
561`default-directory' should be set by the caller."
562 (require 'tar-mode)
563 (if (fboundp 'tar-untar-buffer)
564 (progn
565 ;; tar-mode messes with narrowing, so we just let it have the
566 ;; whole buffer to play with.
567 (delete-region (point-min) (point))
568 (tar-mode)
569 (tar-untar-buffer))
570 ;; FIXME: check the result.
571 (call-process-region (point) (point-max) "tar" nil '(nil nil) nil
572 "xf" "-")))
573
574(defun package-unpack (name version)
575 (let ((pkg-dir (expand-file-name (concat (symbol-name name) "-" version)
576 package-user-dir)))
44198b6e 577 (make-directory package-user-dir t)
015eea59 578 ;; FIXME: should we delete PKG-DIR if it exists?
44198b6e
CY
579 (let* ((default-directory (file-name-as-directory package-user-dir)))
580 (package-untar-buffer)
581 (package-generate-autoloads (symbol-name name) pkg-dir)
582 (let ((load-path (cons pkg-dir load-path)))
583 (byte-recompile-directory pkg-dir 0 t)))))
584
c6affbde 585(defun package--write-file-no-coding (file-name)
bc44bef7 586 (let ((buffer-file-coding-system 'no-conversion))
c6affbde 587 (write-region (point-min) (point-max) file-name)))
bc44bef7 588
44198b6e
CY
589(defun package-unpack-single (file-name version desc requires)
590 "Install the contents of the current buffer as a package."
591 ;; Special case "package".
592 (if (string= file-name "package")
bc44bef7 593 (package--write-file-no-coding
c6affbde 594 (expand-file-name (concat file-name ".el") package-user-dir))
44198b6e
CY
595 (let* ((pkg-dir (expand-file-name (concat file-name "-" version)
596 package-user-dir))
597 (el-file (expand-file-name (concat file-name ".el") pkg-dir))
598 (pkg-file (expand-file-name (concat file-name "-pkg.el") pkg-dir)))
599 (make-directory pkg-dir t)
c6affbde 600 (package--write-file-no-coding el-file)
44198b6e
CY
601 (let ((print-level nil)
602 (print-length nil))
603 (write-region
604 (concat
605 (prin1-to-string
606 (list 'define-package
607 file-name
608 version
609 desc
610 (list 'quote
611 ;; Turn version lists into string form.
612 (mapcar
613 (lambda (elt)
614 (list (car elt)
015eea59 615 (package-version-join (cadr elt))))
44198b6e
CY
616 requires))))
617 "\n")
618 nil
619 pkg-file
620 nil nil nil 'excl))
621 (package-generate-autoloads file-name pkg-dir)
622 (let ((load-path (cons pkg-dir load-path)))
623 (byte-recompile-directory pkg-dir 0 t)))))
624
f561e49a
CY
625(defmacro package--with-work-buffer (location file &rest body)
626 "Run BODY in a buffer containing the contents of FILE at LOCATION.
627LOCATION is the base location of a package archive, and should be
628one of the URLs (or file names) specified in `package-archives'.
629FILE is the name of a file relative to that base location.
630
631This macro retrieves FILE from LOCATION into a temporary buffer,
632and evaluates BODY while that buffer is current. This work
633buffer is killed afterwards. Return the last value in BODY."
634 `(let* ((http (string-match "\\`http:" ,location))
635 (buffer
636 (if http
637 (url-retrieve-synchronously (concat ,location ,file))
638 (generate-new-buffer "*package work buffer*"))))
639 (prog1
640 (with-current-buffer buffer
641 (if http
642 (progn (package-handle-response)
643 (re-search-forward "^$" nil 'move)
644 (forward-char)
645 (delete-region (point-min) (point)))
646 (unless (file-name-absolute-p ,location)
647 (error "Archive location %s is not an absolute file name"
648 ,location))
649 (insert-file-contents (expand-file-name ,file ,location)))
650 ,@body)
651 (kill-buffer buffer))))
652
44198b6e 653(defun package-handle-response ()
f561e49a 654 "Handle the response from a `url-retrieve-synchronously' call.
44198b6e
CY
655Parse the HTTP response and throw if an error occurred.
656The url package seems to require extra processing for this.
657This should be called in a `save-excursion', in the download buffer.
658It will move point to somewhere in the headers."
659 ;; We assume HTTP here.
660 (require 'url-http)
661 (let ((response (url-http-parse-response)))
662 (when (or (< response 200) (>= response 300))
44198b6e
CY
663 (error "Error during download request:%s"
664 (buffer-substring-no-properties (point) (progn
665 (end-of-line)
666 (point)))))))
667
668(defun package-download-single (name version desc requires)
669 "Download and install a single-file package."
f561e49a
CY
670 (let ((location (package-archive-base name))
671 (file (concat (symbol-name name) "-" version ".el")))
672 (package--with-work-buffer location file
673 (package-unpack-single (symbol-name name) version desc requires))))
44198b6e
CY
674
675(defun package-download-tar (name version)
676 "Download and install a tar package."
f561e49a
CY
677 (let ((location (package-archive-base name))
678 (file (concat (symbol-name name) "-" version ".tar")))
679 (package--with-work-buffer location file
680 (package-unpack name version))))
44198b6e 681
bc44bef7 682(defun package-installed-p (package &optional min-version)
4b99edf2
CY
683 "Return true if PACKAGE, of VERSION or newer, is installed.
684Built-in packages also qualify."
44198b6e 685 (let ((pkg-desc (assq package package-alist)))
4b99edf2
CY
686 (if pkg-desc
687 (version-list-<= min-version
688 (package-desc-vers (cdr pkg-desc)))
689 ;; Also check built-in packages.
690 (package-built-in-p package min-version))))
44198b6e 691
96ae4c8f
CY
692(defun package-compute-transaction (package-list requirements)
693 "Return a list of packages to be installed, including PACKAGE-LIST.
694PACKAGE-LIST should be a list of package names (symbols).
695
696REQUIREMENTS should be a list of additional requirements; each
697element in this list should have the form (PACKAGE VERSION),
698where PACKAGE is a package name and VERSION is the required
699version of that package (as a list).
700
701This function recursively computes the requirements of the
702packages in REQUIREMENTS, and returns a list of all the packages
703that must be installed. Packages that are already installed are
704not included in this list."
44198b6e
CY
705 (dolist (elt requirements)
706 (let* ((next-pkg (car elt))
707 (next-version (cadr elt)))
708 (unless (package-installed-p next-pkg next-version)
709 ;; A package is required, but not installed. It might also be
710 ;; blocked via `package-load-list'.
711 (let ((pkg-desc (assq next-pkg package-archive-contents))
712 hold)
713 (when (setq hold (assq next-pkg package-load-list))
714 (setq hold (cadr hold))
715 (cond ((eq hold nil)
716 (error "Required package '%s' is disabled"
717 (symbol-name next-pkg)))
718 ((null (stringp hold))
719 (error "Invalid element in `package-load-list'"))
148cef8e 720 ((version-list-< (version-to-list hold) next-version)
015eea59 721 (error "Package `%s' held at version %s, \
44198b6e
CY
722but version %s required"
723 (symbol-name next-pkg) hold
724 (package-version-join next-version)))))
725 (unless pkg-desc
015eea59 726 (error "Package `%s-%s' is unavailable"
4b99edf2
CY
727 (symbol-name next-pkg)
728 (package-version-join next-version)))
148cef8e
CY
729 (unless (version-list-<= next-version
730 (package-desc-vers (cdr pkg-desc)))
44198b6e 731 (error
015eea59 732 "Need package `%s-%s', but only %s is available"
44198b6e
CY
733 (symbol-name next-pkg) (package-version-join next-version)
734 (package-version-join (package-desc-vers (cdr pkg-desc)))))
735 ;; Only add to the transaction if we don't already have it.
96ae4c8f 736 (unless (memq next-pkg package-list)
ebf662f4 737 (push next-pkg package-list))
96ae4c8f
CY
738 (setq package-list
739 (package-compute-transaction package-list
44198b6e
CY
740 (package-desc-reqs
741 (cdr pkg-desc))))))))
96ae4c8f 742 package-list)
44198b6e
CY
743
744(defun package-read-from-string (str)
745 "Read a Lisp expression from STR.
746Signal an error if the entire string was not used."
747 (let* ((read-data (read-from-string str))
187d3296
CY
748 (more-left
749 (condition-case nil
750 ;; The call to `ignore' suppresses a compiler warning.
751 (progn (ignore (read-from-string
752 (substring str (cdr read-data))))
753 t)
754 (end-of-file nil))))
44198b6e
CY
755 (if more-left
756 (error "Can't read whole string")
757 (car read-data))))
758
759(defun package--read-archive-file (file)
760 "Re-read archive file FILE, if it exists.
761Will return the data from the file, or nil if the file does not exist.
762Will throw an error if the archive version is too new."
763 (let ((filename (expand-file-name file package-user-dir)))
187d3296
CY
764 (when (file-exists-p filename)
765 (with-temp-buffer
766 (insert-file-contents-literally filename)
767 (let ((contents (read (current-buffer))))
768 (if (> (car contents) package-archive-version)
769 (error "Package archive version %d is higher than %d"
770 (car contents) package-archive-version))
771 (cdr contents))))))
44198b6e 772
bc44bef7 773(defun package-read-all-archive-contents ()
96ae4c8f
CY
774 "Re-read `archive-contents', if it exists.
775If successful, set `package-archive-contents'."
fbe3be3f 776 (setq package-archive-contents nil)
bc44bef7 777 (dolist (archive package-archives)
96ae4c8f 778 (package-read-archive-contents (car archive))))
44198b6e 779
bc44bef7 780(defun package-read-archive-contents (archive)
187d3296
CY
781 "Re-read archive contents for ARCHIVE.
782If successful, set the variable `package-archive-contents'.
bc44bef7 783If the archive version is too new, signal an error."
187d3296
CY
784 ;; Version 1 of 'archive-contents' is identical to our internal
785 ;; representation.
786 (let* ((dir (concat "archives/" archive))
787 (contents-file (concat dir "/archive-contents"))
788 contents)
789 (when (setq contents (package--read-archive-file contents-file))
790 (dolist (package contents)
791 (package--add-to-archive-contents package archive)))))
bc44bef7
PH
792
793(defun package--add-to-archive-contents (package archive)
794 "Add the PACKAGE from the given ARCHIVE if necessary.
795Also, add the originating archive to the end of the package vector."
796 (let* ((name (car package))
797 (version (aref (cdr package) 0))
798 (entry (cons (car package)
799 (vconcat (cdr package) (vector archive))))
800 (existing-package (cdr (assq name package-archive-contents))))
801 (when (or (not existing-package)
148cef8e 802 (version-list-< (aref existing-package 0) version))
bc44bef7
PH
803 (add-to-list 'package-archive-contents entry))))
804
96ae4c8f
CY
805(defun package-download-transaction (package-list)
806 "Download and install all the packages in PACKAGE-LIST.
807PACKAGE-LIST should be a list of package names (symbols).
808This function assumes that all package requirements in
809PACKAGE-LIST are satisfied, i.e. that PACKAGE-LIST is computed
810using `package-compute-transaction'."
811 (dolist (elt package-list)
44198b6e
CY
812 (let* ((desc (cdr (assq elt package-archive-contents)))
813 ;; As an exception, if package is "held" in
814 ;; `package-load-list', download the held version.
815 (hold (cadr (assq elt package-load-list)))
816 (v-string (or (and (stringp hold) hold)
817 (package-version-join (package-desc-vers desc))))
818 (kind (package-desc-kind desc)))
819 (cond
820 ((eq kind 'tar)
821 (package-download-tar elt v-string))
822 ((eq kind 'single)
823 (package-download-single elt v-string
824 (package-desc-doc desc)
825 (package-desc-reqs desc)))
826 (t
827 (error "Unknown package kind: %s" (symbol-name kind)))))))
828
829;;;###autoload
830(defun package-install (name)
831 "Install the package named NAME.
832Interactively, prompt for the package name.
063e5294 833The package is found on one of the archives in `package-archives'."
44198b6e 834 (interactive
bc44bef7
PH
835 (list (intern (completing-read "Install package: "
836 (mapcar (lambda (elt)
837 (cons (symbol-name (car elt))
838 nil))
839 package-archive-contents)
840 nil t))))
44198b6e
CY
841 (let ((pkg-desc (assq name package-archive-contents)))
842 (unless pkg-desc
015eea59 843 (error "Package `%s' is not available for installation"
44198b6e 844 (symbol-name name)))
bc44bef7
PH
845 (package-download-transaction
846 (package-compute-transaction (list name)
847 (package-desc-reqs (cdr pkg-desc)))))
44198b6e
CY
848 ;; Try to activate it.
849 (package-initialize))
850
851(defun package-strip-rcs-id (v-str)
852 "Strip RCS version ID from the version string.
853If the result looks like a dotted numeric version, return it.
854Otherwise return nil."
855 (if v-str
856 (if (string-match "^[ \t]*[$]Revision:[ \t]\([0-9.]+\)[ \t]*[$]$" v-str)
857 (match-string 1 v-str)
858 (if (string-match "^[0-9.]*$" v-str)
859 v-str))))
860
861(defun package-buffer-info ()
187d3296
CY
862 "Return a vector describing the package in the current buffer.
863The vector has the form
864
865 [FILENAME REQUIRES DESCRIPTION VERSION COMMENTARY]
866
867FILENAME is the file name, a string, sans the \".el\" extension.
44198b6e 868REQUIRES is a requires list, or nil.
187d3296 869DESCRIPTION is the package description, a string.
44198b6e
CY
870VERSION is the version, a string.
871COMMENTARY is the commentary section, a string, or nil if none.
187d3296
CY
872
873If the buffer does not contain a conforming package, signal an
874error. If there is a package, narrow the buffer to the file's
875boundaries."
44198b6e 876 (goto-char (point-min))
187d3296
CY
877 (unless (re-search-forward "^;;; \\([^ ]*\\)\\.el --- \\(.*\\)$" nil t)
878 (error "Packages lacks a file header"))
879 (let ((file-name (match-string-no-properties 1))
880 (desc (match-string-no-properties 2))
881 (start (line-beginning-position)))
882 (unless (search-forward (concat ";;; " file-name ".el ends here"))
883 (error "Package lacks a terminating comment"))
884 ;; Try to include a trailing newline.
885 (forward-line)
886 (narrow-to-region start (point))
887 (require 'lisp-mnt)
888 ;; Use some headers we've invented to drive the process.
889 (let* ((requires-str (lm-header "package-requires"))
890 (requires (if requires-str
891 (package-read-from-string requires-str)))
892 ;; Prefer Package-Version; if defined, the package author
893 ;; probably wants us to use it. Otherwise try Version.
894 (pkg-version
895 (or (package-strip-rcs-id (lm-header "package-version"))
896 (package-strip-rcs-id (lm-header "version"))))
897 (commentary (lm-commentary)))
898 (unless pkg-version
899 (error
900 "Package lacks a \"Version\" or \"Package-Version\" header"))
901 ;; Turn string version numbers into list form.
902 (setq requires
903 (mapcar
904 (lambda (elt)
905 (list (car elt)
906 (version-to-list (car (cdr elt)))))
907 requires))
908 (vector file-name requires desc pkg-version commentary))))
44198b6e
CY
909
910(defun package-tar-file-info (file)
911 "Find package information for a tar file.
912FILE is the name of the tar file to examine.
913The return result is a vector like `package-buffer-info'."
b511b994
MA
914 (let ((default-directory (file-name-directory file))
915 (file (file-name-nondirectory file)))
916 (unless (string-match "^\\(.+\\)-\\([0-9.]+\\)\\.tar$" file)
917 (error "Invalid package name `%s'" file))
918 (let* ((pkg-name (match-string-no-properties 1 file))
919 (pkg-version (match-string-no-properties 2 file))
920 ;; Extract the package descriptor.
921 (pkg-def-contents (shell-command-to-string
922 ;; Requires GNU tar.
923 (concat "tar -xOf " file " "
924
925 pkg-name "-" pkg-version "/"
926 pkg-name "-pkg.el")))
927 (pkg-def-parsed (package-read-from-string pkg-def-contents)))
928 (unless (eq (car pkg-def-parsed) 'define-package)
929 (error "No `define-package' sexp is present in `%s-pkg.el'" pkg-name))
930 (let ((name-str (nth 1 pkg-def-parsed))
931 (version-string (nth 2 pkg-def-parsed))
932 (docstring (nth 3 pkg-def-parsed))
933 (requires (nth 4 pkg-def-parsed))
934 (readme (shell-command-to-string
935 ;; Requires GNU tar.
936 (concat "tar -xOf " file " "
937 pkg-name "-" pkg-version "/README"))))
938 (unless (equal pkg-version version-string)
939 (error "Package has inconsistent versions"))
940 (unless (equal pkg-name name-str)
941 (error "Package has inconsistent names"))
942 ;; Kind of a hack.
943 (if (string-match ": Not found in archive" readme)
944 (setq readme nil))
945 ;; Turn string version numbers into list form.
946 (if (eq (car requires) 'quote)
947 (setq requires (car (cdr requires))))
948 (setq requires
949 (mapcar (lambda (elt)
950 (list (car elt)
951 (version-to-list (cadr elt))))
952 requires))
953 (vector pkg-name requires docstring version-string readme)))))
44198b6e 954
187d3296
CY
955;;;###autoload
956(defun package-install-from-buffer (pkg-info type)
957 "Install a package from the current buffer.
958When called interactively, the current buffer is assumed to be a
959single .el file that follows the packaging guidelines; see info
960node `(elisp)Packaging'.
961
962When called from Lisp, PKG-INFO is a vector describing the
963information, of the type returned by `package-buffer-info'; and
964TYPE is the package type (either `single' or `tar')."
965 (interactive (list (package-buffer-info) 'single))
44198b6e
CY
966 (save-excursion
967 (save-restriction
968 (let* ((file-name (aref pkg-info 0))
187d3296 969 (requires (aref pkg-info 1))
44198b6e
CY
970 (desc (if (string= (aref pkg-info 2) "")
971 "No description available."
972 (aref pkg-info 2)))
973 (pkg-version (aref pkg-info 3)))
974 ;; Download and install the dependencies.
975 (let ((transaction (package-compute-transaction nil requires)))
976 (package-download-transaction transaction))
977 ;; Install the package itself.
978 (cond
979 ((eq type 'single)
980 (package-unpack-single file-name pkg-version desc requires))
981 ((eq type 'tar)
982 (package-unpack (intern file-name) pkg-version))
983 (t
984 (error "Unknown type: %s" (symbol-name type))))
985 ;; Try to activate it.
986 (package-initialize)))))
987
44198b6e
CY
988;;;###autoload
989(defun package-install-file (file)
990 "Install a package from a file.
991The file can either be a tar file or an Emacs Lisp file."
992 (interactive "fPackage file name: ")
993 (with-temp-buffer
994 (insert-file-contents-literally file)
995 (cond
187d3296
CY
996 ((string-match "\\.el$" file)
997 (package-install-from-buffer (package-buffer-info) 'single))
44198b6e 998 ((string-match "\\.tar$" file)
187d3296 999 (package-install-from-buffer (package-tar-file-info file) 'tar))
44198b6e
CY
1000 (t (error "Unrecognized extension `%s'" (file-name-extension file))))))
1001
1002(defun package-delete (name version)
015eea59
CY
1003 (let ((dir (package--dir name version)))
1004 (if (string-equal (file-name-directory dir)
1005 (file-name-as-directory
1006 (expand-file-name package-user-dir)))
1007 (progn
1008 (delete-directory dir t t)
1009 (message "Package `%s-%s' deleted." name version))
1010 ;; Don't delete "system" packages
1011 (error "Package `%s-%s' is a system package, not deleting"
1012 name version))))
44198b6e 1013
f561e49a 1014(defun package-archive-base (name)
bc44bef7
PH
1015 "Return the archive containing the package NAME."
1016 (let ((desc (cdr (assq (intern-soft name) package-archive-contents))))
1017 (cdr (assoc (aref desc (- (length desc) 1)) package-archives))))
1018
1019(defun package--download-one-archive (archive file)
f561e49a
CY
1020 "Retrieve an archive file FILE from ARCHIVE, and cache it.
1021ARCHIVE should be a cons cell of the form (NAME . LOCATION),
1022similar to an entry in `package-alist'. Save the cached copy to
1023\"archives/NAME/archive-contents\" in `package-user-dir'."
1024 (let* ((dir (expand-file-name "archives" package-user-dir))
1025 (dir (expand-file-name (car archive) dir)))
1026 (package--with-work-buffer (cdr archive) file
ebf662f4
CY
1027 ;; Read the retrieved buffer to make sure it is valid (e.g. it
1028 ;; may fetch a URL redirect page).
1029 (when (listp (read buffer))
1030 (make-directory dir t)
1031 (setq buffer-file-name (expand-file-name file dir))
1032 (let ((version-control 'never))
f561e49a 1033 (save-buffer))))))
44198b6e
CY
1034
1035(defun package-refresh-contents ()
1036 "Download the ELPA archive description if needed.
ebf662f4
CY
1037This informs Emacs about the latest versions of all packages, and
1038makes them available for download."
44198b6e
CY
1039 (interactive)
1040 (unless (file-exists-p package-user-dir)
1041 (make-directory package-user-dir t))
bc44bef7 1042 (dolist (archive package-archives)
cb6c4991
CY
1043 (condition-case nil
1044 (package--download-one-archive archive "archive-contents")
187d3296 1045 (error (message "Failed to download `%s' archive."
cb6c4991 1046 (car archive)))))
bc44bef7 1047 (package-read-all-archive-contents))
44198b6e 1048
4b99edf2
CY
1049(defvar package--initialized nil)
1050
44198b6e 1051;;;###autoload
4b99edf2 1052(defun package-initialize (&optional no-activate)
44198b6e 1053 "Load Emacs Lisp packages, and activate them.
4b99edf2
CY
1054The variable `package-load-list' controls which packages to load.
1055If optional arg NO-ACTIVATE is non-nil, don't activate packages."
44198b6e 1056 (interactive)
015eea59
CY
1057 (setq package-alist nil
1058 package-obsolete-alist nil)
44198b6e 1059 (package-load-all-descriptors)
bc44bef7 1060 (package-read-all-archive-contents)
4b99edf2
CY
1061 (unless no-activate
1062 (dolist (elt package-alist)
1063 (package-activate (car elt) (package-desc-vers (cdr elt)))))
1064 (setq package--initialized t))
44198b6e
CY
1065
1066\f
cced7584 1067;;;; Package description buffer.
44198b6e 1068
cced7584
CY
1069;;;###autoload
1070(defun describe-package (package)
1071 "Display the full documentation of PACKAGE (a symbol)."
1072 (interactive
8a500a91
CY
1073 (let* ((guess (function-called-at-point))
1074 packages val)
4b99edf2
CY
1075 (require 'finder-inf nil t)
1076 ;; Load the package list if necessary (but don't activate them).
1077 (unless package--initialized
1078 (package-initialize t))
8a500a91 1079 (setq packages (append (mapcar 'car package-alist)
4b99edf2
CY
1080 (mapcar 'car package-archive-contents)
1081 (mapcar 'car package--builtins)))
cced7584
CY
1082 (unless (memq guess packages)
1083 (setq guess nil))
1084 (setq packages (mapcar 'symbol-name packages))
1085 (setq val
1086 (completing-read (if guess
1087 (format "Describe package (default %s): "
1088 guess)
1089 "Describe package: ")
1090 packages nil t nil nil guess))
cb6c4991 1091 (list (if (equal val "") guess (intern val)))))
4b99edf2
CY
1092 (if (or (null package) (not (symbolp package)))
1093 (message "No package specified")
cced7584
CY
1094 (help-setup-xref (list #'describe-package package)
1095 (called-interactively-p 'interactive))
1096 (with-help-window (help-buffer)
1097 (with-current-buffer standard-output
1098 (describe-package-1 package)))))
1099
1100(defun describe-package-1 (package)
96ae4c8f 1101 (require 'lisp-mnt)
cb6c4991
CY
1102 (let ((package-name (symbol-name package))
1103 (built-in (assq package package--builtins))
1104 desc pkg-dir reqs version installable)
cced7584
CY
1105 (prin1 package)
1106 (princ " is ")
4b99edf2
CY
1107 (cond
1108 ;; Loaded packages are in `package-alist'.
1109 ((setq desc (cdr (assq package package-alist)))
1110 (setq version (package-version-join (package-desc-vers desc)))
1111 (if (setq pkg-dir (package--dir package-name version))
1112 (insert "an installed package.\n\n")
1113 ;; This normally does not happen.
1114 (insert "a deleted package.\n\n")))
1115 ;; Available packages are in `package-archive-contents'.
1116 ((setq desc (cdr (assq package package-archive-contents)))
1117 (setq version (package-version-join (package-desc-vers desc))
8adb4c33 1118 installable t)
4b99edf2
CY
1119 (if built-in
1120 (insert "a built-in package.\n\n")
1121 (insert "an uninstalled package.\n\n")))
1122 (built-in
1123 (setq desc (cdr built-in)
1124 version (package-version-join (package-desc-vers desc)))
1125 (insert "a built-in package.\n\n"))
1126 (t
1127 (insert "an orphan package.\n\n")))
cb6c4991 1128
96ae4c8f 1129 (insert " " (propertize "Status" 'font-lock-face 'bold) ": ")
cb6c4991 1130 (cond (pkg-dir
96ae4c8f
CY
1131 (insert (propertize "Installed"
1132 'font-lock-face 'font-lock-comment-face))
cb6c4991
CY
1133 (insert " in `")
1134 ;; Todo: Add button for uninstalling.
1135 (help-insert-xref-button (file-name-as-directory pkg-dir)
1136 'help-package-def pkg-dir)
4b99edf2
CY
1137 (if built-in
1138 (insert "',\n shadowing a "
1139 (propertize "built-in package"
1140 'font-lock-face 'font-lock-builtin-face)
1141 ".")
1142 (insert "'.")))
cb6c4991 1143 (installable
4b99edf2
CY
1144 (if built-in
1145 (insert (propertize "Built-in." 'font-lock-face 'font-lock-builtin-face)
1146 " Alternate version available -- ")
1147 (insert "Available -- "))
1148 (let ((button-text (if (display-graphic-p) "Install" "[Install]"))
cb6c4991
CY
1149 (button-face (if (display-graphic-p)
1150 '(:box (:line-width 2 :color "dark grey")
1151 :background "light grey"
1152 :foreground "black")
1153 'link)))
4b99edf2 1154 (insert-text-button button-text 'face button-face 'follow-link t
cb6c4991
CY
1155 'package-symbol package
1156 'action 'package-install-button-action)))
1157 (built-in
4b99edf2 1158 (insert (propertize "Built-in." 'font-lock-face 'font-lock-builtin-face)))
cb6c4991
CY
1159 (t (insert "Deleted.")))
1160 (insert "\n")
4b99edf2 1161 (and version (> (length version) 0)
96ae4c8f
CY
1162 (insert " "
1163 (propertize "Version" 'font-lock-face 'bold) ": " version "\n"))
4b99edf2
CY
1164
1165 (setq reqs (if desc (package-desc-reqs desc)))
8adb4c33 1166 (when reqs
96ae4c8f 1167 (insert " " (propertize "Requires" 'font-lock-face 'bold) ": ")
8adb4c33
CY
1168 (let ((first t)
1169 name vers text)
1170 (dolist (req reqs)
1171 (setq name (car req)
1172 vers (cadr req)
1173 text (format "%s-%s" (symbol-name name)
1174 (package-version-join vers)))
1175 (cond (first (setq first nil))
1176 ((>= (+ 2 (current-column) (length text))
1177 (window-width))
1178 (insert ",\n "))
1179 (t (insert ", ")))
1180 (help-insert-xref-button text 'help-package name))
1181 (insert "\n")))
96ae4c8f 1182 (insert " " (propertize "Summary" 'font-lock-face 'bold)
4b99edf2 1183 ": " (if desc (package-desc-doc desc)) "\n\n")
cb6c4991 1184
4b99edf2 1185 (if built-in
96ae4c8f
CY
1186 ;; For built-in packages, insert the commentary.
1187 (let ((fn (locate-file (concat package-name ".el") load-path
1188 load-file-rep-suffixes))
1189 (opoint (point)))
1190 (insert (or (lm-commentary fn) ""))
1191 (save-excursion
1192 (goto-char opoint)
1193 (when (re-search-forward "^;;; Commentary:\n" nil t)
1194 (replace-match ""))
1195 (while (re-search-forward "^\\(;+ ?\\)" nil t)
1196 (replace-match ""))))
1197 (let ((readme (expand-file-name (concat package-name "-readme.txt")
f561e49a
CY
1198 package-user-dir))
1199 readme-string)
96ae4c8f
CY
1200 ;; For elpa packages, try downloading the commentary. If that
1201 ;; fails, try an existing readme file in `package-user-dir'.
f561e49a
CY
1202 (cond ((condition-case nil
1203 (package--with-work-buffer (package-archive-base package)
1204 (concat package-name "-readme.txt")
1205 (setq buffer-file-name
1206 (expand-file-name readme package-user-dir))
1207 (let ((version-control 'never))
1208 (save-buffer))
1209 (setq readme-string (buffer-string))
1210 t)
1211 (error nil))
1212 (insert readme-string))
96ae4c8f
CY
1213 ((file-readable-p readme)
1214 (insert-file-contents readme)
1215 (goto-char (point-max))))))))
cb6c4991
CY
1216
1217(defun package-install-button-action (button)
1218 (let ((package (button-get button 'package-symbol)))
1219 (when (y-or-n-p (format "Install package `%s'? " package))
1220 (package-install package)
1221 (revert-buffer nil t)
1222 (goto-char (point-min)))))
cced7584
CY
1223
1224\f
44198b6e
CY
1225;;;; Package menu mode.
1226
54ea2a0d 1227(defvar package-menu-mode-map
abef340a 1228 (let ((map (copy-keymap special-mode-map))
64eba874 1229 (menu-map (make-sparse-keymap "Package")))
43207249 1230 (set-keymap-parent map button-buffer-map)
8adb4c33 1231 (define-key map "\C-m" 'package-menu-describe-package)
54ea2a0d
JB
1232 (define-key map "n" 'next-line)
1233 (define-key map "p" 'previous-line)
1234 (define-key map "u" 'package-menu-mark-unmark)
1235 (define-key map "\177" 'package-menu-backup-unmark)
1236 (define-key map "d" 'package-menu-mark-delete)
1237 (define-key map "i" 'package-menu-mark-install)
54ea2a0d
JB
1238 (define-key map "r" 'package-menu-refresh)
1239 (define-key map "~" 'package-menu-mark-obsolete-for-deletion)
1240 (define-key map "x" 'package-menu-execute)
1241 (define-key map "h" 'package-menu-quick-help)
cb6c4991 1242 (define-key map "?" 'package-menu-describe-package)
96ae4c8f
CY
1243 (define-key map [follow-link] 'mouse-face)
1244 (define-key map [mouse-2] 'mouse-select-window)
64eba874
DN
1245 (define-key map [menu-bar package-menu] (cons "Package" menu-map))
1246 (define-key menu-map [mq]
1247 '(menu-item "Quit" quit-window
1248 :help "Quit package selection"))
1249 (define-key menu-map [s1] '("--"))
1250 (define-key menu-map [mn]
1251 '(menu-item "Next" next-line
1252 :help "Next Line"))
1253 (define-key menu-map [mp]
1254 '(menu-item "Previous" previous-line
1255 :help "Previous Line"))
1256 (define-key menu-map [s2] '("--"))
1257 (define-key menu-map [mu]
1258 '(menu-item "Unmark" package-menu-mark-unmark
1259 :help "Clear any marks on a package and move to the next line"))
1260 (define-key menu-map [munm]
1261 '(menu-item "Unmark backwards" package-menu-backup-unmark
1262 :help "Back up one line and clear any marks on that package"))
1263 (define-key menu-map [md]
1264 '(menu-item "Mark for deletion" package-menu-mark-delete
1265 :help "Mark a package for deletion and move to the next line"))
1266 (define-key menu-map [mi]
1267 '(menu-item "Mark for install" package-menu-mark-install
1268 :help "Mark a package for installation and move to the next line"))
1269 (define-key menu-map [s3] '("--"))
1270 (define-key menu-map [mg]
e687c2cd 1271 '(menu-item "Update package list" revert-buffer
64eba874
DN
1272 :help "Update the list of packages"))
1273 (define-key menu-map [mr]
1274 '(menu-item "Refresh package list" package-menu-refresh
1275 :help "Download the ELPA archive"))
1276 (define-key menu-map [s4] '("--"))
1277 (define-key menu-map [mt]
1278 '(menu-item "Mark obsolete packages" package-menu-mark-obsolete-for-deletion
1279 :help "Mark all obsolete packages for deletion"))
1280 (define-key menu-map [mx]
1281 '(menu-item "Execute actions" package-menu-execute
1282 :help "Perform all the marked actions"))
1283 (define-key menu-map [s5] '("--"))
1284 (define-key menu-map [mh]
1285 '(menu-item "Help" package-menu-quick-help
1286 :help "Show short key binding help for package-menu-mode"))
1287 (define-key menu-map [mc]
1288 '(menu-item "View Commentary" package-menu-view-commentary
1289 :help "Display information about this package"))
54ea2a0d 1290 map)
44198b6e
CY
1291 "Local keymap for `package-menu-mode' buffers.")
1292
44198b6e
CY
1293(defvar package-menu-sort-button-map
1294 (let ((map (make-sparse-keymap)))
1295 (define-key map [header-line mouse-1] 'package-menu-sort-by-column)
96ae4c8f 1296 (define-key map [header-line mouse-2] 'package-menu-sort-by-column)
44198b6e
CY
1297 (define-key map [follow-link] 'mouse-face)
1298 map)
1299 "Local keymap for package menu sort buttons.")
1300
1301(put 'package-menu-mode 'mode-class 'special)
1302
abef340a 1303(define-derived-mode package-menu-mode special-mode "Package Menu"
44198b6e
CY
1304 "Major mode for browsing a list of packages.
1305Letters do not insert themselves; instead, they are commands.
1306\\<package-menu-mode-map>
1307\\{package-menu-mode-map}"
44198b6e
CY
1308 (setq truncate-lines t)
1309 (setq buffer-read-only t)
cd205c76 1310 (set (make-local-variable 'revert-buffer-function) 'package-menu-revert)
187d3296
CY
1311 (setq header-line-format
1312 (mapconcat
1313 (lambda (pair)
1314 (let ((column (car pair))
1315 (name (cdr pair)))
1316 (concat
1317 ;; Insert a space that aligns the button properly.
1318 (propertize " " 'display (list 'space :align-to column)
1319 'face 'fixed-pitch)
1320 ;; Set up the column button.
1321 (propertize name
1322 'column-name name
1323 'help-echo "mouse-1: sort by column"
1324 'mouse-face 'highlight
1325 'keymap package-menu-sort-button-map))))
1326 ;; We take a trick from buff-menu and have a dummy leading
1327 ;; space to align the header line with the beginning of the
1328 ;; text. This doesn't really work properly on Emacs 21, but
1329 ;; it is close enough.
1330 '((0 . "")
1331 (2 . "Package")
1332 (20 . "Version")
1333 (32 . "Status")
1334 (43 . "Description"))
abef340a 1335 "")))
44198b6e
CY
1336
1337(defun package-menu-refresh ()
ebf662f4
CY
1338 "Download the Emacs Lisp package archive.
1339This fetches the contents of each archive specified in
1340`package-archives', and then refreshes the package menu."
44198b6e 1341 (interactive)
187d3296
CY
1342 (unless (eq major-mode 'package-menu-mode)
1343 (error "The current buffer is not a Package Menu"))
44198b6e 1344 (package-refresh-contents)
96ae4c8f 1345 (package--generate-package-list))
44198b6e 1346
e687c2cd
CY
1347(defun package-menu-revert (&optional arg noconfirm)
1348 "Update the list of packages.
1349This function is the `revert-buffer-function' for Package Menu
1350buffers. The arguments are ignored."
44198b6e 1351 (interactive)
187d3296
CY
1352 (unless (eq major-mode 'package-menu-mode)
1353 (error "The current buffer is not a Package Menu"))
96ae4c8f 1354 (package--generate-package-list))
44198b6e 1355
8adb4c33
CY
1356(defun package-menu-describe-package ()
1357 "Describe the package in the current line."
1358 (interactive)
1359 (let ((name (package-menu-get-package)))
1360 (if name
1361 (describe-package (intern name))
1362 (message "No package on this line"))))
1363
44198b6e
CY
1364(defun package-menu-mark-internal (what)
1365 (unless (eobp)
1366 (let ((buffer-read-only nil))
1367 (beginning-of-line)
1368 (delete-char 1)
1369 (insert what)
1370 (forward-line))))
1371
1372;; fixme numeric argument
1373(defun package-menu-mark-delete (num)
1374 "Mark a package for deletion and move to the next line."
1375 (interactive "p")
015eea59
CY
1376 (if (string-equal (package-menu-get-status) "installed")
1377 (package-menu-mark-internal "D")
1378 (forward-line)))
44198b6e
CY
1379
1380(defun package-menu-mark-install (num)
1381 "Mark a package for installation and move to the next line."
1382 (interactive "p")
015eea59
CY
1383 (if (string-equal (package-menu-get-status) "available")
1384 (package-menu-mark-internal "I")
1385 (forward-line)))
44198b6e
CY
1386
1387(defun package-menu-mark-unmark (num)
1388 "Clear any marks on a package and move to the next line."
1389 (interactive "p")
1390 (package-menu-mark-internal " "))
1391
1392(defun package-menu-backup-unmark ()
1393 "Back up one line and clear any marks on that package."
1394 (interactive)
1395 (forward-line -1)
1396 (package-menu-mark-internal " ")
1397 (forward-line -1))
1398
1399(defun package-menu-mark-obsolete-for-deletion ()
1400 "Mark all obsolete packages for deletion."
1401 (interactive)
1402 (save-excursion
1403 (goto-char (point-min))
1404 (forward-line 2)
1405 (while (not (eobp))
1406 (if (looking-at ".*\\s obsolete\\s ")
1407 (package-menu-mark-internal "D")
1408 (forward-line 1)))))
1409
1410(defun package-menu-quick-help ()
1411 "Show short key binding help for package-menu-mode."
1412 (interactive)
1413 (message "n-ext, i-nstall, d-elete, u-nmark, x-ecute, r-efresh, h-elp"))
1414
cb6c4991
CY
1415(define-obsolete-function-alias
1416 'package-menu-view-commentary 'package-menu-describe-package "24.1")
44198b6e
CY
1417
1418;; Return the name of the package on the current line.
1419(defun package-menu-get-package ()
1420 (save-excursion
1421 (beginning-of-line)
1422 (if (looking-at ". \\([^ \t]*\\)")
8adb4c33 1423 (match-string-no-properties 1))))
44198b6e
CY
1424
1425;; Return the version of the package on the current line.
1426(defun package-menu-get-version ()
1427 (save-excursion
1428 (beginning-of-line)
1429 (if (looking-at ". [^ \t]*[ \t]*\\([0-9.]*\\)")
1430 (match-string 1))))
1431
1432(defun package-menu-get-status ()
1433 (save-excursion
1434 (if (looking-at ". [^ \t]*[ \t]*[^ \t]*[ \t]*\\([^ \t]*\\)")
1435 (match-string 1)
1436 "")))
1437
1438(defun package-menu-execute ()
015eea59
CY
1439 "Perform marked Package Menu actions.
1440Packages marked for installation are downloaded and installed;
1441packages marked for deletion are removed."
44198b6e 1442 (interactive)
015eea59
CY
1443 (let (install-list delete-list cmd)
1444 (save-excursion
1445 (goto-char (point-min))
1446 (while (not (eobp))
1447 (setq cmd (char-after))
1448 (cond
1449 ((eq cmd ?\s) t)
1450 ((eq cmd ?D)
1451 (push (cons (package-menu-get-package)
1452 (package-menu-get-version))
1453 delete-list))
1454 ((eq cmd ?I)
1455 (push (package-menu-get-package) install-list)))
1456 (forward-line)))
1457 ;; Delete packages, prompting if necessary.
1458 (when delete-list
1459 (if (yes-or-no-p
1460 (if (= (length delete-list) 1)
1461 (format "Delete package `%s-%s'? "
1462 (caar delete-list)
1463 (cdr (car delete-list)))
1464 (format "Delete these %d packages (%s)? "
1465 (length delete-list)
1466 (mapconcat (lambda (elt)
1467 (concat (car elt) "-" (cdr elt)))
1468 delete-list
1469 ", "))))
1470 (dolist (elt delete-list)
1471 (condition-case err
1472 (package-delete (car elt) (cdr elt))
1473 (error (message (cadr err)))))
1474 (error "Aborted")))
1475 (when install-list
1476 (if (yes-or-no-p
1477 (if (= (length install-list) 1)
1478 (format "Install package `%s'? " (car install-list))
1479 (format "Install these %d packages (%s)? "
1480 (length install-list)
1481 (mapconcat 'identity install-list ", "))))
1482 (dolist (elt install-list)
1483 (package-install (intern elt)))))
1484 ;; If we deleted anything, regenerate `package-alist'. This is done
1485 ;; automatically if we installed a package.
1486 (and delete-list (null install-list)
1487 (package-initialize))
1488 (if (or delete-list install-list)
1489 (package-menu-revert)
1490 (message "No operations specified."))))
44198b6e
CY
1491
1492(defun package-print-package (package version key desc)
1493 (let ((face
376c2b6b 1494 (cond ((string= key "built-in") 'font-lock-builtin-face)
44198b6e
CY
1495 ((string= key "available") 'default)
1496 ((string= key "held") 'font-lock-constant-face)
1497 ((string= key "disabled") 'font-lock-warning-face)
1498 ((string= key "installed") 'font-lock-comment-face)
1499 (t ; obsolete, but also the default.
1500 'font-lock-warning-face))))
1501 (insert (propertize " " 'font-lock-face face))
8adb4c33
CY
1502 (insert-text-button (symbol-name package)
1503 'face 'link
1504 'follow-link t
1505 'package-symbol package
1506 'action (lambda (button)
1507 (describe-package
1508 (button-get button 'package-symbol))))
44198b6e
CY
1509 (indent-to 20 1)
1510 (insert (propertize (package-version-join version) 'font-lock-face face))
8adb4c33 1511 (indent-to 32 1)
44198b6e
CY
1512 (insert (propertize key 'font-lock-face face))
1513 ;; FIXME: this 'when' is bogus...
1514 (when desc
8adb4c33 1515 (indent-to 43 1)
376c2b6b
CY
1516 (let ((opoint (point)))
1517 (insert (propertize desc 'font-lock-face face))
1518 (upcase-region opoint (min (point) (1+ opoint)))))
44198b6e
CY
1519 (insert "\n")))
1520
1521(defun package-list-maybe-add (package version status description result)
1522 (unless (assoc (cons package version) result)
ebf662f4 1523 (push (list (cons package version) status description) result))
44198b6e
CY
1524 result)
1525
187d3296
CY
1526(defvar package-menu-package-list nil
1527 "List of packages to display in the Package Menu buffer.
1528A value of nil means to display all packages.")
44198b6e 1529
187d3296
CY
1530(defvar package-menu-sort-key nil
1531 "Sort key for the current Package Menu buffer.")
1532
1533(defun package--generate-package-list ()
1534 "Populate the current Package Menu buffer."
187d3296
CY
1535 (let ((inhibit-read-only t)
1536 info-list name desc hold builtin)
44198b6e 1537 (erase-buffer)
187d3296
CY
1538 ;; List installed packages
1539 (dolist (elt package-alist)
1540 (setq name (car elt))
4b99edf2
CY
1541 (when (or (null package-menu-package-list)
1542 (memq name package-menu-package-list))
187d3296 1543 (setq desc (cdr elt)
4b99edf2 1544 hold (cadr (assq name package-load-list)))
187d3296
CY
1545 (setq info-list
1546 (package-list-maybe-add
1547 name (package-desc-vers desc)
1548 ;; FIXME: it turns out to be tricky to see if this
1549 ;; package is presently activated.
4b99edf2
CY
1550 (if (stringp hold) "held" "installed")
1551 (package-desc-doc desc)
1552 info-list))))
1553
1554 ;; List built-in packages
1555 (dolist (elt package--builtins)
1556 (setq name (car elt))
1557 (when (and (not (eq name 'emacs)) ; Hide the `emacs' package.
1558 (or (null package-menu-package-list)
1559 (memq name package-menu-package-list)))
1560 (setq desc (cdr elt))
1561 (setq info-list
1562 (package-list-maybe-add
1563 name (package-desc-vers desc)
1564 "built-in"
187d3296
CY
1565 (package-desc-doc desc)
1566 info-list))))
1567
1568 ;; List available and disabled packages
1569 (dolist (elt package-archive-contents)
1570 (setq name (car elt)
1571 desc (cdr elt)
1572 hold (assq name package-load-list))
1573 (when (or (null package-menu-package-list)
1574 (memq name package-menu-package-list))
1575 (setq info-list
1576 (package-list-maybe-add name
1577 (package-desc-vers desc)
1578 (if (and hold (null (cadr hold)))
1579 "disabled"
1580 "available")
1581 (package-desc-doc (cdr elt))
1582 info-list))))
1583 ;; List obsolete packages
1584 (mapc (lambda (elt)
1585 (mapc (lambda (inner-elt)
1586 (setq info-list
1587 (package-list-maybe-add (car elt)
1588 (package-desc-vers
1589 (cdr inner-elt))
1590 "obsolete"
1591 (package-desc-doc
1592 (cdr inner-elt))
1593 info-list)))
1594 (cdr elt)))
1595 package-obsolete-alist)
1596
1597 (setq info-list
1598 (sort info-list
1599 (cond ((string= package-menu-sort-key "Package")
1600 'package-menu--name-predicate)
1601 ((string= package-menu-sort-key "Version")
1602 'package-menu--version-predicate)
1603 ((string= package-menu-sort-key "Description")
1604 'package-menu--description-predicate)
1605 (t ; By default, sort by package status
1606 'package-menu--status-predicate))))
1607
1608 (dolist (elt info-list)
1609 (package-print-package (car (car elt))
1610 (cdr (car elt))
1611 (car (cdr elt))
1612 (car (cdr (cdr elt)))))
44198b6e 1613 (goto-char (point-min))
96ae4c8f 1614 (set-buffer-modified-p nil)
44198b6e
CY
1615 (current-buffer)))
1616
96ae4c8f 1617(defun package-menu--version-predicate (left right)
187d3296
CY
1618 (let ((vleft (or (cdr (car left)) '(0)))
1619 (vright (or (cdr (car right)) '(0))))
1620 (if (version-list-= vleft vright)
96ae4c8f 1621 (package-menu--name-predicate left right)
187d3296 1622 (version-list-< vleft vright))))
96ae4c8f
CY
1623
1624(defun package-menu--status-predicate (left right)
1625 (let ((sleft (cadr left))
1626 (sright (cadr right)))
1627 (cond ((string= sleft sright)
1628 (package-menu--name-predicate left right))
1629 ((string= sleft "available") t)
1630 ((string= sright "available") nil)
1631 ((string= sleft "installed") t)
1632 ((string= sright "installed") nil)
1633 ((string= sleft "held") t)
1634 ((string= sright "held") nil)
1635 ((string= sleft "built-in") t)
1636 ((string= sright "built-in") nil)
1637 ((string= sleft "obsolete") t)
1638 ((string= sright "obsolete") nil)
1639 (t (string< sleft sright)))))
1640
1641(defun package-menu--description-predicate (left right)
1642 (let ((sleft (car (cddr left)))
1643 (sright (car (cddr right))))
1644 (if (string= sleft sright)
1645 (package-menu--name-predicate left right)
1646 (string< sleft sright))))
1647
1648(defun package-menu--name-predicate (left right)
1649 (string< (symbol-name (caar left))
1650 (symbol-name (caar right))))
1651
44198b6e 1652(defun package-menu-sort-by-column (&optional e)
187d3296 1653 "Sort the package menu by the column of the mouse click E."
96ae4c8f 1654 (interactive "e")
44198b6e 1655 (let* ((pos (event-start e))
187d3296
CY
1656 (obj (posn-object pos))
1657 (col (if obj
1658 (get-text-property (cdr obj) 'column-name (car obj))
1659 (get-text-property (posn-point pos) 'column-name)))
1660 (buf (window-buffer (posn-window (event-start e)))))
1661 (with-current-buffer buf
1662 (when (eq major-mode 'package-menu-mode)
1663 (setq package-menu-sort-key col)
1664 (package--generate-package-list)))))
96ae4c8f
CY
1665
1666(defun package--list-packages (&optional packages)
187d3296
CY
1667 "Generate and pop to the *Packages* buffer.
1668Optional PACKAGES is a list of names of packages (symbols) to
1669list; the default is to display everything in `package-alist'."
4b99edf2 1670 (require 'finder-inf nil t)
2a8b13af
CY
1671 (let ((buf (get-buffer-create "*Packages*")))
1672 (with-current-buffer buf
abd20d91 1673 (package-menu-mode)
2a8b13af
CY
1674 (set (make-local-variable 'package-menu-package-list) packages)
1675 (set (make-local-variable 'package-menu-sort-key) nil)
abd20d91 1676 (package--generate-package-list))
2a8b13af
CY
1677 ;; The package menu buffer has keybindings. If the user types
1678 ;; `M-x list-packages', that suggests it should become current.
1679 (switch-to-buffer buf)))
44198b6e
CY
1680
1681;;;###autoload
96ae4c8f 1682(defun list-packages ()
44198b6e
CY
1683 "Display a list of packages.
1684Fetches the updated list of packages before displaying.
1685The list is displayed in a buffer named `*Packages*'."
1686 (interactive)
8a500a91 1687 ;; Initialize the package system if necessary.
4b99edf2
CY
1688 (unless package--initialized
1689 (package-initialize t))
44198b6e
CY
1690 (package-refresh-contents)
1691 (package--list-packages))
1692
cb8759ca 1693;;;###autoload
96ae4c8f 1694(defalias 'package-list-packages 'list-packages)
cb8759ca 1695
44198b6e
CY
1696(defun package-list-packages-no-fetch ()
1697 "Display a list of packages.
1698Does not fetch the updated list of packages before displaying.
1699The list is displayed in a buffer named `*Packages*'."
1700 (interactive)
1701 (package--list-packages))
1702
44198b6e
CY
1703(provide 'package)
1704
1705;;; package.el ends here