* lisp/emacs-lisp/package.el: Improve transaction y-or-n prompt
[emacs.git] / lisp / emacs-lisp / package.el
blob6fb5ba45468a84655a70039f4a542443dc122564
1 ;;; package.el --- Simple package system for Emacs -*- lexical-binding:t -*-
3 ;; Copyright (C) 2007-2015 Free Software Foundation, Inc.
5 ;; Author: Tom Tromey <tromey@redhat.com>
6 ;; Daniel Hackney <dan@haxney.org>
7 ;; Created: 10 Mar 2007
8 ;; Version: 1.0.1
9 ;; Keywords: tools
10 ;; Package-Requires: ((tabulated-list "1.0"))
12 ;; This file is part of GNU Emacs.
14 ;; GNU Emacs is free software: you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation, either version 3 of the License, or
17 ;; (at your option) any later version.
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
27 ;;; Change Log:
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
35 ;;; Commentary:
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.)
46 ;; A package is described by its name and version. The distribution
47 ;; format is either a tar file or a single .el file.
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.
55 ;; A .el file is named "NAME-VERSION.el" in the remote archive, but is
56 ;; installed as simply "NAME.el" in a directory named "NAME-VERSION".
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.
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.
67 ;; Conceptually a package has multiple state transitions:
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.
78 ;; Other external functions you may want to use:
80 ;; M-x list-packages
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.
87 ;; M-x package-install-from-buffer
88 ;; Install a package consisting of a single .el file that appears
89 ;; in the current buffer. This only works for packages which
90 ;; define a Version header properly; package.el also supports the
91 ;; extension headers Package-Version (in case Version is an RCS id
92 ;; or similar), and Package-Requires (if the package requires other
93 ;; packages).
95 ;; M-x package-install-file
96 ;; Install a package from the indicated file. The package can be
97 ;; either a tar file or a .el file. A tar file must contain an
98 ;; appropriately-named "-pkg.el" file; a .el file must be properly
99 ;; formatted as with package-install-from-buffer.
101 ;;; Thanks:
102 ;;; (sorted by sort-lines):
104 ;; Jim Blandy <jimb@red-bean.com>
105 ;; Karl Fogel <kfogel@red-bean.com>
106 ;; Kevin Ryde <user42@zip.com.au>
107 ;; Lawrence Mitchell
108 ;; Michael Olson <mwolson@member.fsf.org>
109 ;; Sebastian Tennant <sebyte@smolny.plus.com>
110 ;; Stefan Monnier <monnier@iro.umontreal.ca>
111 ;; Vinicius Jose Latorre <viniciusjl@ig.com.br>
112 ;; Phil Hagelberg <phil@hagelb.org>
114 ;;; ToDo:
116 ;; - putting info dirs at the start of the info path means
117 ;; users see a weird ordering of categories. OTOH we want to
118 ;; override later entries. maybe emacs needs to enforce
119 ;; the standard layout?
120 ;; - put bytecode in a separate directory tree
121 ;; - perhaps give users a way to recompile their bytecode
122 ;; or do it automatically when emacs changes
123 ;; - give users a way to know whether a package is installed ok
124 ;; - give users a way to view a package's documentation when it
125 ;; only appears in the .el
126 ;; - use/extend checkdoc so people can tell if their package will work
127 ;; - "installed" instead of a blank in the status column
128 ;; - tramp needs its files to be compiled in a certain order.
129 ;; how to handle this? fix tramp?
130 ;; - on emacs 21 we don't kill the -autoloads.el buffer. what about 22?
131 ;; - maybe we need separate .elc directories for various emacs versions
132 ;; and also emacs-vs-xemacs. That way conditional compilation can
133 ;; work. But would this break anything?
134 ;; - should store the package's keywords in archive-contents, then
135 ;; let the users filter the package-menu by keyword. See
136 ;; finder-by-keyword. (We could also let people view the
137 ;; Commentary, but it isn't clear how useful this is.)
138 ;; - William Xu suggests being able to open a package file without
139 ;; installing it
140 ;; - Interface with desktop.el so that restarting after an install
141 ;; works properly
142 ;; - Use hierarchical layout. PKG/etc PKG/lisp PKG/info
143 ;; ... except maybe lisp?
144 ;; - It may be nice to have a macro that expands to the package's
145 ;; private data dir, aka ".../etc". Or, maybe data-directory
146 ;; needs to be a list (though this would be less nice)
147 ;; a few packages want this, eg sokoban
148 ;; - package menu needs:
149 ;; ability to know which packages are built-in & thus not deletable
150 ;; it can sometimes print odd results, like 0.3 available but 0.4 active
151 ;; why is that?
152 ;; - Allow multiple versions on the server...?
153 ;; [ why bother? ]
154 ;; - Don't install a package which will invalidate dependencies overall
155 ;; - Allow something like (or (>= emacs 21.0) (>= xemacs 21.5))
156 ;; [ currently thinking, why bother.. KISS ]
157 ;; - Allow optional package dependencies
158 ;; then if we require 'bbdb', bbdb-specific lisp in lisp/bbdb
159 ;; and just don't compile to add to load path ...?
160 ;; - Our treatment of the info path is somewhat bogus
162 ;;; Code:
164 (eval-when-compile (require 'subr-x))
165 (eval-when-compile (require 'cl-lib))
166 (eval-when-compile (require 'epg)) ;For setf accessors.
168 (require 'tabulated-list)
169 (require 'macroexp)
171 (defgroup package nil
172 "Manager for Emacs Lisp packages."
173 :group 'applications
174 :version "24.1")
177 ;;; Customization options
178 ;;;###autoload
179 (defcustom package-enable-at-startup t
180 "Whether to activate installed packages when Emacs starts.
181 If non-nil, packages are activated after reading the init file
182 and before `after-init-hook'. Activation is not done if
183 `user-init-file' is nil (e.g. Emacs was started with \"-q\").
185 Even if the value is nil, you can type \\[package-initialize] to
186 activate the package system at any time."
187 :type 'boolean
188 :group 'package
189 :version "24.1")
191 (defcustom package-load-list '(all)
192 "List of packages for `package-initialize' to load.
193 Each element in this list should be a list (NAME VERSION), or the
194 symbol `all'. The symbol `all' says to load the latest installed
195 versions of all packages not specified by other elements.
197 For an element (NAME VERSION), NAME is a package name (a symbol).
198 VERSION should be t, a string, or nil.
199 If VERSION is t, the most recent version is activated.
200 If VERSION is a string, only that version is ever loaded.
201 Any other version, even if newer, is silently ignored.
202 Hence, the package is \"held\" at that version.
203 If VERSION is nil, the package is not loaded (it is \"disabled\")."
204 :type '(repeat symbol)
205 :risky t
206 :group 'package
207 :version "24.1")
209 (defcustom package-archives '(("gnu" . "http://elpa.gnu.org/packages/"))
210 "An alist of archives from which to fetch.
211 The default value points to the GNU Emacs package repository.
213 Each element has the form (ID . LOCATION).
214 ID is an archive name, as a string.
215 LOCATION specifies the base location for the archive.
216 If it starts with \"http:\", it is treated as a HTTP URL;
217 otherwise it should be an absolute directory name.
218 (Other types of URL are currently not supported.)
220 Only add locations that you trust, since fetching and installing
221 a package can run arbitrary code."
222 :type '(alist :key-type (string :tag "Archive name")
223 :value-type (string :tag "URL or directory name"))
224 :risky t
225 :group 'package
226 :version "24.1")
228 (defcustom package-archive-priorities nil
229 "An alist of priorities for packages.
231 Each element has the form (ARCHIVE-ID . PRIORITY).
233 When installing packages, the package with the highest version
234 number from the archive with the highest priority is
235 selected. When higher versions are available from archives with
236 lower priorities, the user has to select those manually.
238 Archives not in this list have the priority 0."
239 :type '(alist :key-type (string :tag "Archive name")
240 :value-type (integer :tag "Priority (default is 0)"))
241 :risky t
242 :group 'package
243 :version "25.1")
245 (defcustom package-pinned-packages nil
246 "An alist of packages that are pinned to specific archives.
247 This can be useful if you have multiple package archives enabled,
248 and want to control which archive a given package gets installed from.
250 Each element of the alist has the form (PACKAGE . ARCHIVE), where:
251 PACKAGE is a symbol representing a package
252 ARCHIVE is a string representing an archive (it should be the car of
253 an element in `package-archives', e.g. \"gnu\").
255 Adding an entry to this variable means that only ARCHIVE will be
256 considered as a source for PACKAGE. If other archives provide PACKAGE,
257 they are ignored (for this package). If ARCHIVE does not contain PACKAGE,
258 the package will be unavailable."
259 :type '(alist :key-type (symbol :tag "Package")
260 :value-type (string :tag "Archive name"))
261 ;; I don't really see why this is risky...
262 ;; I suppose it could prevent you receiving updates for a package,
263 ;; via an entry (PACKAGE . NON-EXISTING). Which could be an issue
264 ;; if PACKAGE has a known vulnerability that is fixed in newer versions.
265 :risky t
266 :group 'package
267 :version "24.4")
269 (defcustom package-user-dir (locate-user-emacs-file "elpa")
270 "Directory containing the user's Emacs Lisp packages.
271 The directory name should be absolute.
272 Apart from this directory, Emacs also looks for system-wide
273 packages in `package-directory-list'."
274 :type 'directory
275 :risky t
276 :group 'package
277 :version "24.1")
279 (defcustom package-directory-list
280 ;; Defaults are subdirs named "elpa" in the site-lisp dirs.
281 (let (result)
282 (dolist (f load-path)
283 (and (stringp f)
284 (equal (file-name-nondirectory f) "site-lisp")
285 (push (expand-file-name "elpa" f) result)))
286 (nreverse result))
287 "List of additional directories containing Emacs Lisp packages.
288 Each directory name should be absolute.
290 These directories contain packages intended for system-wide; in
291 contrast, `package-user-dir' contains packages for personal use."
292 :type '(repeat directory)
293 :risky t
294 :group 'package
295 :version "24.1")
297 (defvar epg-gpg-program)
299 (defcustom package-check-signature
300 (if (progn (require 'epg-config) (executable-find epg-gpg-program))
301 'allow-unsigned)
302 "Non-nil means to check package signatures when installing.
303 The value `allow-unsigned' means to still install a package even if
304 it is unsigned.
306 This also applies to the \"archive-contents\" file that lists the
307 contents of the archive."
308 :type '(choice (const nil :tag "Never")
309 (const allow-unsigned :tag "Allow unsigned")
310 (const t :tag "Check always"))
311 :risky t
312 :group 'package
313 :version "24.4")
315 (defcustom package-unsigned-archives nil
316 "List of archives where we do not check for package signatures."
317 :type '(repeat (string :tag "Archive name"))
318 :risky t
319 :group 'package
320 :version "24.4")
322 (defcustom package-selected-packages nil
323 "Store here packages installed explicitly by user.
324 This variable is fed automatically by Emacs when installing a new package.
325 This variable is used by `package-autoremove' to decide
326 which packages are no longer needed.
327 You can use it to (re)install packages on other machines
328 by running `package-user-selected-packages-install'.
330 To check if a package is contained in this list here, use
331 `package--user-selected-p', as it may populate the variable with
332 a sane initial value."
333 :group 'package
334 :type '(repeat symbol))
337 ;;; `package-desc' object definition
338 ;; This is the struct used internally to represent packages.
339 ;; Functions that deal with packages should generally take this object
340 ;; as an argument. In some situations (e.g. commands that query the
341 ;; user) it makes sense to take the package name as a symbol instead,
342 ;; but keep in mind there could be multiple `package-desc's with the
343 ;; same name.
344 (defvar package--default-summary "No description available.")
346 (cl-defstruct (package-desc
347 ;; Rename the default constructor from `make-package-desc'.
348 (:constructor package-desc-create)
349 ;; Has the same interface as the old `define-package',
350 ;; which is still used in the "foo-pkg.el" files. Extra
351 ;; options can be supported by adding additional keys.
352 (:constructor
353 package-desc-from-define
354 (name-string version-string &optional summary requirements
355 &rest rest-plist
356 &aux
357 (name (intern name-string))
358 (version (version-to-list version-string))
359 (reqs (mapcar #'(lambda (elt)
360 (list (car elt)
361 (version-to-list (cadr elt))))
362 (if (eq 'quote (car requirements))
363 (nth 1 requirements)
364 requirements)))
365 (kind (plist-get rest-plist :kind))
366 (archive (plist-get rest-plist :archive))
367 (extras (let (alist)
368 (while rest-plist
369 (unless (memq (car rest-plist) '(:kind :archive))
370 (let ((value (cadr rest-plist)))
371 (when value
372 (push (cons (car rest-plist)
373 (if (eq (car-safe value) 'quote)
374 (cadr value)
375 value))
376 alist))))
377 (setq rest-plist (cddr rest-plist)))
378 alist)))))
379 "Structure containing information about an individual package.
380 Slots:
382 `name' Name of the package, as a symbol.
384 `version' Version of the package, as a version list.
386 `summary' Short description of the package, typically taken from
387 the first line of the file.
389 `reqs' Requirements of the package. A list of (PACKAGE
390 VERSION-LIST) naming the dependent package and the minimum
391 required version.
393 `kind' The distribution format of the package. Currently, it is
394 either `single' or `tar'.
396 `archive' The name of the archive (as a string) whence this
397 package came.
399 `dir' The directory where the package is installed (if installed),
400 `builtin' if it is built-in, or nil otherwise.
402 `extras' Optional alist of additional keyword-value pairs.
404 `signed' Flag to indicate that the package is signed by provider."
405 name
406 version
407 (summary package--default-summary)
408 reqs
409 kind
410 archive
412 extras
413 signed)
415 (defun package--from-builtin (bi-desc)
416 (package-desc-create :name (pop bi-desc)
417 :version (package--bi-desc-version bi-desc)
418 :summary (package--bi-desc-summary bi-desc)
419 :dir 'builtin))
421 ;; Pseudo fields.
422 (defun package-version-join (vlist)
423 "Return the version string corresponding to the list VLIST.
424 This is, approximately, the inverse of `version-to-list'.
425 \(Actually, it returns only one of the possible inverses, since
426 `version-to-list' is a many-to-one operation.)"
427 (if (null vlist)
429 (let ((str-list (list "." (int-to-string (car vlist)))))
430 (dolist (num (cdr vlist))
431 (cond
432 ((>= num 0)
433 (push (int-to-string num) str-list)
434 (push "." str-list))
435 ((< num -4)
436 (error "Invalid version list `%s'" vlist))
438 ;; pre, or beta, or alpha
439 (cond ((equal "." (car str-list))
440 (pop str-list))
441 ((not (string-match "[0-9]+" (car str-list)))
442 (error "Invalid version list `%s'" vlist)))
443 (push (cond ((= num -1) "pre")
444 ((= num -2) "beta")
445 ((= num -3) "alpha")
446 ((= num -4) "snapshot"))
447 str-list))))
448 (if (equal "." (car str-list))
449 (pop str-list))
450 (apply 'concat (nreverse str-list)))))
452 (defun package-desc-full-name (pkg-desc)
453 (format "%s-%s"
454 (package-desc-name pkg-desc)
455 (package-version-join (package-desc-version pkg-desc))))
457 (defun package-desc-suffix (pkg-desc)
458 (pcase (package-desc-kind pkg-desc)
459 (`single ".el")
460 (`tar ".tar")
461 (`dir "")
462 (kind (error "Unknown package kind: %s" kind))))
464 (defun package-desc--keywords (pkg-desc)
465 (let ((keywords (cdr (assoc :keywords (package-desc-extras pkg-desc)))))
466 (if (eq (car-safe keywords) 'quote)
467 (nth 1 keywords)
468 keywords)))
470 ;; Package descriptor format used in finder-inf.el and package--builtins.
471 (cl-defstruct (package--bi-desc
472 (:constructor package-make-builtin (version summary))
473 (:type vector))
474 version
475 reqs
476 summary)
479 ;;; Installed packages
480 ;; The following variables store information about packages present in
481 ;; the system. The most important of these is `package-alist'. The
482 ;; command `package-initialize' is also closely related to this
483 ;; section, but it is left for a later section because it also affects
484 ;; other stuff.
485 (defvar package--builtins nil
486 "Alist of built-in packages.
487 The actual value is initialized by loading the library
488 `finder-inf'; this is not done until it is needed, e.g. by the
489 function `package-built-in-p'.
491 Each element has the form (PKG . PACKAGE-BI-DESC), where PKG is a package
492 name (a symbol) and DESC is a `package--bi-desc' structure.")
493 (put 'package--builtins 'risky-local-variable t)
495 (defvar package-alist nil
496 "Alist of all packages available for activation.
497 Each element has the form (PKG . DESCS), where PKG is a package
498 name (a symbol) and DESCS is a non-empty list of `package-desc' structure,
499 sorted by decreasing versions.
501 This variable is set automatically by `package-load-descriptor',
502 called via `package-initialize'. To change which packages are
503 loaded and/or activated, customize `package-load-list'.")
504 (put 'package-alist 'risky-local-variable t)
506 (defvar package-activated-list nil
507 ;; FIXME: This should implicitly include all builtin packages.
508 "List of the names of currently activated packages.")
509 (put 'package-activated-list 'risky-local-variable t)
511 ;;;; Populating `package-alist'.
512 ;; The following functions are called on each installed package by
513 ;; `package-load-all-descriptors', which ultimately populates the
514 ;; `package-alist' variable.
515 (defun package-process-define-package (exp)
516 (when (eq (car-safe exp) 'define-package)
517 (let* ((new-pkg-desc (apply #'package-desc-from-define (cdr exp)))
518 (name (package-desc-name new-pkg-desc))
519 (version (package-desc-version new-pkg-desc))
520 (old-pkgs (assq name package-alist)))
521 (if (null old-pkgs)
522 ;; If there's no old package, just add this to `package-alist'.
523 (push (list name new-pkg-desc) package-alist)
524 ;; If there is, insert the new package at the right place in the list.
525 (while
526 (if (and (cdr old-pkgs)
527 (version-list-< version
528 (package-desc-version (cadr old-pkgs))))
529 (setq old-pkgs (cdr old-pkgs))
530 (push new-pkg-desc (cdr old-pkgs))
531 nil)))
532 new-pkg-desc)))
534 (defun package-load-descriptor (pkg-dir)
535 "Load the description file in directory PKG-DIR."
536 (let ((pkg-file (expand-file-name (package--description-file pkg-dir)
537 pkg-dir))
538 (signed-file (concat pkg-dir ".signed")))
539 (when (file-exists-p pkg-file)
540 (with-temp-buffer
541 (insert-file-contents pkg-file)
542 (goto-char (point-min))
543 (let ((pkg-desc (or (package-process-define-package
544 (read (current-buffer)))
545 (error "Can't find define-package in %s" pkg-file))))
546 (setf (package-desc-dir pkg-desc) pkg-dir)
547 (if (file-exists-p signed-file)
548 (setf (package-desc-signed pkg-desc) t))
549 pkg-desc)))))
551 (defun package-load-all-descriptors ()
552 "Load descriptors for installed Emacs Lisp packages.
553 This looks for package subdirectories in `package-user-dir' and
554 `package-directory-list'. The variable `package-load-list'
555 controls which package subdirectories may be loaded.
557 In each valid package subdirectory, this function loads the
558 description file containing a call to `define-package', which
559 updates `package-alist'."
560 (dolist (dir (cons package-user-dir package-directory-list))
561 (when (file-directory-p dir)
562 (dolist (subdir (directory-files dir))
563 (let ((pkg-dir (expand-file-name subdir dir)))
564 (when (file-directory-p pkg-dir)
565 (package-load-descriptor pkg-dir)))))))
567 (defun define-package (_name-string _version-string
568 &optional _docstring _requirements
569 &rest _extra-properties)
570 "Define a new package.
571 NAME-STRING is the name of the package, as a string.
572 VERSION-STRING is the version of the package, as a string.
573 DOCSTRING is a short description of the package, a string.
574 REQUIREMENTS is a list of dependencies on other packages.
575 Each requirement is of the form (OTHER-PACKAGE OTHER-VERSION),
576 where OTHER-VERSION is a string.
578 EXTRA-PROPERTIES is currently unused."
579 ;; FIXME: Placeholder! Should we keep it?
580 (error "Don't call me!"))
583 ;;; Package activation
584 ;; Section for functions used by `package-activate', which see.
585 (defun package-disabled-p (pkg-name version)
586 "Return whether PKG-NAME at VERSION can be activated.
587 The decision is made according to `package-load-list'.
588 Return nil if the package can be activated.
589 Return t if the package is completely disabled.
590 Return the max version (as a string) if the package is held at a lower version."
591 (let ((force (assq pkg-name package-load-list)))
592 (cond ((null force) (not (memq 'all package-load-list)))
593 ((null (setq force (cadr force))) t) ; disabled
594 ((eq force t) nil)
595 ((stringp force) ; held
596 (unless (version-list-= version (version-to-list force))
597 force))
598 (t (error "Invalid element in `package-load-list'")))))
600 (defun package-built-in-p (package &optional min-version)
601 "Return true if PACKAGE is built-in to Emacs.
602 Optional arg MIN-VERSION, if non-nil, should be a version list
603 specifying the minimum acceptable version."
604 (if (package-desc-p package) ;; was built-in and then was converted
605 (eq 'builtin (package-desc-dir package))
606 (let ((bi (assq package package--builtin-versions)))
607 (cond
608 (bi (version-list-<= min-version (cdr bi)))
609 ((remove 0 min-version) nil)
611 (require 'finder-inf nil t) ; For `package--builtins'.
612 (assq package package--builtins))))))
614 (defvar Info-directory-list)
615 (declare-function info-initialize "info" ())
617 (defun package-activate-1 (pkg-desc &optional reload)
618 "Activate package given by PKG-DESC, even if it was already active.
619 If RELOAD is non-nil, also `load' any files inside the package which
620 correspond to previously loaded files (those returned by
621 `package--list-loaded-files')."
622 (let* ((name (package-desc-name pkg-desc))
623 (pkg-dir (package-desc-dir pkg-desc))
624 (pkg-dir-dir (file-name-as-directory pkg-dir)))
625 (unless pkg-dir
626 (error "Internal error: unable to find directory for `%s'"
627 (package-desc-full-name pkg-desc)))
628 ;; Add to load path, add autoloads, and activate the package.
629 (let* ((old-lp load-path)
630 (autoloads-file (expand-file-name
631 (format "%s-autoloads" name) pkg-dir))
632 (loaded-files-list (and reload (package--list-loaded-files pkg-dir))))
633 (with-demoted-errors "Error in package-activate-1: %s"
634 (load autoloads-file nil t))
635 (when (and (eq old-lp load-path)
636 (not (or (member pkg-dir load-path)
637 (member pkg-dir-dir load-path))))
638 ;; Old packages don't add themselves to the `load-path', so we have to
639 ;; do it ourselves.
640 (push pkg-dir load-path))
641 ;; Call `load' on all files in `pkg-dir' already present in
642 ;; `load-history'. This is done so that macros in these files are updated
643 ;; to their new definitions. If another package is being installed which
644 ;; depends on this new definition, not doing this update would cause
645 ;; compilation errors and break the installation.
646 (with-demoted-errors "Error in package-activate-1: %s"
647 (mapc (lambda (feature) (load feature nil t))
648 ;; Skip autoloads file since we already evaluated it above.
649 (remove (file-truename autoloads-file) loaded-files-list))))
650 ;; Add info node.
651 (when (file-exists-p (expand-file-name "dir" pkg-dir))
652 ;; FIXME: not the friendliest, but simple.
653 (require 'info)
654 (info-initialize)
655 (push pkg-dir Info-directory-list))
656 (push name package-activated-list)
657 ;; Don't return nil.
660 (declare-function find-library-name "find-func" (library))
662 (defun package--list-loaded-files (dir)
663 "Recursively list all files in DIR which correspond to loaded features.
664 Returns the `file-name-sans-extension' of each file, relative to
665 DIR, sorted by most recently loaded last."
666 (let* ((history (delq nil
667 (mapcar (lambda (x)
668 (let ((f (car x)))
669 (and f (file-name-sans-extension f))))
670 load-history)))
671 (dir (file-truename dir))
672 ;; List all files that have already been loaded.
673 (list-of-conflicts
674 (delq
676 (mapcar
677 (lambda (x) (let* ((file (file-relative-name x dir))
678 ;; Previously loaded file, if any.
679 (previous
680 (ignore-errors
681 (file-name-sans-extension
682 (file-truename (find-library-name file)))))
683 (pos (when previous (member previous history))))
684 ;; Return (RELATIVE-FILENAME . HISTORY-POSITION)
685 (when pos
686 (cons (file-name-sans-extension file) (length pos)))))
687 (directory-files-recursively dir "\\`[^\\.].*\\.el\\'")))))
688 ;; Turn the list of (FILENAME . POS) back into a list of features. Files in
689 ;; subdirectories are returned relative to DIR (so not actually features).
690 (let ((default-directory (file-name-as-directory dir)))
691 (mapcar (lambda (x) (file-truename (car x)))
692 (sort list-of-conflicts
693 ;; Sort the files by ascending HISTORY-POSITION.
694 (lambda (x y) (< (cdr x) (cdr y))))))))
696 ;;;; `package-activate'
697 ;; This function activates a newer version of a package if an older
698 ;; one was already activated. It also loads a features of this
699 ;; package which were already loaded.
700 (defun package-activate (package &optional force)
701 "Activate package PACKAGE.
702 If FORCE is true, (re-)activate it if it's already activated.
703 Newer versions are always activated, regardless of FORCE."
704 (let ((pkg-descs (cdr (assq package package-alist))))
705 ;; Check if PACKAGE is available in `package-alist'.
706 (while
707 (when pkg-descs
708 (let ((available-version (package-desc-version (car pkg-descs))))
709 (or (package-disabled-p package available-version)
710 ;; Prefer a builtin package.
711 (package-built-in-p package available-version))))
712 (setq pkg-descs (cdr pkg-descs)))
713 (cond
714 ;; If no such package is found, maybe it's built-in.
715 ((null pkg-descs)
716 (package-built-in-p package))
717 ;; If the package is already activated, just return t.
718 ((and (memq package package-activated-list) (not force))
720 ;; Otherwise, proceed with activation.
722 (let* ((pkg-vec (car pkg-descs))
723 (fail (catch 'dep-failure
724 ;; Activate its dependencies recursively.
725 (dolist (req (package-desc-reqs pkg-vec))
726 (unless (package-activate (car req))
727 (throw 'dep-failure req))))))
728 (if fail
729 (warn "Unable to activate package `%s'.
730 Required package `%s-%s' is unavailable"
731 package (car fail) (package-version-join (cadr fail)))
732 ;; If all goes well, activate the package itself.
733 (package-activate-1 pkg-vec force)))))))
736 ;;; Installation -- Local operations
737 ;; This section contains a variety of features regarding installing a
738 ;; package to/from disk. This includes autoload generation,
739 ;; unpacking, compiling, as well as defining a package from the
740 ;; current buffer.
742 ;;;; Unpacking
743 (defvar tar-parse-info)
744 (declare-function tar-untar-buffer "tar-mode" ())
745 (declare-function tar-header-name "tar-mode" (tar-header) t)
746 (declare-function tar-header-link-type "tar-mode" (tar-header) t)
748 (defun package-untar-buffer (dir)
749 "Untar the current buffer.
750 This uses `tar-untar-buffer' from Tar mode. All files should
751 untar into a directory named DIR; otherwise, signal an error."
752 (require 'tar-mode)
753 (tar-mode)
754 ;; Make sure everything extracts into DIR.
755 (let ((regexp (concat "\\`" (regexp-quote (expand-file-name dir)) "/"))
756 (case-fold-search (memq system-type '(windows-nt ms-dos cygwin))))
757 (dolist (tar-data tar-parse-info)
758 (let ((name (expand-file-name (tar-header-name tar-data))))
759 (or (string-match regexp name)
760 ;; Tarballs created by some utilities don't list
761 ;; directories with a trailing slash (Bug#13136).
762 (and (string-equal dir name)
763 (eq (tar-header-link-type tar-data) 5))
764 (error "Package does not untar cleanly into directory %s/" dir)))))
765 (tar-untar-buffer))
767 (defun package--alist-to-plist-args (alist)
768 (mapcar 'macroexp-quote
769 (apply #'nconc
770 (mapcar (lambda (pair) (list (car pair) (cdr pair))) alist))))
771 (defun package-unpack (pkg-desc)
772 "Install the contents of the current buffer as a package."
773 (let* ((name (package-desc-name pkg-desc))
774 (dirname (package-desc-full-name pkg-desc))
775 (pkg-dir (expand-file-name dirname package-user-dir)))
776 (pcase (package-desc-kind pkg-desc)
777 (`dir
778 (make-directory pkg-dir t)
779 (let ((file-list
780 (directory-files
781 default-directory 'full "\\`[^.].*\\.el\\'" 'nosort)))
782 (dolist (source-file file-list)
783 (let ((target-el-file
784 (expand-file-name (file-name-nondirectory source-file) pkg-dir)))
785 (copy-file source-file target-el-file t)))
786 ;; Now that the files have been installed, this package is
787 ;; indistinguishable from a `tar' or a `single'. Let's make
788 ;; things simple by ensuring we're one of them.
789 (setf (package-desc-kind pkg-desc)
790 (if (> (length file-list) 1) 'tar 'single))))
791 (`tar
792 (make-directory package-user-dir t)
793 ;; FIXME: should we delete PKG-DIR if it exists?
794 (let* ((default-directory (file-name-as-directory package-user-dir)))
795 (package-untar-buffer dirname)))
796 (`single
797 (let ((el-file (expand-file-name (format "%s.el" name) pkg-dir)))
798 (make-directory pkg-dir t)
799 (package--write-file-no-coding el-file)))
800 (kind (error "Unknown package kind: %S" kind)))
801 (package--make-autoloads-and-stuff pkg-desc pkg-dir)
802 ;; Update package-alist.
803 (let ((new-desc (package-load-descriptor pkg-dir)))
804 ;; FIXME: Check that `new-desc' matches `desc'!
805 ;; FIXME: Compilation should be done as a separate, optional, step.
806 ;; E.g. for multi-package installs, we should first install all packages
807 ;; and then compile them.
808 (package--compile new-desc))
809 ;; Try to activate it.
810 (package-activate name 'force)
811 pkg-dir))
813 (defun package-generate-description-file (pkg-desc pkg-file)
814 "Create the foo-pkg.el file for single-file packages."
815 (let* ((name (package-desc-name pkg-desc)))
816 (let ((print-level nil)
817 (print-quoted t)
818 (print-length nil))
819 (write-region
820 (concat
821 ";;; -*- no-byte-compile: t -*-\n"
822 (prin1-to-string
823 (nconc
824 (list 'define-package
825 (symbol-name name)
826 (package-version-join (package-desc-version pkg-desc))
827 (package-desc-summary pkg-desc)
828 (let ((requires (package-desc-reqs pkg-desc)))
829 (list 'quote
830 ;; Turn version lists into string form.
831 (mapcar
832 (lambda (elt)
833 (list (car elt)
834 (package-version-join (cadr elt))))
835 requires))))
836 (package--alist-to-plist-args
837 (package-desc-extras pkg-desc))))
838 "\n")
839 nil pkg-file nil 'silent))))
841 ;;;; Autoload
842 ;; From Emacs 22, but changed so it adds to load-path.
843 (defun package-autoload-ensure-default-file (file)
844 "Make sure that the autoload file FILE exists and if not create it."
845 (unless (file-exists-p file)
846 (write-region
847 (concat ";;; " (file-name-nondirectory file)
848 " --- automatically extracted autoloads\n"
849 ";;\n"
850 ";;; Code:\n"
851 "(add-to-list 'load-path (or (file-name-directory #$) (car load-path)))\n"
852 "\f\n;; Local Variables:\n"
853 ";; version-control: never\n"
854 ";; no-byte-compile: t\n"
855 ";; no-update-autoloads: t\n"
856 ";; End:\n"
857 ";;; " (file-name-nondirectory file)
858 " ends here\n")
859 nil file nil 'silent))
860 file)
862 (defvar generated-autoload-file)
863 (defvar version-control)
865 (defun package-generate-autoloads (name pkg-dir)
866 (let* ((auto-name (format "%s-autoloads.el" name))
867 ;;(ignore-name (concat name "-pkg.el"))
868 (generated-autoload-file (expand-file-name auto-name pkg-dir))
869 ;; Silence `autoload-generate-file-autoloads'.
870 (noninteractive package--silence)
871 (backup-inhibited t)
872 (version-control 'never))
873 (package-autoload-ensure-default-file generated-autoload-file)
874 (update-directory-autoloads pkg-dir)
875 (let ((buf (find-buffer-visiting generated-autoload-file)))
876 (when buf (kill-buffer buf)))
877 auto-name))
879 (defun package--make-autoloads-and-stuff (pkg-desc pkg-dir)
880 "Generate autoloads, description file, etc.. for PKG-DESC installed at PKG-DIR."
881 (package-generate-autoloads (package-desc-name pkg-desc) pkg-dir)
882 (let ((desc-file (expand-file-name (package--description-file pkg-dir)
883 pkg-dir)))
884 (unless (file-exists-p desc-file)
885 (package-generate-description-file pkg-desc desc-file)))
886 ;; FIXME: Create foo.info and dir file from foo.texi?
889 ;;;; Compilation
890 (defun package--compile (pkg-desc)
891 "Byte-compile installed package PKG-DESC."
892 (package-activate-1 pkg-desc)
893 (byte-recompile-directory (package-desc-dir pkg-desc) 0 t))
895 ;;;; Inferring package from current buffer
896 (defun package-read-from-string (str)
897 "Read a Lisp expression from STR.
898 Signal an error if the entire string was not used."
899 (let* ((read-data (read-from-string str))
900 (more-left
901 (condition-case nil
902 ;; The call to `ignore' suppresses a compiler warning.
903 (progn (ignore (read-from-string
904 (substring str (cdr read-data))))
906 (end-of-file nil))))
907 (if more-left
908 (error "Can't read whole string")
909 (car read-data))))
911 (defun package--prepare-dependencies (deps)
912 "Turn DEPS into an acceptable list of dependencies.
914 Any parts missing a version string get a default version string
915 of \"0\" (meaning any version) and an appropriate level of lists
916 is wrapped around any parts requiring it."
917 (cond
918 ((not (listp deps))
919 (error "Invalid requirement specifier: %S" deps))
920 (t (mapcar (lambda (dep)
921 (cond
922 ((symbolp dep) `(,dep "0"))
923 ((stringp dep)
924 (error "Invalid requirement specifier: %S" dep))
925 ((and (listp dep) (null (cdr dep)))
926 (list (car dep) "0"))
927 (t dep)))
928 deps))))
930 (declare-function lm-header "lisp-mnt" (header))
931 (declare-function lm-homepage "lisp-mnt" ())
933 (defun package-buffer-info ()
934 "Return a `package-desc' describing the package in the current buffer.
936 If the buffer does not contain a conforming package, signal an
937 error. If there is a package, narrow the buffer to the file's
938 boundaries."
939 (goto-char (point-min))
940 (unless (re-search-forward "^;;; \\([^ ]*\\)\\.el ---[ \t]*\\(.*?\\)[ \t]*\\(-\\*-.*-\\*-[ \t]*\\)?$" nil t)
941 (error "Package lacks a file header"))
942 (let ((file-name (match-string-no-properties 1))
943 (desc (match-string-no-properties 2))
944 (start (line-beginning-position)))
945 (unless (search-forward (concat ";;; " file-name ".el ends here"))
946 (error "Package lacks a terminating comment"))
947 ;; Try to include a trailing newline.
948 (forward-line)
949 (narrow-to-region start (point))
950 (require 'lisp-mnt)
951 ;; Use some headers we've invented to drive the process.
952 (let* ((requires-str (lm-header "package-requires"))
953 ;; Prefer Package-Version; if defined, the package author
954 ;; probably wants us to use it. Otherwise try Version.
955 (pkg-version
956 (or (package-strip-rcs-id (lm-header "package-version"))
957 (package-strip-rcs-id (lm-header "version"))))
958 (homepage (lm-homepage)))
959 (unless pkg-version
960 (error
961 "Package lacks a \"Version\" or \"Package-Version\" header"))
962 (package-desc-from-define
963 file-name pkg-version desc
964 (if requires-str
965 (package--prepare-dependencies
966 (package-read-from-string requires-str)))
967 :kind 'single
968 :url homepage))))
970 (defun package--read-pkg-desc (kind)
971 "Read a `define-package' form in current buffer.
972 Return the pkg-desc, with desc-kind set to KIND."
973 (goto-char (point-min))
974 (unwind-protect
975 (let* ((pkg-def-parsed (read (current-buffer)))
976 (pkg-desc
977 (when (eq (car pkg-def-parsed) 'define-package)
978 (apply #'package-desc-from-define
979 (append (cdr pkg-def-parsed))))))
980 (when pkg-desc
981 (setf (package-desc-kind pkg-desc) kind)
982 pkg-desc))))
984 (declare-function tar-get-file-descriptor "tar-mode" (file))
985 (declare-function tar--extract "tar-mode" (descriptor))
987 (defun package-tar-file-info ()
988 "Find package information for a tar file.
989 The return result is a `package-desc'."
990 (cl-assert (derived-mode-p 'tar-mode))
991 (let* ((dir-name (file-name-directory
992 (tar-header-name (car tar-parse-info))))
993 (desc-file (package--description-file dir-name))
994 (tar-desc (tar-get-file-descriptor (concat dir-name desc-file))))
995 (unless tar-desc
996 (error "No package descriptor file found"))
997 (with-current-buffer (tar--extract tar-desc)
998 (unwind-protect
999 (or (package--read-pkg-desc 'tar)
1000 (error "Can't find define-package in %s"
1001 (tar-header-name tar-desc)))
1002 (kill-buffer (current-buffer))))))
1004 (defun package-dir-info ()
1005 "Find package information for a directory.
1006 The return result is a `package-desc'."
1007 (cl-assert (derived-mode-p 'dired-mode))
1008 (let* ((desc-file (package--description-file default-directory)))
1009 (if (file-readable-p desc-file)
1010 (with-temp-buffer
1011 (insert-file-contents desc-file)
1012 (package--read-pkg-desc 'dir))
1013 (let ((files (directory-files default-directory t "\\.el\\'" t))
1014 info)
1015 (while files
1016 (with-temp-buffer
1017 (insert-file-contents (pop files))
1018 ;; When we find the file with the data,
1019 (when (setq info (ignore-errors (package-buffer-info)))
1020 ;; stop looping,
1021 (setq files nil)
1022 ;; set the 'dir kind,
1023 (setf (package-desc-kind info) 'dir))))
1024 ;; and return the info.
1025 info))))
1028 ;;; Communicating with Archives
1029 ;; Set of low-level functions for communicating with archives and
1030 ;; signature checking.
1031 (defun package--write-file-no-coding (file-name)
1032 (let ((buffer-file-coding-system 'no-conversion))
1033 (write-region (point-min) (point-max) file-name nil 'silent)))
1035 (declare-function url-http-file-exists-p "url-http" (url))
1037 (defun package--archive-file-exists-p (location file)
1038 (let ((http (string-match "\\`https?:" location)))
1039 (if http
1040 (progn
1041 (require 'url-http)
1042 (url-http-file-exists-p (concat location file)))
1043 (file-exists-p (expand-file-name file location)))))
1045 (declare-function epg-make-context "epg"
1046 (&optional protocol armor textmode include-certs
1047 cipher-algorithm
1048 digest-algorithm
1049 compress-algorithm))
1050 (declare-function epg-verify-string "epg" (context signature
1051 &optional signed-text))
1052 (declare-function epg-context-result-for "epg" (context name))
1053 (declare-function epg-signature-status "epg" (signature))
1054 (declare-function epg-signature-to-string "epg" (signature))
1056 (defun package--display-verify-error (context sig-file)
1057 (unless (equal (epg-context-error-output context) "")
1058 (with-output-to-temp-buffer "*Error*"
1059 (with-current-buffer standard-output
1060 (if (epg-context-result-for context 'verify)
1061 (insert (format "Failed to verify signature %s:\n" sig-file)
1062 (mapconcat #'epg-signature-to-string
1063 (epg-context-result-for context 'verify)
1064 "\n"))
1065 (insert (format "Error while verifying signature %s:\n" sig-file)))
1066 (insert "\nCommand output:\n" (epg-context-error-output context))))))
1068 (defmacro package--with-work-buffer (location file &rest body)
1069 "Run BODY in a buffer containing the contents of FILE at LOCATION.
1070 LOCATION is the base location of a package archive, and should be
1071 one of the URLs (or file names) specified in `package-archives'.
1072 FILE is the name of a file relative to that base location.
1074 This macro retrieves FILE from LOCATION into a temporary buffer,
1075 and evaluates BODY while that buffer is current. This work
1076 buffer is killed afterwards. Return the last value in BODY."
1077 (declare (indent 2) (debug t))
1078 `(with-temp-buffer
1079 (if (string-match-p "\\`https?:" ,location)
1080 (url-insert-file-contents (concat ,location ,file))
1081 (unless (file-name-absolute-p ,location)
1082 (error "Archive location %s is not an absolute file name"
1083 ,location))
1084 (insert-file-contents (expand-file-name ,file ,location)))
1085 ,@body))
1087 (defmacro package--with-work-buffer-async (location file async &rest body)
1088 "Run BODY in a buffer containing the contents of FILE at LOCATION.
1089 If ASYNC is non-nil, and if it is possible, run BODY
1090 asynchronously. If an error is encountered and ASYNC is a
1091 function, call it with no arguments (instead of executing BODY),
1092 otherwise propagate the error. For description of the other
1093 arguments see `package--with-work-buffer'."
1094 (declare (indent 3) (debug t))
1095 (macroexp-let2* macroexp-copyable-p
1096 ((async-1 async)
1097 (file-1 file)
1098 (location-1 location))
1099 `(if (or (not ,async-1)
1100 (not (string-match-p "\\`https?:" ,location-1)))
1101 (package--with-work-buffer ,location-1 ,file-1 ,@body)
1102 (url-retrieve (concat ,location-1 ,file-1)
1103 (lambda (status)
1104 (if (eq (car status) :error)
1105 (if (functionp ,async-1)
1106 (funcall ,async-1)
1107 (signal (cdar status) (cddr status)))
1108 (goto-char (point-min))
1109 (unless (search-forward "\n\n" nil 'noerror)
1110 (error "Invalid url response"))
1111 (delete-region (point-min) (point))
1112 ,@body)
1113 (kill-buffer (current-buffer)))
1115 'silent))))
1117 (defun package--check-signature-content (content string &optional sig-file)
1118 "Check signature CONTENT against STRING.
1119 SIG-FILE is the name of the signature file, used when signaling
1120 errors."
1121 (let* ((context (epg-make-context 'OpenPGP))
1122 (homedir (expand-file-name "gnupg" package-user-dir)))
1123 (setf (epg-context-home-directory context) homedir)
1124 (condition-case error
1125 (epg-verify-string context content string)
1126 (error (package--display-verify-error context sig-file)
1127 (signal (car error) (cdr error))))
1128 (let (good-signatures had-fatal-error)
1129 ;; The .sig file may contain multiple signatures. Success if one
1130 ;; of the signatures is good.
1131 (dolist (sig (epg-context-result-for context 'verify))
1132 (if (eq (epg-signature-status sig) 'good)
1133 (push sig good-signatures)
1134 ;; If package-check-signature is allow-unsigned, don't
1135 ;; signal error when we can't verify signature because of
1136 ;; missing public key. Other errors are still treated as
1137 ;; fatal (bug#17625).
1138 (unless (and (eq package-check-signature 'allow-unsigned)
1139 (eq (epg-signature-status sig) 'no-pubkey))
1140 (setq had-fatal-error t))))
1141 (when (and (null good-signatures) had-fatal-error)
1142 (package--display-verify-error context sig-file)
1143 (error "Failed to verify signature %s" sig-file))
1144 good-signatures)))
1146 (defun package--check-signature (location file &optional string async callback)
1147 "Check signature of the current buffer.
1148 Download the signature file from LOCATION by appending \".sig\"
1149 to FILE.
1150 GnuPG keyring is located under \"gnupg\" in `package-user-dir'.
1151 STRING is the string to verify, it defaults to `buffer-string'.
1152 If ASYNC is non-nil, the download of the signature file is
1153 done asynchronously.
1155 If the signature is verified and CALLBACK was provided, CALLBACK
1156 is `funcall'ed with the list of good signatures as argument (the
1157 list can be empty). If the signatures file is not found,
1158 CALLBACK is called with no arguments."
1159 (let ((sig-file (concat file ".sig"))
1160 (string (or string (buffer-string))))
1161 (condition-case nil
1162 (package--with-work-buffer-async
1163 location sig-file (when async (or callback t))
1164 (let ((sig (package--check-signature-content
1165 (buffer-string) string sig-file)))
1166 (when callback (funcall callback sig))
1167 sig))
1168 (file-error (funcall callback)))))
1171 ;;; Packages on Archives
1172 ;; The following variables store information about packages available
1173 ;; from archives. The most important of these is
1174 ;; `package-archive-contents' which is initially populated by the
1175 ;; function `package-read-all-archive-contents' from a cache on disk.
1176 ;; The `package-initialize' command is also closely related to this
1177 ;; section, but it has its own section.
1178 (defconst package-archive-version 1
1179 "Version number of the package archive understood by this file.
1180 Lower version numbers than this will probably be understood as well.")
1182 ;; We don't prime the cache since it tends to get out of date.
1183 (defvar package-archive-contents nil
1184 "Cache of the contents of the Emacs Lisp Package Archive.
1185 This is an alist mapping package names (symbols) to
1186 non-empty lists of `package-desc' structures.")
1187 (put 'package-archive-contents 'risky-local-variable t)
1189 (defvar package--compatibility-table nil
1190 "Hash table connecting package names to their compatibility.
1191 Each key is a symbol, the name of a package.
1193 The value is either nil, representing an incompatible package, or
1194 a version list, representing the highest compatible version of
1195 that package which is available.
1197 A package is considered incompatible if it requires an Emacs
1198 version higher than the one being used. To check for package
1199 \(in)compatibility, don't read this table directly, use
1200 `package--incompatible-p' which also checks dependencies.")
1202 (defun package--build-compatibility-table ()
1203 "Build `package--compatibility-table' with `package--mapc'."
1204 ;; Initialize the list of built-ins.
1205 (require 'finder-inf nil t)
1206 ;; Build compat table.
1207 (setq package--compatibility-table (make-hash-table :test 'eq))
1208 (package--mapc #'package--add-to-compatibility-table))
1210 (defun package--add-to-compatibility-table (pkg)
1211 "If PKG is compatible (without dependencies), add to the compatibility table.
1212 PKG is a package-desc object.
1213 Only adds if its version is higher than what's already stored in
1214 the table."
1215 (unless (package--incompatible-p pkg 'shallow)
1216 (let* ((name (package-desc-name pkg))
1217 (version (or (package-desc-version pkg) '(0)))
1218 (table-version (gethash name package--compatibility-table)))
1219 (when (or (not table-version)
1220 (version-list-< table-version version))
1221 (puthash name version package--compatibility-table)))))
1223 ;; Package descriptor objects used inside the "archive-contents" file.
1224 ;; Changing this defstruct implies changing the format of the
1225 ;; "archive-contents" files.
1226 (cl-defstruct (package--ac-desc
1227 (:constructor package-make-ac-desc (version reqs summary kind extras))
1228 (:copier nil)
1229 (:type vector))
1230 version reqs summary kind extras)
1232 (defun package--append-to-alist (pkg-desc alist)
1233 "Append an entry for PKG-DESC to the start of ALIST and return it.
1234 This entry takes the form (`package-desc-name' PKG-DESC).
1236 If ALIST already has an entry with this name, destructively add
1237 PKG-DESC to the cdr of this entry instead, sorted by version
1238 number."
1239 (let* ((name (package-desc-name pkg-desc))
1240 (priority-version (package-desc-priority-version pkg-desc))
1241 (existing-packages (assq name alist)))
1242 (if (not existing-packages)
1243 (cons (list name pkg-desc)
1244 alist)
1245 (while (if (and (cdr existing-packages)
1246 (version-list-< priority-version
1247 (package-desc-priority-version
1248 (cadr existing-packages))))
1249 (setq existing-packages (cdr existing-packages))
1250 (push pkg-desc (cdr existing-packages))
1251 nil))
1252 alist)))
1254 (defun package--add-to-archive-contents (package archive)
1255 "Add the PACKAGE from the given ARCHIVE if necessary.
1256 PACKAGE should have the form (NAME . PACKAGE--AC-DESC).
1257 Also, add the originating archive to the `package-desc' structure."
1258 (let* ((name (car package))
1259 (version (package--ac-desc-version (cdr package)))
1260 (pkg-desc
1261 (package-desc-create
1262 :name name
1263 :version version
1264 :reqs (package--ac-desc-reqs (cdr package))
1265 :summary (package--ac-desc-summary (cdr package))
1266 :kind (package--ac-desc-kind (cdr package))
1267 :archive archive
1268 :extras (and (> (length (cdr package)) 4)
1269 ;; Older archive-contents files have only 4
1270 ;; elements here.
1271 (package--ac-desc-extras (cdr package)))))
1272 (pinned-to-archive (assoc name package-pinned-packages)))
1273 ;; Skip entirely if pinned to another archive.
1274 (when (not (and pinned-to-archive
1275 (not (equal (cdr pinned-to-archive) archive))))
1276 (setq package-archive-contents
1277 (package--append-to-alist pkg-desc package-archive-contents)))))
1279 (defun package--read-archive-file (file)
1280 "Re-read archive file FILE, if it exists.
1281 Will return the data from the file, or nil if the file does not exist.
1282 Will throw an error if the archive version is too new."
1283 (let ((filename (expand-file-name file package-user-dir)))
1284 (when (file-exists-p filename)
1285 (with-temp-buffer
1286 (insert-file-contents-literally filename)
1287 (let ((contents (read (current-buffer))))
1288 (if (> (car contents) package-archive-version)
1289 (error "Package archive version %d is higher than %d"
1290 (car contents) package-archive-version))
1291 (cdr contents))))))
1293 (defun package-read-archive-contents (archive)
1294 "Re-read archive contents for ARCHIVE.
1295 If successful, set the variable `package-archive-contents'.
1296 If the archive version is too new, signal an error."
1297 ;; Version 1 of 'archive-contents' is identical to our internal
1298 ;; representation.
1299 (let* ((contents-file (format "archives/%s/archive-contents" archive))
1300 (contents (package--read-archive-file contents-file)))
1301 (when contents
1302 (dolist (package contents)
1303 (package--add-to-archive-contents package archive)))))
1305 (defun package-read-all-archive-contents ()
1306 "Re-read `archive-contents', if it exists.
1307 If successful, set `package-archive-contents'."
1308 (setq package-archive-contents nil)
1309 (dolist (archive package-archives)
1310 (package-read-archive-contents (car archive))))
1312 ;;;; Package Initialize
1313 ;; A bit of a milestone. This brings together some of the above
1314 ;; sections and populates all relevant lists of packages from contents
1315 ;; available on disk.
1316 (defvar package--initialized nil)
1318 ;;;###autoload
1319 (defun package-initialize (&optional no-activate)
1320 "Load Emacs Lisp packages, and activate them.
1321 The variable `package-load-list' controls which packages to load.
1322 If optional arg NO-ACTIVATE is non-nil, don't activate packages.
1323 If `user-init-file' does not mention `(package-initialize)', add
1324 it to the file."
1325 (interactive)
1326 (setq package-alist nil)
1327 (package--ensure-init-file)
1328 (package-load-all-descriptors)
1329 (package-read-all-archive-contents)
1330 (unless no-activate
1331 (dolist (elt package-alist)
1332 (package-activate (car elt))))
1333 (setq package--initialized t)
1334 ;; This uses `package--mapc' so it must be called after
1335 ;; `package--initialized' is t.
1336 (package--build-compatibility-table))
1339 ;;;; Populating `package-archive-contents' from archives
1340 ;; This subsection populates the variables listed above from the
1341 ;; actual archives, instead of from a local cache.
1342 (defvar package--downloads-in-progress nil
1343 "List of in-progress asynchronous downloads.")
1345 (declare-function epg-check-configuration "epg-config"
1346 (config &optional minimum-version))
1347 (declare-function epg-configuration "epg-config" ())
1348 (declare-function epg-import-keys-from-file "epg" (context keys))
1350 (defvar package--silence nil)
1352 (defun package--message (format &rest args)
1353 "Like `message', except sometimes don't print to minibuffer.
1354 If the variable `package--silence' is non-nil, the message is not
1355 displayed on the minibuffer."
1356 (apply #'message format args)
1357 (when package--silence
1358 (message nil)))
1360 ;;;###autoload
1361 (defun package-import-keyring (&optional file)
1362 "Import keys from FILE."
1363 (interactive "fFile: ")
1364 (setq file (expand-file-name file))
1365 (let ((context (epg-make-context 'OpenPGP))
1366 (homedir (expand-file-name "gnupg" package-user-dir)))
1367 (with-file-modes 448
1368 (make-directory homedir t))
1369 (setf (epg-context-home-directory context) homedir)
1370 (package--message "Importing %s..." (file-name-nondirectory file))
1371 (epg-import-keys-from-file context file)
1372 (package--message "Importing %s...done" (file-name-nondirectory file))))
1374 (defvar package--post-download-archives-hook nil
1375 "Hook run after the archive contents are downloaded.
1376 Don't run this hook directly. It is meant to be run as part of
1377 `package--update-downloads-in-progress'.")
1378 (put 'package--post-download-archives-hook 'risky-local-variable t)
1380 (defun package--update-downloads-in-progress (entry)
1381 "Remove ENTRY from `package--downloads-in-progress'.
1382 Once it's empty, run `package--post-download-archives-hook'."
1383 ;; Keep track of the downloading progress.
1384 (setq package--downloads-in-progress
1385 (remove entry package--downloads-in-progress))
1386 ;; If this was the last download, run the hook.
1387 (unless package--downloads-in-progress
1388 (package-read-all-archive-contents)
1389 (package--build-compatibility-table)
1390 ;; We message before running the hook, so the hook can give
1391 ;; messages as well.
1392 (message "Package refresh done")
1393 (run-hooks 'package--post-download-archives-hook)))
1395 (defun package--download-one-archive (archive file &optional async)
1396 "Retrieve an archive file FILE from ARCHIVE, and cache it.
1397 ARCHIVE should be a cons cell of the form (NAME . LOCATION),
1398 similar to an entry in `package-alist'. Save the cached copy to
1399 \"archives/NAME/FILE\" in `package-user-dir'."
1400 (package--with-work-buffer-async (cdr archive) file async
1401 (let* ((location (cdr archive))
1402 (name (car archive))
1403 (content (buffer-string))
1404 (dir (expand-file-name (format "archives/%s" name) package-user-dir))
1405 (local-file (expand-file-name file dir)))
1406 (when (listp (read-from-string content))
1407 (make-directory dir t)
1408 (if (or (not package-check-signature)
1409 (member archive package-unsigned-archives))
1410 ;; If we don't care about the signature, save the file and
1411 ;; we're done.
1412 (progn (write-region content nil local-file nil 'silent)
1413 (package--update-downloads-in-progress archive))
1414 ;; If we care, check it (perhaps async) and *then* write the file.
1415 (package--check-signature
1416 location file content async
1417 ;; This function will be called after signature checking.
1418 (lambda (&optional good-sigs)
1419 (unless (or good-sigs (eq package-check-signature 'allow-unsigned))
1420 ;; Even if the sig fails, this download is done, so
1421 ;; remove it from the in-progress list.
1422 (package--update-downloads-in-progress archive)
1423 (error "Unsigned archive `%s'" name))
1424 ;; Write out the archives file.
1425 (write-region content nil local-file nil 'silent)
1426 ;; Write out good signatures into archive-contents.signed file.
1427 (when good-sigs
1428 (write-region (mapconcat #'epg-signature-to-string good-sigs "\n")
1429 nil (concat local-file ".signed") nil 'silent))
1430 (package--update-downloads-in-progress archive))))))))
1432 (defun package--download-and-read-archives (&optional async)
1433 "Download descriptions of all `package-archives' and read them.
1434 This populates `package-archive-contents'. If ASYNC is non-nil,
1435 perform the downloads asynchronously."
1436 ;; The downloaded archive contents will be read as part of
1437 ;; `package--update-downloads-in-progress'.
1438 (setq package--downloads-in-progress
1439 (append package-archives
1440 package--downloads-in-progress))
1441 (dolist (archive package-archives)
1442 (condition-case-unless-debug nil
1443 (package--download-one-archive
1444 archive "archive-contents"
1445 ;; Called if the async download fails
1446 (when async
1447 (lambda () (package--update-downloads-in-progress archive))))
1448 (error (message "Failed to download `%s' archive."
1449 (car archive))))))
1451 ;;;###autoload
1452 (defun package-refresh-contents (&optional async)
1453 "Download descriptions of all configured ELPA packages.
1454 For each archive configured in the variable `package-archives',
1455 inform Emacs about the latest versions of all packages it offers,
1456 and make them available for download.
1457 Optional argument ASYNC specifies whether to perform the
1458 downloads in the background."
1459 (interactive)
1460 ;; FIXME: Do it asynchronously.
1461 (unless (file-exists-p package-user-dir)
1462 (make-directory package-user-dir t))
1463 (let ((default-keyring (expand-file-name "package-keyring.gpg"
1464 data-directory))
1465 (package--silence async))
1466 (when (and package-check-signature (file-exists-p default-keyring))
1467 (condition-case-unless-debug error
1468 (progn
1469 (epg-check-configuration (epg-configuration))
1470 (package-import-keyring default-keyring))
1471 (error (message "Cannot import default keyring: %S" (cdr error)))))
1472 (package--download-and-read-archives async)))
1475 ;;; Dependency Management
1476 ;; Calculating the full transaction necessary for an installation,
1477 ;; keeping track of which packages were installed strictly as
1478 ;; dependencies, and determining which packages cannot be removed
1479 ;; because they are dependencies.
1480 (defun package-compute-transaction (packages requirements &optional seen)
1481 "Return a list of packages to be installed, including PACKAGES.
1482 PACKAGES should be a list of `package-desc'.
1484 REQUIREMENTS should be a list of additional requirements; each
1485 element in this list should have the form (PACKAGE VERSION-LIST),
1486 where PACKAGE is a package name and VERSION-LIST is the required
1487 version of that package.
1489 This function recursively computes the requirements of the
1490 packages in REQUIREMENTS, and returns a list of all the packages
1491 that must be installed. Packages that are already installed are
1492 not included in this list.
1494 SEEN is used internally to detect infinite recursion."
1495 ;; FIXME: We really should use backtracking to explore the whole
1496 ;; search space (e.g. if foo require bar-1.3, and bar-1.4 requires toto-1.1
1497 ;; whereas bar-1.3 requires toto-1.0 and the user has put a hold on toto-1.0:
1498 ;; the current code might fail to see that it could install foo by using the
1499 ;; older bar-1.3).
1500 (dolist (elt requirements)
1501 (let* ((next-pkg (car elt))
1502 (next-version (cadr elt))
1503 (already ()))
1504 (dolist (pkg packages)
1505 (if (eq next-pkg (package-desc-name pkg))
1506 (setq already pkg)))
1507 (when already
1508 (if (version-list-<= next-version (package-desc-version already))
1509 ;; `next-pkg' is already in `packages', but its position there
1510 ;; means it might be installed too late: remove it from there, so
1511 ;; we re-add it (along with its dependencies) at an earlier place
1512 ;; below (bug#16994).
1513 (if (memq already seen) ;Avoid inf-loop on dependency cycles.
1514 (package--message "Dependency cycle going through %S"
1515 (package-desc-full-name already))
1516 (setq packages (delq already packages))
1517 (setq already nil))
1518 (error "Need package `%s-%s', but only %s is being installed"
1519 next-pkg (package-version-join next-version)
1520 (package-version-join (package-desc-version already)))))
1521 (cond
1522 (already nil)
1523 ((package-installed-p next-pkg next-version) nil)
1526 ;; A package is required, but not installed. It might also be
1527 ;; blocked via `package-load-list'.
1528 (let ((pkg-descs (cdr (assq next-pkg package-archive-contents)))
1529 (found nil)
1530 (problem nil))
1531 (while (and pkg-descs (not found))
1532 (let* ((pkg-desc (pop pkg-descs))
1533 (version (package-desc-version pkg-desc))
1534 (disabled (package-disabled-p next-pkg version)))
1535 (cond
1536 ((version-list-< version next-version)
1537 (error
1538 "Need package `%s-%s', but only %s is available"
1539 next-pkg (package-version-join next-version)
1540 (package-version-join version)))
1541 (disabled
1542 (unless problem
1543 (setq problem
1544 (if (stringp disabled)
1545 (format "Package `%s' held at version %s, \
1546 but version %s required"
1547 next-pkg disabled
1548 (package-version-join next-version))
1549 (format "Required package '%s' is disabled"
1550 next-pkg)))))
1551 (t (setq found pkg-desc)))))
1552 (unless found
1553 (if problem
1554 (error "%s" problem)
1555 (error "Package `%s-%s' is unavailable"
1556 next-pkg (package-version-join next-version))))
1557 (setq packages
1558 (package-compute-transaction (cons found packages)
1559 (package-desc-reqs found)
1560 (cons found seen))))))))
1561 packages)
1563 (defun package--find-non-dependencies ()
1564 "Return a list of installed packages which are not dependencies.
1565 Finds all packages in `package-alist' which are not dependencies
1566 of any other packages.
1567 Used to populate `package-selected-packages'."
1568 (let ((dep-list
1569 (delete-dups
1570 (apply #'append
1571 (mapcar (lambda (p) (mapcar #'car (package-desc-reqs (cadr p))))
1572 package-alist)))))
1573 (cl-loop for p in package-alist
1574 for name = (car p)
1575 unless (memq name dep-list)
1576 collect name)))
1578 (defun package--save-selected-packages (value)
1579 "Set and save `package-selected-packages' to VALUE."
1580 (let ((save-silently package--silence))
1581 (customize-save-variable
1582 'package-selected-packages
1583 (setq package-selected-packages value))))
1585 (defun package--user-selected-p (pkg)
1586 "Return non-nil if PKG is a package was installed by the user.
1587 PKG is a package name.
1588 This looks into `package-selected-packages', populating it first
1589 if it is still empty."
1590 (unless (consp package-selected-packages)
1591 (package--save-selected-packages (package--find-non-dependencies)))
1592 (memq pkg package-selected-packages))
1594 (defun package--get-deps (pkg &optional only)
1595 (let* ((pkg-desc (cadr (assq pkg package-alist)))
1596 (direct-deps (cl-loop for p in (package-desc-reqs pkg-desc)
1597 for name = (car p)
1598 when (assq name package-alist)
1599 collect name))
1600 (indirect-deps (unless (eq only 'direct)
1601 (delete-dups
1602 (cl-loop for p in direct-deps
1603 append (package--get-deps p))))))
1604 (cl-case only
1605 (direct direct-deps)
1606 (separate (list direct-deps indirect-deps))
1607 (indirect indirect-deps)
1608 (t (delete-dups (append direct-deps indirect-deps))))))
1610 (defun package--removable-packages ()
1611 "Return a list of names of packages no longer needed.
1612 These are packages which are neither contained in
1613 `package-selected-packages' nor a dependency of one that is."
1614 (let ((needed (cl-loop for p in package-selected-packages
1615 if (assq p package-alist)
1616 ;; `p' and its dependencies are needed.
1617 append (cons p (package--get-deps p)))))
1618 (cl-loop for p in (mapcar #'car package-alist)
1619 unless (memq p needed)
1620 collect p)))
1622 (defun package--used-elsewhere-p (pkg-desc &optional pkg-list)
1623 "Non-nil if PKG-DESC is a dependency of a package in PKG-LIST.
1624 Return the first package found in PKG-LIST of which PKG is a
1625 dependency.
1627 When not specified, PKG-LIST defaults to `package-alist'
1628 with PKG-DESC entry removed."
1629 (unless (string= (package-desc-status pkg-desc) "obsolete")
1630 (let ((pkg (package-desc-name pkg-desc)))
1631 (cl-loop with alist = (or pkg-list
1632 (remove (assq pkg package-alist)
1633 package-alist))
1634 for p in alist thereis
1635 (and (memq pkg (mapcar #'car (package-desc-reqs (cadr p))))
1636 (car p))))))
1638 (defun package--sort-deps-in-alist (package only)
1639 "Return a list of dependencies for PACKAGE sorted by dependency.
1640 PACKAGE is included as the first element of the returned list.
1641 ONLY is an alist associating package names to package objects.
1642 Only these packages will be in the return value an their cdrs are
1643 destructively set to nil in ONLY."
1644 (let ((out))
1645 (dolist (dep (package-desc-reqs package))
1646 (when-let ((cell (assq (car dep) only))
1647 (dep-package (cdr-safe cell)))
1648 (setcdr cell nil)
1649 (setq out (append (package--sort-deps-in-alist dep-package only)
1650 out))))
1651 (cons package out)))
1653 (defun package--sort-by-dependence (package-list)
1654 "Return PACKAGE-LIST sorted by dependence.
1655 That is, any element of the returned list is guaranteed to not
1656 directly depend on any elements that come before it.
1658 PACKAGE-LIST is a list of package-desc objects.
1659 Indirect dependencies are guaranteed to be returned in order only
1660 if all the in-between dependencies are also in PACKAGE-LIST."
1661 (let ((alist (mapcar (lambda (p) (cons (package-desc-name p) p)) package-list))
1662 out-list)
1663 (dolist (cell alist out-list)
1664 ;; `package--sort-deps-in-alist' destructively changes alist, so
1665 ;; some cells might already be empty. We check this here.
1666 (when-let ((pkg-desc (cdr cell)))
1667 (setcdr cell nil)
1668 (setq out-list
1669 (append (package--sort-deps-in-alist pkg-desc alist)
1670 out-list))))))
1673 ;;; Installation Functions
1674 ;; As opposed to the previous section (which listed some underlying
1675 ;; functions necessary for installation), this one contains the actual
1676 ;; functions that install packages. The package itself can be
1677 ;; installed in a variety of ways (archives, buffer, file), but
1678 ;; requirements (dependencies) are always satisfied by looking in
1679 ;; `package-archive-contents'.
1680 (defun package-archive-base (desc)
1681 "Return the archive containing the package NAME."
1682 (cdr (assoc (package-desc-archive desc) package-archives)))
1684 (defun package-install-from-archive (pkg-desc &optional async callback)
1685 "Download and install a tar package.
1686 If ASYNC is non-nil, perform the download asynchronously.
1687 If CALLBACK is non-nil, call it with no arguments once the
1688 operation is done."
1689 ;; This won't happen, unless the archive is doing something wrong.
1690 (when (eq (package-desc-kind pkg-desc) 'dir)
1691 (error "Can't install directory package from archive"))
1692 (let* ((location (package-archive-base pkg-desc))
1693 (file (concat (package-desc-full-name pkg-desc)
1694 (package-desc-suffix pkg-desc))))
1695 (package--with-work-buffer-async location file async
1696 (if (or (not package-check-signature)
1697 (member (package-desc-archive pkg-desc)
1698 package-unsigned-archives))
1699 ;; If we don't care about the signature, unpack and we're
1700 ;; done.
1701 (progn (let ((save-silently async))
1702 (package-unpack pkg-desc))
1703 (funcall callback))
1704 ;; If we care, check it and *then* write the file.
1705 (let ((content (buffer-string)))
1706 (package--check-signature
1707 location file content async
1708 ;; This function will be called after signature checking.
1709 (lambda (&optional good-sigs)
1710 (unless (or good-sigs (eq package-check-signature 'allow-unsigned))
1711 ;; Even if the sig fails, this download is done, so
1712 ;; remove it from the in-progress list.
1713 (error "Unsigned package: `%s'"
1714 (package-desc-name pkg-desc)))
1715 ;; Signature checked, unpack now.
1716 (with-temp-buffer (insert content)
1717 (let ((save-silently async))
1718 (package-unpack pkg-desc)))
1719 ;; Here the package has been installed successfully, mark it as
1720 ;; signed if appropriate.
1721 (when good-sigs
1722 ;; Write out good signatures into NAME-VERSION.signed file.
1723 (write-region (mapconcat #'epg-signature-to-string good-sigs "\n")
1725 (expand-file-name
1726 (concat (package-desc-full-name pkg-desc) ".signed")
1727 package-user-dir)
1728 nil 'silent)
1729 ;; Update the old pkg-desc which will be shown on the description buffer.
1730 (setf (package-desc-signed pkg-desc) t)
1731 ;; Update the new (activated) pkg-desc as well.
1732 (when-let ((pkg-descs (cdr (assq (package-desc-name pkg-desc) package-alist))))
1733 (setf (package-desc-signed (car pkg-descs)) t)))
1734 (when (functionp callback)
1735 (funcall callback)))))))))
1737 (defun package-installed-p (package &optional min-version)
1738 "Return true if PACKAGE, of MIN-VERSION or newer, is installed.
1739 If PACKAGE is a symbol, it is the package name and MIN-VERSION
1740 should be a version list.
1742 If PACKAGE is a package-desc object, MIN-VERSION is ignored."
1743 (unless package--initialized (error "package.el is not yet initialized!"))
1744 (if (package-desc-p package)
1745 (let ((dir (package-desc-dir package)))
1746 (and (stringp dir)
1747 (file-exists-p dir)))
1749 (let ((pkg-descs (cdr (assq package package-alist))))
1750 (and pkg-descs
1751 (version-list-<= min-version
1752 (package-desc-version (car pkg-descs)))))
1753 ;; Also check built-in packages.
1754 (package-built-in-p package min-version))))
1756 (defun package-download-transaction (packages &optional async callback)
1757 "Download and install all the packages in PACKAGES.
1758 PACKAGES should be a list of package-desc.
1759 If ASYNC is non-nil, perform the downloads asynchronously.
1760 If CALLBACK is non-nil, call it with no arguments once the
1761 entire operation is done.
1763 This function assumes that all package requirements in
1764 PACKAGES are satisfied, i.e. that PACKAGES is computed
1765 using `package-compute-transaction'."
1766 (cond
1767 (packages (package-install-from-archive
1768 (car packages)
1769 async
1770 (lambda ()
1771 (package-download-transaction (cdr packages))
1772 (when (functionp callback)
1773 (funcall callback)))))
1774 (callback (funcall callback))))
1776 (defun package--ensure-init-file ()
1777 "Ensure that the user's init file calls `package-initialize'."
1778 ;; Don't mess with the init-file from "emacs -Q".
1779 (when user-init-file
1780 (let* ((buffer (find-buffer-visiting user-init-file))
1781 (contains-init
1782 (if buffer
1783 (with-current-buffer buffer
1784 (search-forward "(package-initialize)" nil 'noerror))
1785 (with-temp-buffer
1786 (insert-file-contents user-init-file)
1787 (goto-char (point-min))
1788 (search-forward "(package-initialize)" nil 'noerror)))))
1789 (unless contains-init
1790 (with-current-buffer (or buffer
1791 (let ((delay-mode-hooks t))
1792 (find-file-noselect user-init-file)))
1793 (save-excursion
1794 (save-restriction
1795 (widen)
1796 (goto-char (point-min))
1797 (insert
1798 ";; Added by Package.el. This must come before configurations of\n"
1799 ";; installed packages. Don't delete this line. If you don't want it,\n"
1800 ";; just comment it out by adding a semicolon to the start of the line.\n"
1801 ";; You may delete these explanatory comments.\n"
1802 "(package-initialize)\n")
1803 (unless (looking-at-p "$")
1804 (insert "\n"))
1805 (let ((file-precious-flag t))
1806 (save-buffer))
1807 (unless buffer
1808 (kill-buffer (current-buffer))))))))))
1810 ;;;###autoload
1811 (defun package-install (pkg &optional dont-select async callback)
1812 "Install the package PKG.
1813 PKG can be a package-desc or the package name of one the available packages
1814 in an archive in `package-archives'. Interactively, prompt for its name.
1816 If called interactively or if DONT-SELECT nil, add PKG to
1817 `package-selected-packages'.
1818 If ASYNC is non-nil, perform the downloads asynchronously.
1819 If CALLBACK is non-nil, call it with no arguments once the
1820 entire operation is done.
1822 If PKG is a package-desc and it is already installed, don't try
1823 to install it but still mark it as selected."
1824 (interactive
1825 (progn
1826 ;; Initialize the package system to get the list of package
1827 ;; symbols for completion.
1828 (unless package--initialized
1829 (package-initialize t))
1830 (unless package-archive-contents
1831 (package-refresh-contents))
1832 (list (intern (completing-read
1833 "Install package: "
1834 (delq nil
1835 (mapcar (lambda (elt)
1836 (unless (package-installed-p (car elt))
1837 (symbol-name (car elt))))
1838 package-archive-contents))
1839 nil t))
1840 nil)))
1841 (let ((name (if (package-desc-p pkg)
1842 (package-desc-name pkg)
1843 pkg)))
1844 (unless (or dont-select (package--user-selected-p name))
1845 (package--save-selected-packages
1846 (cons name package-selected-packages))))
1847 (if-let ((transaction
1848 (if (package-desc-p pkg)
1849 (unless (package-installed-p pkg)
1850 (package-compute-transaction (list pkg)
1851 (package-desc-reqs pkg)))
1852 (package-compute-transaction () (list (list pkg))))))
1853 (package-download-transaction transaction async callback)
1854 (package--message "`%s' is already installed" (package-desc-full-name pkg))))
1856 (defun package-strip-rcs-id (str)
1857 "Strip RCS version ID from the version string STR.
1858 If the result looks like a dotted numeric version, return it.
1859 Otherwise return nil."
1860 (when str
1861 (when (string-match "\\`[ \t]*[$]Revision:[ \t]+" str)
1862 (setq str (substring str (match-end 0))))
1863 (condition-case nil
1864 (if (version-to-list str)
1865 str)
1866 (error nil))))
1868 (declare-function lm-homepage "lisp-mnt" (&optional file))
1870 ;;;###autoload
1871 (defun package-install-from-buffer ()
1872 "Install a package from the current buffer.
1873 The current buffer is assumed to be a single .el or .tar file or
1874 a directory. These must follow the packaging guidelines (see
1875 info node `(elisp)Packaging').
1877 Specially, if current buffer is a directory, the -pkg.el
1878 description file is not mandatory, in which case the information
1879 is derived from the main .el file in the directory.
1881 Downloads and installs required packages as needed."
1882 (interactive)
1883 (let* ((pkg-desc
1884 (cond
1885 ((derived-mode-p 'dired-mode)
1886 ;; This is the only way a package-desc object with a `dir'
1887 ;; desc-kind can be created. Such packages can't be
1888 ;; uploaded or installed from archives, they can only be
1889 ;; installed from local buffers or directories.
1890 (package-dir-info))
1891 ((derived-mode-p 'tar-mode)
1892 (package-tar-file-info))
1894 (package-buffer-info))))
1895 (name (package-desc-name pkg-desc)))
1896 ;; Download and install the dependencies.
1897 (let* ((requires (package-desc-reqs pkg-desc))
1898 (transaction (package-compute-transaction nil requires)))
1899 (package-download-transaction transaction))
1900 ;; Install the package itself.
1901 (package-unpack pkg-desc)
1902 (unless (package--user-selected-p name)
1903 (package--save-selected-packages
1904 (cons name package-selected-packages)))
1905 pkg-desc))
1907 ;;;###autoload
1908 (defun package-install-file (file)
1909 "Install a package from a file.
1910 The file can either be a tar file or an Emacs Lisp file."
1911 (interactive "fPackage file name: ")
1912 (with-temp-buffer
1913 (if (file-directory-p file)
1914 (progn
1915 (setq default-directory file)
1916 (dired-mode))
1917 (insert-file-contents-literally file)
1918 (when (string-match "\\.tar\\'" file) (tar-mode)))
1919 (package-install-from-buffer)))
1921 ;;;###autoload
1922 (defun package-install-user-selected-packages ()
1923 "Ensure packages in `package-selected-packages' are installed.
1924 If some packages are not installed propose to install them."
1925 (interactive)
1926 ;; We don't need to populate `package-selected-packages' before
1927 ;; using here, because the outcome is the same either way (nothing
1928 ;; gets installed).
1929 (if (not package-selected-packages)
1930 (message "`package-selected-packages' is empty, nothing to install")
1931 (cl-loop for p in package-selected-packages
1932 unless (package-installed-p p)
1933 collect p into lst
1934 finally
1935 (if lst
1936 (when (y-or-n-p
1937 (format "%s packages will be installed:\n%s, proceed?"
1938 (length lst)
1939 (mapconcat #'symbol-name lst ", ")))
1940 (mapc #'package-install lst))
1941 (message "All your packages are already installed")))))
1944 ;;; Package Deletion
1945 (defun package--newest-p (pkg)
1946 "Return t if PKG is the newest package with its name."
1947 (equal (cadr (assq (package-desc-name pkg) package-alist))
1948 pkg))
1950 (defun package-delete (pkg-desc &optional force nosave)
1951 "Delete package PKG-DESC.
1953 Argument PKG-DESC is a full description of package as vector.
1954 When package is used elsewhere as dependency of another package,
1955 refuse deleting it and return an error.
1956 If FORCE is non-nil package will be deleted even if it is used
1957 elsewhere.
1958 If NOSAVE is non-nil, the package is not removed from
1959 `package-selected-packages'."
1960 (let ((dir (package-desc-dir pkg-desc))
1961 (name (package-desc-name pkg-desc))
1962 pkg-used-elsewhere-by)
1963 ;; If the user is trying to delete this package, they definitely
1964 ;; don't want it marked as selected, so we remove it from
1965 ;; `package-selected-packages' even if it can't be deleted.
1966 (when (and (null nosave)
1967 (package--user-selected-p name)
1968 ;; Don't deselect if this is an older version of an
1969 ;; upgraded package.
1970 (package--newest-p pkg-desc))
1971 (package--save-selected-packages (remove name package-selected-packages)))
1972 (cond ((not (string-prefix-p (file-name-as-directory
1973 (expand-file-name package-user-dir))
1974 (expand-file-name dir)))
1975 ;; Don't delete "system" packages.
1976 (error "Package `%s' is a system package, not deleting"
1977 (package-desc-full-name pkg-desc)))
1978 ((and (null force)
1979 (setq pkg-used-elsewhere-by
1980 (package--used-elsewhere-p pkg-desc)))
1981 ;; Don't delete packages used as dependency elsewhere.
1982 (error "Package `%s' is used by `%s' as dependency, not deleting"
1983 (package-desc-full-name pkg-desc)
1984 pkg-used-elsewhere-by))
1986 (delete-directory dir t t)
1987 ;; Remove NAME-VERSION.signed file.
1988 (let ((signed-file (concat dir ".signed")))
1989 (if (file-exists-p signed-file)
1990 (delete-file signed-file)))
1991 ;; Update package-alist.
1992 (let ((pkgs (assq name package-alist)))
1993 (delete pkg-desc pkgs)
1994 (unless (cdr pkgs)
1995 (setq package-alist (delq pkgs package-alist))))
1996 (package--message "Package `%s' deleted." (package-desc-full-name pkg-desc))))))
1998 ;;;###autoload
1999 (defun package-reinstall (pkg)
2000 "Reinstall package PKG.
2001 PKG should be either a symbol, the package name, or a package-desc
2002 object."
2003 (interactive (list (intern (completing-read
2004 "Reinstall package: "
2005 (mapcar #'symbol-name
2006 (mapcar #'car package-alist))))))
2007 (package-delete
2008 (if (package-desc-p pkg) pkg (cadr (assq pkg package-alist)))
2009 'force 'nosave)
2010 (package-install pkg 'dont-select))
2012 ;;;###autoload
2013 (defun package-autoremove ()
2014 "Remove packages that are no more needed.
2016 Packages that are no more needed by other packages in
2017 `package-selected-packages' and their dependencies
2018 will be deleted."
2019 (interactive)
2020 ;; If `package-selected-packages' is nil, it would make no sense to
2021 ;; try to populate it here, because then `package-autoremove' will
2022 ;; do absolutely nothing.
2023 (when (or package-selected-packages
2024 (yes-or-no-p
2025 "`package-selected-packages' is empty! Really remove ALL packages? "))
2026 (let ((removable (package--removable-packages)))
2027 (if removable
2028 (when (y-or-n-p
2029 (format "%s packages will be deleted:\n%s, proceed? "
2030 (length removable)
2031 (mapconcat #'symbol-name removable ", ")))
2032 (mapc (lambda (p)
2033 (package-delete (cadr (assq p package-alist)) t))
2034 removable))
2035 (message "Nothing to autoremove")))))
2038 ;;;; Package description buffer.
2040 ;;;###autoload
2041 (defun describe-package (package)
2042 "Display the full documentation of PACKAGE (a symbol)."
2043 (interactive
2044 (let* ((guess (function-called-at-point)))
2045 (require 'finder-inf nil t)
2046 ;; Load the package list if necessary (but don't activate them).
2047 (unless package--initialized
2048 (package-initialize t))
2049 (let ((packages (append (mapcar 'car package-alist)
2050 (mapcar 'car package-archive-contents)
2051 (mapcar 'car package--builtins))))
2052 (unless (memq guess packages)
2053 (setq guess nil))
2054 (setq packages (mapcar 'symbol-name packages))
2055 (let ((val
2056 (completing-read (if guess
2057 (format "Describe package (default %s): "
2058 guess)
2059 "Describe package: ")
2060 packages nil t nil nil guess)))
2061 (list (intern val))))))
2062 (if (not (or (package-desc-p package) (and package (symbolp package))))
2063 (message "No package specified")
2064 (help-setup-xref (list #'describe-package package)
2065 (called-interactively-p 'interactive))
2066 (with-help-window (help-buffer)
2067 (with-current-buffer standard-output
2068 (describe-package-1 package)))))
2070 (declare-function lm-commentary "lisp-mnt" (&optional file))
2072 (defun describe-package-1 (pkg)
2073 (require 'lisp-mnt)
2074 (let* ((desc (or
2075 (if (package-desc-p pkg) pkg)
2076 (cadr (assq pkg package-alist))
2077 (let ((built-in (assq pkg package--builtins)))
2078 (if built-in
2079 (package--from-builtin built-in)
2080 (cadr (assq pkg package-archive-contents))))))
2081 (name (if desc (package-desc-name desc) pkg))
2082 (pkg-dir (if desc (package-desc-dir desc)))
2083 (reqs (if desc (package-desc-reqs desc)))
2084 (version (if desc (package-desc-version desc)))
2085 (archive (if desc (package-desc-archive desc)))
2086 (extras (and desc (package-desc-extras desc)))
2087 (homepage (cdr (assoc :url extras)))
2088 (keywords (if desc (package-desc--keywords desc)))
2089 (built-in (eq pkg-dir 'builtin))
2090 (installable (and archive (not built-in)))
2091 (status (if desc (package-desc-status desc) "orphan"))
2092 (incompatible-reason (package--incompatible-p desc))
2093 (signed (if desc (package-desc-signed desc))))
2094 (when incompatible-reason
2095 (setq status "incompatible"))
2096 (prin1 name)
2097 (princ " is ")
2098 (princ (if (memq (aref status 0) '(?a ?e ?i ?o ?u)) "an " "a "))
2099 (princ status)
2100 (princ " package.\n\n")
2102 (insert " " (propertize "Status" 'font-lock-face 'bold) ": ")
2103 (cond (built-in
2104 (insert (propertize (capitalize status)
2105 'font-lock-face 'font-lock-builtin-face)
2106 "."))
2107 (pkg-dir
2108 (insert (propertize (if (member status '("unsigned" "dependency"))
2109 "Installed"
2110 (capitalize status)) ;FIXME: Why comment-face?
2111 'font-lock-face 'font-lock-comment-face))
2112 (insert " in `")
2113 ;; Todo: Add button for uninstalling.
2114 (help-insert-xref-button (abbreviate-file-name
2115 (file-name-as-directory pkg-dir))
2116 'help-package-def pkg-dir)
2117 (if (and (package-built-in-p name)
2118 (not (package-built-in-p name version)))
2119 (insert "',\n shadowing a "
2120 (propertize "built-in package"
2121 'font-lock-face 'font-lock-builtin-face))
2122 (insert "'"))
2123 (if signed
2124 (insert ".")
2125 (insert " (unsigned).")))
2126 (incompatible-reason
2127 (insert (propertize "Incompatible" 'face font-lock-warning-face)
2128 " because it depends on ")
2129 (if (stringp incompatible-reason)
2130 (insert "Emacs " incompatible-reason ".")
2131 (insert "uninstallable packages.")))
2132 (installable
2133 (insert (capitalize status))
2134 (insert " from " (format "%s" archive))
2135 (insert " -- ")
2136 (package-make-button
2137 "Install"
2138 'action 'package-install-button-action
2139 'package-desc desc))
2140 (t (insert (capitalize status) ".")))
2141 (insert "\n")
2142 (insert " " (propertize "Archive" 'font-lock-face 'bold)
2143 ": " (or archive "n/a") "\n")
2144 (and version
2145 (insert " "
2146 (propertize "Version" 'font-lock-face 'bold) ": "
2147 (package-version-join version) "\n"))
2149 (setq reqs (if desc (package-desc-reqs desc)))
2150 (when reqs
2151 (insert " " (propertize "Requires" 'font-lock-face 'bold) ": ")
2152 (let ((first t))
2153 (dolist (req reqs)
2154 (let* ((name (car req))
2155 (vers (cadr req))
2156 (text (format "%s-%s" (symbol-name name)
2157 (package-version-join vers)))
2158 (reason (if (and (listp incompatible-reason)
2159 (assq name incompatible-reason))
2160 " (not available)" "")))
2161 (cond (first (setq first nil))
2162 ((>= (+ 2 (current-column) (length text) (length reason))
2163 (window-width))
2164 (insert ",\n "))
2165 (t (insert ", ")))
2166 (help-insert-xref-button text 'help-package name)
2167 (insert reason)))
2168 (insert "\n")))
2169 (insert " " (propertize "Summary" 'font-lock-face 'bold)
2170 ": " (if desc (package-desc-summary desc)) "\n")
2171 (when homepage
2172 (insert " " (propertize "Homepage" 'font-lock-face 'bold) ": ")
2173 (help-insert-xref-button homepage 'help-url homepage)
2174 (insert "\n"))
2175 (when keywords
2176 (insert " " (propertize "Keywords" 'font-lock-face 'bold) ": ")
2177 (dolist (k keywords)
2178 (package-make-button
2180 'package-keyword k
2181 'action 'package-keyword-button-action)
2182 (insert " "))
2183 (insert "\n"))
2184 (let* ((all-pkgs (append (cdr (assq name package-alist))
2185 (cdr (assq name package-archive-contents))
2186 (let ((bi (assq name package--builtins)))
2187 (if bi (list (package--from-builtin bi))))))
2188 (other-pkgs (delete desc all-pkgs)))
2189 (when other-pkgs
2190 (insert " " (propertize "Other versions" 'font-lock-face 'bold) ": "
2191 (mapconcat
2192 (lambda (opkg)
2193 (let* ((ov (package-desc-version opkg))
2194 (dir (package-desc-dir opkg))
2195 (from (or (package-desc-archive opkg)
2196 (if (stringp dir) "installed" dir))))
2197 (if (not ov) (format "%s" from)
2198 (format "%s (%s)"
2199 (make-text-button (package-version-join ov) nil
2200 'face 'link
2201 'follow-link t
2202 'action
2203 (lambda (_button)
2204 (describe-package opkg)))
2205 from))))
2206 other-pkgs ", ")
2207 ".\n")))
2209 (insert "\n")
2211 (if built-in
2212 ;; For built-in packages, insert the commentary.
2213 (let ((fn (locate-file (format "%s.el" name) load-path
2214 load-file-rep-suffixes))
2215 (opoint (point)))
2216 (insert (or (lm-commentary fn) ""))
2217 (save-excursion
2218 (goto-char opoint)
2219 (when (re-search-forward "^;;; Commentary:\n" nil t)
2220 (replace-match ""))
2221 (while (re-search-forward "^\\(;+ ?\\)" nil t)
2222 (replace-match ""))))
2223 (let ((readme (expand-file-name (format "%s-readme.txt" name)
2224 package-user-dir))
2225 readme-string)
2226 ;; For elpa packages, try downloading the commentary. If that
2227 ;; fails, try an existing readme file in `package-user-dir'.
2228 (cond ((condition-case nil
2229 (save-excursion
2230 (package--with-work-buffer
2231 (package-archive-base desc)
2232 (format "%s-readme.txt" name)
2233 (save-excursion
2234 (goto-char (point-max))
2235 (unless (bolp)
2236 (insert ?\n)))
2237 (write-region nil nil
2238 (expand-file-name readme package-user-dir)
2239 nil 'silent)
2240 (setq readme-string (buffer-string))
2242 (error nil))
2243 (insert readme-string))
2244 ((file-readable-p readme)
2245 (insert-file-contents readme)
2246 (goto-char (point-max))))))))
2248 (defun package-install-button-action (button)
2249 (let ((pkg-desc (button-get button 'package-desc)))
2250 (when (y-or-n-p (format "Install package `%s'? "
2251 (package-desc-full-name pkg-desc)))
2252 (package-install pkg-desc nil)
2253 (revert-buffer nil t)
2254 (goto-char (point-min)))))
2256 (defun package-keyword-button-action (button)
2257 (let ((pkg-keyword (button-get button 'package-keyword)))
2258 (package-show-package-list t (list pkg-keyword))))
2260 (defun package-make-button (text &rest props)
2261 (let ((button-text (if (display-graphic-p) text (concat "[" text "]")))
2262 (button-face (if (display-graphic-p)
2263 '(:box (:line-width 2 :color "dark grey")
2264 :background "light grey"
2265 :foreground "black")
2266 'link)))
2267 (apply 'insert-text-button button-text 'face button-face 'follow-link t
2268 props)))
2271 ;;;; Package menu mode.
2273 (defvar package-menu-mode-map
2274 (let ((map (make-sparse-keymap))
2275 (menu-map (make-sparse-keymap "Package")))
2276 (set-keymap-parent map tabulated-list-mode-map)
2277 (define-key map "\C-m" 'package-menu-describe-package)
2278 (define-key map "u" 'package-menu-mark-unmark)
2279 (define-key map "\177" 'package-menu-backup-unmark)
2280 (define-key map "d" 'package-menu-mark-delete)
2281 (define-key map "i" 'package-menu-mark-install)
2282 (define-key map "U" 'package-menu-mark-upgrades)
2283 (define-key map "r" 'package-menu-refresh)
2284 (define-key map "f" 'package-menu-filter)
2285 (define-key map "~" 'package-menu-mark-obsolete-for-deletion)
2286 (define-key map "x" 'package-menu-execute)
2287 (define-key map "h" 'package-menu-quick-help)
2288 (define-key map "?" 'package-menu-describe-package)
2289 (define-key map [menu-bar package-menu] (cons "Package" menu-map))
2290 (define-key menu-map [mq]
2291 '(menu-item "Quit" quit-window
2292 :help "Quit package selection"))
2293 (define-key menu-map [s1] '("--"))
2294 (define-key menu-map [mn]
2295 '(menu-item "Next" next-line
2296 :help "Next Line"))
2297 (define-key menu-map [mp]
2298 '(menu-item "Previous" previous-line
2299 :help "Previous Line"))
2300 (define-key menu-map [s2] '("--"))
2301 (define-key menu-map [mu]
2302 '(menu-item "Unmark" package-menu-mark-unmark
2303 :help "Clear any marks on a package and move to the next line"))
2304 (define-key menu-map [munm]
2305 '(menu-item "Unmark Backwards" package-menu-backup-unmark
2306 :help "Back up one line and clear any marks on that package"))
2307 (define-key menu-map [md]
2308 '(menu-item "Mark for Deletion" package-menu-mark-delete
2309 :help "Mark a package for deletion and move to the next line"))
2310 (define-key menu-map [mi]
2311 '(menu-item "Mark for Install" package-menu-mark-install
2312 :help "Mark a package for installation and move to the next line"))
2313 (define-key menu-map [mupgrades]
2314 '(menu-item "Mark Upgradable Packages" package-menu-mark-upgrades
2315 :help "Mark packages that have a newer version for upgrading"))
2316 (define-key menu-map [s3] '("--"))
2317 (define-key menu-map [mf]
2318 '(menu-item "Filter Package List..." package-menu-filter
2319 :help "Filter package selection (q to go back)"))
2320 (define-key menu-map [mg]
2321 '(menu-item "Update Package List" revert-buffer
2322 :help "Update the list of packages"))
2323 (define-key menu-map [mr]
2324 '(menu-item "Refresh Package List" package-menu-refresh
2325 :help "Download the ELPA archive"))
2326 (define-key menu-map [s4] '("--"))
2327 (define-key menu-map [mt]
2328 '(menu-item "Mark Obsolete Packages" package-menu-mark-obsolete-for-deletion
2329 :help "Mark all obsolete packages for deletion"))
2330 (define-key menu-map [mx]
2331 '(menu-item "Execute Actions" package-menu-execute
2332 :help "Perform all the marked actions"))
2333 (define-key menu-map [s5] '("--"))
2334 (define-key menu-map [mh]
2335 '(menu-item "Help" package-menu-quick-help
2336 :help "Show short key binding help for package-menu-mode"))
2337 (define-key menu-map [mc]
2338 '(menu-item "Describe Package" package-menu-describe-package
2339 :help "Display information about this package"))
2340 map)
2341 "Local keymap for `package-menu-mode' buffers.")
2343 (defvar package-menu--new-package-list nil
2344 "List of newly-available packages since `list-packages' was last called.")
2346 (define-derived-mode package-menu-mode tabulated-list-mode "Package Menu"
2347 "Major mode for browsing a list of packages.
2348 Letters do not insert themselves; instead, they are commands.
2349 \\<package-menu-mode-map>
2350 \\{package-menu-mode-map}"
2351 (setq mode-line-process '(package--downloads-in-progress ":Loading"))
2352 (setq tabulated-list-format
2353 `[("Package" 18 package-menu--name-predicate)
2354 ("Version" 13 nil)
2355 ("Status" 10 package-menu--status-predicate)
2356 ,@(if (cdr package-archives)
2357 '(("Archive" 10 package-menu--archive-predicate)))
2358 ("Description" 0 nil)])
2359 (setq tabulated-list-padding 2)
2360 (setq tabulated-list-sort-key (cons "Status" nil))
2361 (add-hook 'tabulated-list-revert-hook 'package-menu--refresh nil t)
2362 (tabulated-list-init-header))
2364 (defmacro package--push (pkg-desc status listname)
2365 "Convenience macro for `package-menu--generate'.
2366 If the alist stored in the symbol LISTNAME lacks an entry for a
2367 package PKG-DESC, add one. The alist is keyed with PKG-DESC."
2368 `(unless (assoc ,pkg-desc ,listname)
2369 ;; FIXME: Should we move status into pkg-desc?
2370 (push (cons ,pkg-desc ,status) ,listname)))
2372 (defvar package-list-unversioned nil
2373 "If non-nil include packages that don't have a version in `list-package'.")
2375 (defvar package-list-unsigned nil
2376 "If non-nil, mention in the list which packages were installed w/o signature.")
2378 (defvar package--emacs-version-list (version-to-list emacs-version)
2379 "`emacs-version', as a list.")
2381 (defun package--incompatible-p (pkg &optional shallow)
2382 "Return non-nil if PKG has no chance of being installable.
2383 PKG is a package-desc object.
2385 If SHALLOW is non-nil, this only checks if PKG depends on a
2386 higher `emacs-version' than the one being used. Otherwise, also
2387 checks the viability of dependencies, according to
2388 `package--compatibility-table'.
2390 If PKG requires an incompatible Emacs version, the return value
2391 is this version (as a string).
2392 If PKG requires incompatible packages, the return value is a list
2393 of these dependencies, similar to the list returned by
2394 `package-desc-reqs'."
2395 (let* ((reqs (package-desc-reqs pkg))
2396 (version (cadr (assq 'emacs reqs))))
2397 (if (and version (version-list-< package--emacs-version-list version))
2398 (package-version-join version)
2399 (unless shallow
2400 (let (out)
2401 (dolist (dep (package-desc-reqs pkg) out)
2402 (let ((dep-name (car dep)))
2403 (unless (eq 'emacs dep-name)
2404 (let ((cv (gethash dep-name package--compatibility-table)))
2405 (when (version-list-< (or cv '(0)) (or (cadr dep) '(0)))
2406 (push dep out)))))))))))
2408 (defun package-desc-status (pkg-desc)
2409 (let* ((name (package-desc-name pkg-desc))
2410 (dir (package-desc-dir pkg-desc))
2411 (lle (assq name package-load-list))
2412 (held (cadr lle))
2413 (version (package-desc-version pkg-desc))
2414 (signed (or (not package-list-unsigned)
2415 (package-desc-signed pkg-desc))))
2416 (cond
2417 ((eq dir 'builtin) "built-in")
2418 ((and lle (null held)) "disabled")
2419 ((stringp held)
2420 (let ((hv (if (stringp held) (version-to-list held))))
2421 (cond
2422 ((version-list-= version hv) "held")
2423 ((version-list-< version hv) "obsolete")
2424 (t "disabled"))))
2425 ((package-built-in-p name version) "obsolete")
2426 ((package--incompatible-p pkg-desc) "incompat")
2427 (dir ;One of the installed packages.
2428 (cond
2429 ((not (file-exists-p (package-desc-dir pkg-desc))) "deleted")
2430 ((eq pkg-desc (cadr (assq name package-alist)))
2431 (if (not signed) "unsigned"
2432 (if (package--user-selected-p name)
2433 "installed" "dependency")))
2434 (t "obsolete")))
2436 (let* ((ins (cadr (assq name package-alist)))
2437 (ins-v (if ins (package-desc-version ins))))
2438 (cond
2439 ((or (null ins) (version-list-< ins-v version))
2440 (if (memq name package-menu--new-package-list)
2441 "new" "available"))
2442 ((version-list-< version ins-v) "obsolete")
2443 ((version-list-= version ins-v)
2444 (if (not signed) "unsigned"
2445 (if (package--user-selected-p name)
2446 "installed" "dependency")))))))))
2448 (defun package-menu--refresh (&optional packages keywords)
2449 "Re-populate the `tabulated-list-entries'.
2450 PACKAGES should be nil or t, which means to display all known packages.
2451 KEYWORDS should be nil or a list of keywords."
2452 ;; Construct list of (PKG-DESC . STATUS).
2453 (unless packages (setq packages t))
2454 (let (info-list name)
2455 ;; Installed packages:
2456 (dolist (elt package-alist)
2457 (setq name (car elt))
2458 (when (or (eq packages t) (memq name packages))
2459 (dolist (pkg (cdr elt))
2460 (when (package--has-keyword-p pkg keywords)
2461 (package--push pkg (package-desc-status pkg) info-list)))))
2463 ;; Built-in packages:
2464 (dolist (elt package--builtins)
2465 (setq name (car elt))
2466 (when (and (not (eq name 'emacs)) ; Hide the `emacs' package.
2467 (package--has-keyword-p (package--from-builtin elt) keywords)
2468 (or package-list-unversioned
2469 (package--bi-desc-version (cdr elt)))
2470 (or (eq packages t) (memq name packages)))
2471 (package--push (package--from-builtin elt) "built-in" info-list)))
2473 ;; Available and disabled packages:
2474 (dolist (elt package-archive-contents)
2475 (setq name (car elt))
2476 (when (or (eq packages t) (memq name packages))
2477 (dolist (pkg (cdr elt))
2478 ;; Hide obsolete packages.
2479 (when (and (not (package-installed-p (package-desc-name pkg)
2480 (package-desc-version pkg)))
2481 (package--has-keyword-p pkg keywords))
2482 (package--push pkg (package-desc-status pkg) info-list)))))
2484 ;; Print the result.
2485 (setq tabulated-list-entries
2486 (mapcar #'package-menu--print-info info-list))))
2488 (defun package-all-keywords ()
2489 "Collect all package keywords"
2490 (let (keywords)
2491 (package--mapc (lambda (desc)
2492 (let* ((desc-keywords (and desc (package-desc--keywords desc))))
2493 (setq keywords (append keywords desc-keywords)))))
2494 keywords))
2496 (defun package--mapc (function &optional packages)
2497 "Call FUNCTION for all known PACKAGES.
2498 PACKAGES can be nil or t, which means to display all known
2499 packages, or a list of packages.
2501 Built-in packages are converted with `package--from-builtin'."
2502 (unless packages (setq packages t))
2503 (let (name)
2504 ;; Installed packages:
2505 (dolist (elt package-alist)
2506 (setq name (car elt))
2507 (when (or (eq packages t) (memq name packages))
2508 (mapc function (cdr elt))))
2510 ;; Built-in packages:
2511 (dolist (elt package--builtins)
2512 (setq name (car elt))
2513 (when (and (not (eq name 'emacs)) ; Hide the `emacs' package.
2514 (or package-list-unversioned
2515 (package--bi-desc-version (cdr elt)))
2516 (or (eq packages t) (memq name packages)))
2517 (funcall function (package--from-builtin elt))))
2519 ;; Available and disabled packages:
2520 (dolist (elt package-archive-contents)
2521 (setq name (car elt))
2522 (when (or (eq packages t) (memq name packages))
2523 (dolist (pkg (cdr elt))
2524 ;; Hide obsolete packages.
2525 (unless (package-installed-p (package-desc-name pkg)
2526 (package-desc-version pkg))
2527 (funcall function pkg)))))))
2529 (defun package--has-keyword-p (desc &optional keywords)
2530 "Test if package DESC has any of the given KEYWORDS.
2531 When none are given, the package matches."
2532 (if keywords
2533 (let* ((desc-keywords (and desc (package-desc--keywords desc)))
2534 found)
2535 (dolist (k keywords)
2536 (when (and (not found)
2537 (member k desc-keywords))
2538 (setq found t)))
2539 found)
2542 (defun package-menu--generate (remember-pos packages &optional keywords)
2543 "Populate the Package Menu.
2544 If REMEMBER-POS is non-nil, keep point on the same entry.
2545 PACKAGES should be t, which means to display all known packages,
2546 or a list of package names (symbols) to display.
2548 With KEYWORDS given, only packages with those keywords are
2549 shown."
2550 (package-menu--refresh packages keywords)
2551 (setf (car (aref tabulated-list-format 0))
2552 (if keywords
2553 (let ((filters (mapconcat 'identity keywords ",")))
2554 (concat "Package[" filters "]"))
2555 "Package"))
2556 (if keywords
2557 (define-key package-menu-mode-map "q" 'package-show-package-list)
2558 (define-key package-menu-mode-map "q" 'quit-window))
2559 (tabulated-list-init-header)
2560 (tabulated-list-print remember-pos))
2562 (defun package-menu--print-info (pkg)
2563 "Return a package entry suitable for `tabulated-list-entries'.
2564 PKG has the form (PKG-DESC . STATUS).
2565 Return (PKG-DESC [NAME VERSION STATUS DOC])."
2566 (let* ((pkg-desc (car pkg))
2567 (status (cdr pkg))
2568 (face (pcase status
2569 (`"built-in" 'font-lock-builtin-face)
2570 (`"available" 'default)
2571 (`"new" 'bold)
2572 (`"held" 'font-lock-constant-face)
2573 (`"disabled" 'font-lock-warning-face)
2574 (`"installed" 'font-lock-comment-face)
2575 (`"dependency" 'font-lock-comment-face)
2576 (`"unsigned" 'font-lock-warning-face)
2577 (`"incompat" 'font-lock-comment-face)
2578 (_ 'font-lock-warning-face)))) ; obsolete.
2579 (list pkg-desc
2580 `[,(list (symbol-name (package-desc-name pkg-desc))
2581 'face 'link
2582 'follow-link t
2583 'package-desc pkg-desc
2584 'action 'package-menu-describe-package)
2585 ,(propertize (package-version-join
2586 (package-desc-version pkg-desc))
2587 'font-lock-face face)
2588 ,(propertize status 'font-lock-face face)
2589 ,@(if (cdr package-archives)
2590 (list (propertize (or (package-desc-archive pkg-desc) "")
2591 'font-lock-face face)))
2592 ,(propertize (package-desc-summary pkg-desc)
2593 'font-lock-face face)])))
2595 (defun package-menu-refresh ()
2596 "Download the Emacs Lisp package archive.
2597 This fetches the contents of each archive specified in
2598 `package-archives', and then refreshes the package menu."
2599 (interactive)
2600 (unless (derived-mode-p 'package-menu-mode)
2601 (user-error "The current buffer is not a Package Menu"))
2602 (setq package-menu--old-archive-contents package-archive-contents)
2603 (setq package-menu--new-package-list nil)
2604 (package-refresh-contents package-menu-async))
2606 (defun package-menu-describe-package (&optional button)
2607 "Describe the current package.
2608 If optional arg BUTTON is non-nil, describe its associated package."
2609 (interactive)
2610 (let ((pkg-desc (if button (button-get button 'package-desc)
2611 (tabulated-list-get-id))))
2612 (if pkg-desc
2613 (describe-package pkg-desc)
2614 (user-error "No package here"))))
2616 ;; fixme numeric argument
2617 (defun package-menu-mark-delete (&optional _num)
2618 "Mark a package for deletion and move to the next line."
2619 (interactive "p")
2620 (if (member (package-menu-get-status)
2621 '("installed" "dependency" "obsolete" "unsigned"))
2622 (tabulated-list-put-tag "D" t)
2623 (forward-line)))
2625 (defun package-menu-mark-install (&optional _num)
2626 "Mark a package for installation and move to the next line."
2627 (interactive "p")
2628 (if (member (package-menu-get-status) '("available" "new" "dependency"))
2629 (tabulated-list-put-tag "I" t)
2630 (forward-line)))
2632 (defun package-menu-mark-unmark (&optional _num)
2633 "Clear any marks on a package and move to the next line."
2634 (interactive "p")
2635 (tabulated-list-put-tag " " t))
2637 (defun package-menu-backup-unmark ()
2638 "Back up one line and clear any marks on that package."
2639 (interactive)
2640 (forward-line -1)
2641 (tabulated-list-put-tag " "))
2643 (defun package-menu-mark-obsolete-for-deletion ()
2644 "Mark all obsolete packages for deletion."
2645 (interactive)
2646 (save-excursion
2647 (goto-char (point-min))
2648 (while (not (eobp))
2649 (if (equal (package-menu-get-status) "obsolete")
2650 (tabulated-list-put-tag "D" t)
2651 (forward-line 1)))))
2653 (defvar package--quick-help-keys
2654 '(("install," "delete," "unmark," ("execute" . 1))
2655 ("next," "previous")
2656 ("refresh-contents," "g-redisplay," "filter," "help")))
2658 (defun package--prettify-quick-help-key (desc)
2659 "Prettify DESC to be displayed as a help menu."
2660 (if (listp desc)
2661 (if (listp (cdr desc))
2662 (mapconcat #'package--prettify-quick-help-key desc " ")
2663 (let ((place (cdr desc))
2664 (out (car desc)))
2665 ;; (setq out (propertize out 'face 'paradox-comment-face))
2666 (add-text-properties place (1+ place)
2667 '(face (bold font-lock-function-name-face))
2668 out)
2669 out))
2670 (package--prettify-quick-help-key (cons desc 0))))
2672 (defun package-menu-quick-help ()
2673 "Show short key binding help for `package-menu-mode'.
2674 The full list of keys can be viewed with \\[describe-mode]."
2675 (interactive)
2676 (message (mapconcat #'package--prettify-quick-help-key
2677 package--quick-help-keys "\n")))
2679 (define-obsolete-function-alias
2680 'package-menu-view-commentary 'package-menu-describe-package "24.1")
2682 (defun package-menu-get-status ()
2683 (let* ((id (tabulated-list-get-id))
2684 (entry (and id (assq id tabulated-list-entries))))
2685 (if entry
2686 (aref (cadr entry) 2)
2687 "")))
2689 (defun package-archive-priority (archive)
2690 "Return the priority of ARCHIVE.
2692 The archive priorities are specified in
2693 `package-archive-priorities'. If not given there, the priority
2694 defaults to 0."
2695 (or (cdr (assoc archive package-archive-priorities))
2698 (defun package-desc-priority-version (pkg-desc)
2699 "Return the version PKG-DESC with the archive priority prepended.
2701 This allows for easy comparison of package versions from
2702 different archives if archive priorities are meant to be taken in
2703 consideration."
2704 (cons (package-archive-priority
2705 (package-desc-archive pkg-desc))
2706 (package-desc-version pkg-desc)))
2708 (defun package-menu--find-upgrades ()
2709 (let (installed available upgrades)
2710 ;; Build list of installed/available packages in this buffer.
2711 (dolist (entry tabulated-list-entries)
2712 ;; ENTRY is (PKG-DESC [NAME VERSION STATUS DOC])
2713 (let ((pkg-desc (car entry))
2714 (status (aref (cadr entry) 2)))
2715 (cond ((member status '("installed" "dependency" "unsigned"))
2716 (push pkg-desc installed))
2717 ((member status '("available" "new"))
2718 (setq available (package--append-to-alist pkg-desc available))))))
2719 ;; Loop through list of installed packages, finding upgrades.
2720 (dolist (pkg-desc installed)
2721 (let* ((name (package-desc-name pkg-desc))
2722 (avail-pkg (cadr (assq name available))))
2723 (and avail-pkg
2724 (version-list-< (package-desc-priority-version pkg-desc)
2725 (package-desc-priority-version avail-pkg))
2726 (push (cons name avail-pkg) upgrades))))
2727 upgrades))
2729 (defun package-menu-mark-upgrades ()
2730 "Mark all upgradable packages in the Package Menu.
2731 For each installed package with a newer version available, place
2732 an (I)nstall flag on the available version and a (D)elete flag on
2733 the installed version. A subsequent \\[package-menu-execute]
2734 call will upgrade the package."
2735 (interactive)
2736 (unless (derived-mode-p 'package-menu-mode)
2737 (error "The current buffer is not a Package Menu"))
2738 (let ((upgrades (package-menu--find-upgrades)))
2739 (if (null upgrades)
2740 (message "No packages to upgrade.")
2741 (widen)
2742 (save-excursion
2743 (goto-char (point-min))
2744 (while (not (eobp))
2745 (let* ((pkg-desc (tabulated-list-get-id))
2746 (upgrade (cdr (assq (package-desc-name pkg-desc) upgrades))))
2747 (cond ((null upgrade)
2748 (forward-line 1))
2749 ((equal pkg-desc upgrade)
2750 (package-menu-mark-install))
2752 (package-menu-mark-delete))))))
2753 (message "%d package%s marked for upgrading."
2754 (length upgrades)
2755 (if (= (length upgrades) 1) "" "s")))))
2757 (defun package-menu--list-to-prompt (packages)
2758 "Return a string listing PACKAGES that's usable in a prompt.
2759 PACKAGES is a list of `package-desc' objects.
2760 Formats the returned string to be usable in a minibuffer
2761 prompt (see `package-menu--prompt-transaction-p')."
2762 (cond
2763 ;; None
2764 ((not packages) "")
2765 ;; More than 1
2766 ((cdr packages)
2767 (format "these %d packages (%s)"
2768 (length packages)
2769 (mapconcat #'package-desc-full-name packages ", ")))
2770 ;; Exactly 1
2771 (t (format "package `%s'"
2772 (package-desc-full-name (car packages))))))
2774 (defun package-menu--prompt-transaction-p (install delete)
2775 "Prompt the user about installing INSTALL and deleting DELETE.
2776 INSTALL and DELETE are lists of `package-desc'. Either may be
2777 nil, but not both."
2778 (let* ((upg (cl-intersection install delete :key #'package-desc-name))
2779 (ins (cl-set-difference install upg :key #'package-desc-name))
2780 (del (cl-set-difference delete upg :key #'package-desc-name)))
2781 (y-or-n-p
2782 (concat
2783 (when del "Delete ")
2784 (package-menu--list-to-prompt del)
2785 (when (and del ins)
2786 (if upg "; " "; and "))
2787 (when ins "Install ")
2788 (package-menu--list-to-prompt ins)
2789 (when (and upg (or ins del)) "; and ")
2790 (when upg "Upgrade ")
2791 (package-menu--list-to-prompt upg)
2792 "? "))))
2794 (defun package-menu--perform-transaction (install-list delete-list &optional async)
2795 "Install packages in INSTALL-LIST and delete DELETE-LIST.
2796 If ASYNC is non-nil, perform the installation downloads
2797 asynchronously."
2798 ;; While there are packages to install, call `package-install' on
2799 ;; the next one and defer deletion to the callback function.
2800 (if install-list
2801 (let* ((pkg (car install-list))
2802 (rest (cdr install-list))
2803 ;; Don't mark as selected if it's a new version of an
2804 ;; installed package.
2805 (dont-mark (and (not (package-installed-p pkg))
2806 (package-installed-p
2807 (package-desc-name pkg)))))
2808 (package-install
2809 pkg dont-mark async
2810 (lambda () (package-menu--perform-transaction rest delete-list async))))
2811 ;; Once there are no more packages to install, proceed to
2812 ;; deletion.
2813 (let ((package--silence async))
2814 (dolist (elt (package--sort-by-dependence delete-list))
2815 (condition-case-unless-debug err
2816 (package-delete elt)
2817 (error (message (cadr err)))))
2818 (when package-selected-packages
2819 (when-let ((removable (package--removable-packages)))
2820 (package--message "These %d packages are no longer needed, type `M-x package-autoremove' to remove them (%s)"
2821 (length removable)
2822 (mapconcat #'symbol-name removable ", ")))))
2823 (message "Transaction done")
2824 (package-menu--post-refresh)))
2826 (defun package-menu-execute (&optional noquery)
2827 "Perform marked Package Menu actions.
2828 Packages marked for installation are downloaded and installed;
2829 packages marked for deletion are removed.
2830 Optional argument NOQUERY non-nil means do not ask the user to confirm."
2831 (interactive)
2832 (unless (derived-mode-p 'package-menu-mode)
2833 (error "The current buffer is not in Package Menu mode"))
2834 (let (install-list delete-list cmd pkg-desc)
2835 (save-excursion
2836 (goto-char (point-min))
2837 (while (not (eobp))
2838 (setq cmd (char-after))
2839 (unless (eq cmd ?\s)
2840 ;; This is the key PKG-DESC.
2841 (setq pkg-desc (tabulated-list-get-id))
2842 (cond ((eq cmd ?D)
2843 (push pkg-desc delete-list))
2844 ((eq cmd ?I)
2845 (push pkg-desc install-list))))
2846 (forward-line)))
2847 (unless (or delete-list install-list)
2848 (user-error "No operations specified"))
2849 (when (or noquery
2850 (package-menu--prompt-transaction-p install-list delete-list))
2851 (message "Transaction started")
2852 ;; This calls `package-menu--generate' after everything's done.
2853 (package-menu--perform-transaction
2854 install-list delete-list package-menu-async))))
2856 (defun package-menu--version-predicate (A B)
2857 (let ((vA (or (aref (cadr A) 1) '(0)))
2858 (vB (or (aref (cadr B) 1) '(0))))
2859 (if (version-list-= vA vB)
2860 (package-menu--name-predicate A B)
2861 (version-list-< vA vB))))
2863 (defun package-menu--status-predicate (A B)
2864 (let ((sA (aref (cadr A) 2))
2865 (sB (aref (cadr B) 2)))
2866 (cond ((string= sA sB)
2867 (package-menu--name-predicate A B))
2868 ((string= sA "new") t)
2869 ((string= sB "new") nil)
2870 ((string= sA "available") t)
2871 ((string= sB "available") nil)
2872 ((string= sA "installed") t)
2873 ((string= sB "installed") nil)
2874 ((string= sA "dependency") t)
2875 ((string= sB "dependency") nil)
2876 ((string= sA "unsigned") t)
2877 ((string= sB "unsigned") nil)
2878 ((string= sA "held") t)
2879 ((string= sB "held") nil)
2880 ((string= sA "built-in") t)
2881 ((string= sB "built-in") nil)
2882 ((string= sA "obsolete") t)
2883 ((string= sB "obsolete") nil)
2884 ((string= sA "incompat") t)
2885 ((string= sB "incompat") nil)
2886 (t (string< sA sB)))))
2888 (defun package-menu--description-predicate (A B)
2889 (let ((dA (aref (cadr A) 3))
2890 (dB (aref (cadr B) 3)))
2891 (if (string= dA dB)
2892 (package-menu--name-predicate A B)
2893 (string< dA dB))))
2895 (defun package-menu--name-predicate (A B)
2896 (string< (symbol-name (package-desc-name (car A)))
2897 (symbol-name (package-desc-name (car B)))))
2899 (defun package-menu--archive-predicate (A B)
2900 (string< (or (package-desc-archive (car A)) "")
2901 (or (package-desc-archive (car B)) "")))
2903 (defvar package-menu--old-archive-contents nil
2904 "`package-archive-contents' before the latest refresh.")
2906 (defun package-menu--populate-new-package-list ()
2907 "Decide which packages are new in `package-archives-contents'.
2908 Store this list in `package-menu--new-package-list'."
2909 ;; Find which packages are new.
2910 (when package-menu--old-archive-contents
2911 (dolist (elt package-archive-contents)
2912 (unless (assq (car elt) package-menu--old-archive-contents)
2913 (push (car elt) package-menu--new-package-list)))
2914 (setq package-menu--old-archive-contents nil)))
2916 (defun package-menu--find-and-notify-upgrades ()
2917 "Notify the user of upgradable packages."
2918 (when-let ((upgrades (package-menu--find-upgrades)))
2919 (message "%d package%s can be upgraded; type `%s' to mark %s for upgrading."
2920 (length upgrades)
2921 (if (= (length upgrades) 1) "" "s")
2922 (substitute-command-keys "\\[package-menu-mark-upgrades]")
2923 (if (= (length upgrades) 1) "it" "them"))))
2925 (defun package-menu--post-refresh ()
2926 "Check for new packages, revert the *Packages* buffer, and check for upgrades.
2927 This function is called after `package-refresh-contents' and
2928 after `package-menu--perform-transaction'."
2929 (package-menu--populate-new-package-list)
2930 (let ((buf (get-buffer "*Packages*")))
2931 (when (buffer-live-p buf)
2932 (with-current-buffer buf
2933 (revert-buffer nil 'noconfirm))))
2934 (package-menu--find-and-notify-upgrades))
2936 (defcustom package-menu-async t
2937 "If non-nil, package-menu will use async operations when possible.
2938 This includes refreshing archive contents as well as installing
2939 packages."
2940 :type 'boolean
2941 :group 'package)
2943 ;;;###autoload
2944 (defun list-packages (&optional no-fetch)
2945 "Display a list of packages.
2946 This first fetches the updated list of packages before
2947 displaying, unless a prefix argument NO-FETCH is specified.
2948 The list is displayed in a buffer named `*Packages*'."
2949 (interactive "P")
2950 (require 'finder-inf nil t)
2951 ;; Initialize the package system if necessary.
2952 (unless package--initialized
2953 (package-initialize t))
2954 ;; Integrate the package-menu with updating the archives.
2955 (add-hook 'package--post-download-archives-hook
2956 #'package-menu--post-refresh)
2958 ;; Generate the Package Menu.
2959 (let ((buf (get-buffer-create "*Packages*")))
2960 (with-current-buffer buf
2961 (package-menu-mode)
2963 ;; Fetch the remote list of packages.
2964 (unless no-fetch (package-menu-refresh))
2966 ;; If we're not async, this would be redundant.
2967 (when package-menu-async
2968 (package-menu--generate nil t)))
2969 ;; The package menu buffer has keybindings. If the user types
2970 ;; `M-x list-packages', that suggests it should become current.
2971 (switch-to-buffer buf)))
2973 ;;;###autoload
2974 (defalias 'package-list-packages 'list-packages)
2976 ;; Used in finder.el
2977 (defun package-show-package-list (&optional packages keywords)
2978 "Display PACKAGES in a *Packages* buffer.
2979 This is similar to `list-packages', but it does not fetch the
2980 updated list of packages, and it only displays packages with
2981 names in PACKAGES (which should be a list of symbols).
2983 When KEYWORDS are given, only packages with those KEYWORDS are
2984 shown."
2985 (interactive)
2986 (require 'finder-inf nil t)
2987 (let* ((buf (get-buffer-create "*Packages*"))
2988 (win (get-buffer-window buf)))
2989 (with-current-buffer buf
2990 (package-menu-mode)
2991 (package-menu--generate nil packages keywords))
2992 (if win
2993 (select-window win)
2994 (switch-to-buffer buf))))
2996 ;; package-menu--generate rebinds "q" on the fly, so we have to
2997 ;; hard-code the binding in the doc-string here.
2998 (defun package-menu-filter (keyword)
2999 "Filter the *Packages* buffer.
3000 Show only those items that relate to the specified KEYWORD.
3001 To restore the full package list, type `q'."
3002 (interactive (list (completing-read "Keyword: " (package-all-keywords))))
3003 (package-show-package-list t (list keyword)))
3005 (defun package-list-packages-no-fetch ()
3006 "Display a list of packages.
3007 Does not fetch the updated list of packages before displaying.
3008 The list is displayed in a buffer named `*Packages*'."
3009 (interactive)
3010 (list-packages t))
3012 (provide 'package)
3014 ;;; package.el ends here