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
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/>.
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
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
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:
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
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.
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>
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>
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
140 ;; - Interface with desktop.el so that restarting after an install
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
152 ;; - Allow multiple versions on the server...?
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
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
)
171 (defgroup package nil
172 "Manager for Emacs Lisp packages."
177 (defcustom package-enable-at-startup t
178 "Whether to activate installed packages when Emacs starts.
179 If non-nil, packages are activated after reading the init file
180 and before `after-init-hook'. Activation is not done if
181 `user-init-file' is nil (e.g. Emacs was started with \"-q\").
183 Even if the value is nil, you can type \\[package-initialize] to
184 activate the package system at any time."
189 (defcustom package-load-list
'(all)
190 "List of packages for `package-initialize' to load.
191 Each element in this list should be a list (NAME VERSION), or the
192 symbol `all'. The symbol `all' says to load the latest installed
193 versions of all packages not specified by other elements.
195 For an element (NAME VERSION), NAME is a package name (a symbol).
196 VERSION should be t, a string, or nil.
197 If VERSION is t, the most recent version is activated.
198 If VERSION is a string, only that version is ever loaded.
199 Any other version, even if newer, is silently ignored.
200 Hence, the package is \"held\" at that version.
201 If VERSION is nil, the package is not loaded (it is \"disabled\")."
202 :type
'(repeat symbol
)
207 (defvar Info-directory-list
)
208 (declare-function info-initialize
"info" ())
209 (declare-function url-http-file-exists-p
"url-http" (url))
210 (declare-function lm-header
"lisp-mnt" (header))
211 (declare-function lm-commentary
"lisp-mnt" (&optional file
))
213 (defcustom package-archives
'(("gnu" .
"http://elpa.gnu.org/packages/"))
214 "An alist of archives from which to fetch.
215 The default value points to the GNU Emacs package repository.
217 Each element has the form (ID . LOCATION).
218 ID is an archive name, as a string.
219 LOCATION specifies the base location for the archive.
220 If it starts with \"http:\", it is treated as a HTTP URL;
221 otherwise it should be an absolute directory name.
222 (Other types of URL are currently not supported.)
224 Only add locations that you trust, since fetching and installing
225 a package can run arbitrary code."
226 :type
'(alist :key-type
(string :tag
"Archive name")
227 :value-type
(string :tag
"URL or directory name"))
232 (defcustom package-archive-priorities nil
233 "An alist of priorities for packages.
235 Each element has the form (ARCHIVE-ID . PRIORITY).
237 When installing packages, the package with the highest version
238 number from the archive with the highest priority is
239 selected. When higher versions are available from archives with
240 lower priorities, the user has to select those manually.
242 Archives not in this list have the priority 0."
243 :type
'(alist :key-type
(string :tag
"Archive name")
244 :value-type
(integer :tag
"Priority (default is 0)"))
249 (defcustom package-pinned-packages nil
250 "An alist of packages that are pinned to specific archives.
251 This can be useful if you have multiple package archives enabled,
252 and want to control which archive a given package gets installed from.
254 Each element of the alist has the form (PACKAGE . ARCHIVE), where:
255 PACKAGE is a symbol representing a package
256 ARCHIVE is a string representing an archive (it should be the car of
257 an element in `package-archives', e.g. \"gnu\").
259 Adding an entry to this variable means that only ARCHIVE will be
260 considered as a source for PACKAGE. If other archives provide PACKAGE,
261 they are ignored (for this package). If ARCHIVE does not contain PACKAGE,
262 the package will be unavailable."
263 :type
'(alist :key-type
(symbol :tag
"Package")
264 :value-type
(string :tag
"Archive name"))
265 ;; I don't really see why this is risky...
266 ;; I suppose it could prevent you receiving updates for a package,
267 ;; via an entry (PACKAGE . NON-EXISTING). Which could be an issue
268 ;; if PACKAGE has a known vulnerability that is fixed in newer versions.
273 (defconst package-archive-version
1
274 "Version number of the package archive understood by this file.
275 Lower version numbers than this will probably be understood as well.")
277 ;; We don't prime the cache since it tends to get out of date.
278 (defvar package-archive-contents nil
279 "Cache of the contents of the Emacs Lisp Package Archive.
280 This is an alist mapping package names (symbols) to
281 non-empty lists of `package-desc' structures.")
282 (put 'package-archive-contents
'risky-local-variable t
)
284 (defcustom package-user-dir
(locate-user-emacs-file "elpa")
285 "Directory containing the user's Emacs Lisp packages.
286 The directory name should be absolute.
287 Apart from this directory, Emacs also looks for system-wide
288 packages in `package-directory-list'."
294 (defcustom package-directory-list
295 ;; Defaults are subdirs named "elpa" in the site-lisp dirs.
297 (dolist (f load-path
)
299 (equal (file-name-nondirectory f
) "site-lisp")
300 (push (expand-file-name "elpa" f
) result
)))
302 "List of additional directories containing Emacs Lisp packages.
303 Each directory name should be absolute.
305 These directories contain packages intended for system-wide; in
306 contrast, `package-user-dir' contains packages for personal use."
307 :type
'(repeat directory
)
312 (defvar epg-gpg-program
)
314 (defcustom package-check-signature
315 (if (progn (require 'epg-config
) (executable-find epg-gpg-program
))
317 "Non-nil means to check package signatures when installing.
318 The value `allow-unsigned' means to still install a package even if
321 This also applies to the \"archive-contents\" file that lists the
322 contents of the archive."
323 :type
'(choice (const nil
:tag
"Never")
324 (const allow-unsigned
:tag
"Allow unsigned")
325 (const t
:tag
"Check always"))
330 (defcustom package-unsigned-archives nil
331 "List of archives where we do not check for package signatures."
332 :type
'(repeat (string :tag
"Archive name"))
337 (defcustom package-selected-packages nil
338 "Store here packages installed explicitely by user.
339 This variable will be feeded automatically by emacs,
340 when installing a new package.
341 This variable will be used by `package-autoremove' to decide
342 which packages are no more needed.
343 You can use it to (re)install packages on other machines
344 by running `package-user-selected-packages-install'.
346 To check if a package is contained in this list here, use
347 `package--user-selected-p', as it may populate the variable with
348 a sane initial value."
350 :type
'(repeat symbol
))
352 (defvar package--default-summary
"No description available.")
354 (cl-defstruct (package-desc
355 ;; Rename the default constructor from `make-package-desc'.
356 (:constructor package-desc-create
)
357 ;; Has the same interface as the old `define-package',
358 ;; which is still used in the "foo-pkg.el" files. Extra
359 ;; options can be supported by adding additional keys.
361 package-desc-from-define
362 (name-string version-string
&optional summary requirements
365 (name (intern name-string
))
366 (version (version-to-list version-string
))
367 (reqs (mapcar #'(lambda (elt)
369 (version-to-list (cadr elt
))))
370 (if (eq 'quote
(car requirements
))
373 (kind (plist-get rest-plist
:kind
))
374 (archive (plist-get rest-plist
:archive
))
377 (unless (memq (car rest-plist
) '(:kind
:archive
))
378 (let ((value (cadr rest-plist
)))
380 (push (cons (car rest-plist
)
381 (if (eq (car-safe value
) 'quote
)
385 (setq rest-plist
(cddr rest-plist
)))
387 "Structure containing information about an individual package.
390 `name' Name of the package, as a symbol.
392 `version' Version of the package, as a version list.
394 `summary' Short description of the package, typically taken from
395 the first line of the file.
397 `reqs' Requirements of the package. A list of (PACKAGE
398 VERSION-LIST) naming the dependent package and the minimum
401 `kind' The distribution format of the package. Currently, it is
402 either `single' or `tar'.
404 `archive' The name of the archive (as a string) whence this
407 `dir' The directory where the package is installed (if installed),
408 `builtin' if it is built-in, or nil otherwise.
410 `extras' Optional alist of additional keyword-value pairs.
412 `signed' Flag to indicate that the package is signed by provider."
415 (summary package--default-summary
)
424 (defun package-desc-full-name (pkg-desc)
426 (package-desc-name pkg-desc
)
427 (package-version-join (package-desc-version pkg-desc
))))
429 (defun package-desc-suffix (pkg-desc)
430 (pcase (package-desc-kind pkg-desc
)
434 (kind (error "Unknown package kind: %s" kind
))))
436 (defun package-desc--keywords (pkg-desc)
437 (let ((keywords (cdr (assoc :keywords
(package-desc-extras pkg-desc
)))))
438 (if (eq (car-safe keywords
) 'quote
)
442 ;; Package descriptor format used in finder-inf.el and package--builtins.
443 (cl-defstruct (package--bi-desc
444 (:constructor package-make-builtin
(version summary
))
450 (defvar package--builtins nil
451 "Alist of built-in packages.
452 The actual value is initialized by loading the library
453 `finder-inf'; this is not done until it is needed, e.g. by the
454 function `package-built-in-p'.
456 Each element has the form (PKG . PACKAGE-BI-DESC), where PKG is a package
457 name (a symbol) and DESC is a `package--bi-desc' structure.")
458 (put 'package--builtins
'risky-local-variable t
)
460 (defvar package-alist nil
461 "Alist of all packages available for activation.
462 Each element has the form (PKG . DESCS), where PKG is a package
463 name (a symbol) and DESCS is a non-empty list of `package-desc' structure,
464 sorted by decreasing versions.
466 This variable is set automatically by `package-load-descriptor',
467 called via `package-initialize'. To change which packages are
468 loaded and/or activated, customize `package-load-list'.")
469 (put 'package-alist
'risky-local-variable t
)
471 (defvar package--compatibility-table nil
472 "Hash table connecting package names to their compatibility.
473 Each key is a symbol, the name of a package.
475 The value is either nil, representing an incompatible package, or
476 a version list, representing the highest compatible version of
477 that package which is available.
479 A package is considered incompatible if it requires an Emacs
480 version higher than the one being used. To check for package
481 \(in)compatibility, don't read this table directly, use
482 `package--incompatible-p' which also checks dependencies.")
484 (defvar package-activated-list nil
485 ;; FIXME: This should implicitly include all builtin packages.
486 "List of the names of currently activated packages.")
487 (put 'package-activated-list
'risky-local-variable t
)
489 (defun package-version-join (vlist)
490 "Return the version string corresponding to the list VLIST.
491 This is, approximately, the inverse of `version-to-list'.
492 \(Actually, it returns only one of the possible inverses, since
493 `version-to-list' is a many-to-one operation.)"
496 (let ((str-list (list "." (int-to-string (car vlist
)))))
497 (dolist (num (cdr vlist
))
500 (push (int-to-string num
) str-list
)
503 (error "Invalid version list `%s'" vlist
))
505 ;; pre, or beta, or alpha
506 (cond ((equal "." (car str-list
))
508 ((not (string-match "[0-9]+" (car str-list
)))
509 (error "Invalid version list `%s'" vlist
)))
510 (push (cond ((= num -
1) "pre")
513 ((= num -
4) "snapshot"))
515 (if (equal "." (car str-list
))
517 (apply 'concat
(nreverse str-list
)))))
519 (defun package-load-descriptor (pkg-dir)
520 "Load the description file in directory PKG-DIR."
521 (let ((pkg-file (expand-file-name (package--description-file pkg-dir
)
523 (signed-file (concat pkg-dir
".signed")))
524 (when (file-exists-p pkg-file
)
526 (insert-file-contents pkg-file
)
527 (goto-char (point-min))
528 (let ((pkg-desc (package-process-define-package
529 (read (current-buffer)) pkg-file
)))
530 (setf (package-desc-dir pkg-desc
) pkg-dir
)
531 (if (file-exists-p signed-file
)
532 (setf (package-desc-signed pkg-desc
) t
))
535 (defun package-load-all-descriptors ()
536 "Load descriptors for installed Emacs Lisp packages.
537 This looks for package subdirectories in `package-user-dir' and
538 `package-directory-list'. The variable `package-load-list'
539 controls which package subdirectories may be loaded.
541 In each valid package subdirectory, this function loads the
542 description file containing a call to `define-package', which
543 updates `package-alist'."
544 (dolist (dir (cons package-user-dir package-directory-list
))
545 (when (file-directory-p dir
)
546 (dolist (subdir (directory-files dir
))
547 (let ((pkg-dir (expand-file-name subdir dir
)))
548 (when (file-directory-p pkg-dir
)
549 (package-load-descriptor pkg-dir
)))))))
551 (defun package-disabled-p (pkg-name version
)
552 "Return whether PKG-NAME at VERSION can be activated.
553 The decision is made according to `package-load-list'.
554 Return nil if the package can be activated.
555 Return t if the package is completely disabled.
556 Return the max version (as a string) if the package is held at a lower version."
557 (let ((force (assq pkg-name package-load-list
)))
558 (cond ((null force
) (not (memq 'all package-load-list
)))
559 ((null (setq force
(cadr force
))) t
) ; disabled
561 ((stringp force
) ; held
562 (unless (version-list-= version
(version-to-list force
))
564 (t (error "Invalid element in `package-load-list'")))))
566 (defun package-activate-1 (pkg-desc &optional reload
)
567 "Activate package given by PKG-DESC, even if it was already active.
568 If RELOAD is non-nil, also `load' any files inside the package which
569 correspond to previously loaded files (those returned by
570 `package--list-loaded-files')."
571 (let* ((name (package-desc-name pkg-desc
))
572 (pkg-dir (package-desc-dir pkg-desc
))
573 (pkg-dir-dir (file-name-as-directory pkg-dir
)))
575 (error "Internal error: unable to find directory for `%s'"
576 (package-desc-full-name pkg-desc
)))
577 ;; Add to load path, add autoloads, and activate the package.
578 (let* ((old-lp load-path
)
579 (autoloads-file (expand-file-name
580 (format "%s-autoloads" name
) pkg-dir
))
581 (loaded-files-list (and reload
(package--list-loaded-files pkg-dir
))))
582 (with-demoted-errors "Error in package-activate-1: %s"
583 (load autoloads-file nil t
))
584 (when (and (eq old-lp load-path
)
585 (not (or (member pkg-dir load-path
)
586 (member pkg-dir-dir load-path
))))
587 ;; Old packages don't add themselves to the `load-path', so we have to
589 (push pkg-dir load-path
))
590 ;; Call `load' on all files in `pkg-dir' already present in
591 ;; `load-history'. This is done so that macros in these files are updated
592 ;; to their new definitions. If another package is being installed which
593 ;; depends on this new definition, not doing this update would cause
594 ;; compilation errors and break the installation.
595 (with-demoted-errors "Error in package-activate-1: %s"
596 (mapc (lambda (feature) (load feature nil t
))
597 ;; Skip autoloads file since we already evaluated it above.
598 (remove (file-truename autoloads-file
) loaded-files-list
))))
600 (when (file-exists-p (expand-file-name "dir" pkg-dir
))
601 ;; FIXME: not the friendliest, but simple.
604 (push pkg-dir Info-directory-list
))
605 (push name package-activated-list
)
609 (declare-function find-library-name
"find-func" (library))
610 (defun package--list-loaded-files (dir)
611 "Recursively list all files in DIR which correspond to loaded features.
612 Returns the `file-name-sans-extension' of each file, relative to
613 DIR, sorted by most recently loaded last."
614 (let* ((history (delq nil
617 (and f
(file-name-sans-extension f
))))
619 (dir (file-truename dir
))
620 ;; List all files that have already been loaded.
625 (lambda (x) (let* ((file (file-relative-name x dir
))
626 ;; Previously loaded file, if any.
629 (file-name-sans-extension
630 (file-truename (find-library-name file
)))))
631 (pos (when previous
(member previous history
))))
632 ;; Return (RELATIVE-FILENAME . HISTORY-POSITION)
634 (cons (file-name-sans-extension file
) (length pos
)))))
635 (directory-files-recursively dir
"\\`[^\\.].*\\.el\\'")))))
636 ;; Turn the list of (FILENAME . POS) back into a list of features. Files in
637 ;; subdirectories are returned relative to DIR (so not actually features).
638 (let ((default-directory (file-name-as-directory dir
)))
639 (mapcar (lambda (x) (file-truename (car x
)))
640 (sort list-of-conflicts
641 ;; Sort the files by ascending HISTORY-POSITION.
642 (lambda (x y
) (< (cdr x
) (cdr y
))))))))
644 (defun package-built-in-p (package &optional min-version
)
645 "Return true if PACKAGE is built-in to Emacs.
646 Optional arg MIN-VERSION, if non-nil, should be a version list
647 specifying the minimum acceptable version."
648 (if (package-desc-p package
) ;; was built-in and then was converted
649 (eq 'builtin
(package-desc-dir package
))
650 (let ((bi (assq package package--builtin-versions
)))
652 (bi (version-list-<= min-version
(cdr bi
)))
653 ((remove 0 min-version
) nil
)
655 (require 'finder-inf nil t
) ; For `package--builtins'.
656 (assq package package--builtins
))))))
658 (defun package--from-builtin (bi-desc)
659 (package-desc-create :name
(pop bi-desc
)
660 :version
(package--bi-desc-version bi-desc
)
661 :summary
(package--bi-desc-summary bi-desc
)
664 ;; This function goes ahead and activates a newer version of a package
665 ;; if an older one was already activated. This is not ideal; we'd at
666 ;; least need to check to see if the package has actually been loaded,
667 ;; and not merely activated.
668 (defun package-activate (package &optional force
)
669 "Activate package PACKAGE.
670 If FORCE is true, (re-)activate it if it's already activated."
671 (let ((pkg-descs (cdr (assq package package-alist
))))
672 ;; Check if PACKAGE is available in `package-alist'.
675 (let ((available-version (package-desc-version (car pkg-descs
))))
676 (or (package-disabled-p package available-version
)
677 ;; Prefer a builtin package.
678 (package-built-in-p package available-version
))))
679 (setq pkg-descs
(cdr pkg-descs
)))
681 ;; If no such package is found, maybe it's built-in.
683 (package-built-in-p package
))
684 ;; If the package is already activated, just return t.
685 ((and (memq package package-activated-list
) (not force
))
687 ;; Otherwise, proceed with activation.
689 (let* ((pkg-vec (car pkg-descs
))
690 (fail (catch 'dep-failure
691 ;; Activate its dependencies recursively.
692 (dolist (req (package-desc-reqs pkg-vec
))
693 (unless (package-activate (car req
))
694 (throw 'dep-failure req
))))))
696 (warn "Unable to activate package `%s'.
697 Required package `%s-%s' is unavailable"
698 package
(car fail
) (package-version-join (cadr fail
)))
699 ;; If all goes well, activate the package itself.
700 (package-activate-1 pkg-vec force
)))))))
702 (defun define-package (_name-string _version-string
703 &optional _docstring _requirements
704 &rest _extra-properties
)
705 "Define a new package.
706 NAME-STRING is the name of the package, as a string.
707 VERSION-STRING is the version of the package, as a string.
708 DOCSTRING is a short description of the package, a string.
709 REQUIREMENTS is a list of dependencies on other packages.
710 Each requirement is of the form (OTHER-PACKAGE OTHER-VERSION),
711 where OTHER-VERSION is a string.
713 EXTRA-PROPERTIES is currently unused."
714 ;; FIXME: Placeholder! Should we keep it?
715 (error "Don't call me!"))
717 (defun package-process-define-package (exp origin
)
718 (unless (eq (car-safe exp
) 'define-package
)
719 (error "Can't find define-package in %s" origin
))
720 (let* ((new-pkg-desc (apply #'package-desc-from-define
(cdr exp
)))
721 (name (package-desc-name new-pkg-desc
))
722 (version (package-desc-version new-pkg-desc
))
723 (old-pkgs (assq name package-alist
)))
725 ;; If there's no old package, just add this to `package-alist'.
726 (push (list name new-pkg-desc
) package-alist
)
727 ;; If there is, insert the new package at the right place in the list.
729 (if (and (cdr old-pkgs
)
730 (version-list-< version
731 (package-desc-version (cadr old-pkgs
))))
732 (setq old-pkgs
(cdr old-pkgs
))
733 (push new-pkg-desc
(cdr old-pkgs
))
737 ;; From Emacs 22, but changed so it adds to load-path.
738 (defun package-autoload-ensure-default-file (file)
739 "Make sure that the autoload file FILE exists and if not create it."
740 (unless (file-exists-p file
)
742 (concat ";;; " (file-name-nondirectory file
)
743 " --- automatically extracted autoloads\n"
746 "(add-to-list 'load-path (or (file-name-directory #$) (car load-path)))\n"
747 "\f\n;; Local Variables:\n"
748 ";; version-control: never\n"
749 ";; no-byte-compile: t\n"
750 ";; no-update-autoloads: t\n"
752 ";;; " (file-name-nondirectory file
)
754 nil file nil
'silent
))
757 (defvar generated-autoload-file
)
758 (defvar version-control
)
760 (defun package-generate-autoloads (name pkg-dir
)
761 (let* ((auto-name (format "%s-autoloads.el" name
))
762 ;;(ignore-name (concat name "-pkg.el"))
763 (generated-autoload-file (expand-file-name auto-name pkg-dir
))
765 (version-control 'never
))
766 (package-autoload-ensure-default-file generated-autoload-file
)
767 (update-directory-autoloads pkg-dir
)
768 (let ((buf (find-buffer-visiting generated-autoload-file
)))
769 (when buf
(kill-buffer buf
)))
772 (defvar tar-parse-info
)
773 (declare-function tar-untar-buffer
"tar-mode" ())
774 (declare-function tar-header-name
"tar-mode" (tar-header) t
)
775 (declare-function tar-header-link-type
"tar-mode" (tar-header) t
)
777 (defun package-untar-buffer (dir)
778 "Untar the current buffer.
779 This uses `tar-untar-buffer' from Tar mode. All files should
780 untar into a directory named DIR; otherwise, signal an error."
783 ;; Make sure everything extracts into DIR.
784 (let ((regexp (concat "\\`" (regexp-quote (expand-file-name dir
)) "/"))
785 (case-fold-search (memq system-type
'(windows-nt ms-dos cygwin
))))
786 (dolist (tar-data tar-parse-info
)
787 (let ((name (expand-file-name (tar-header-name tar-data
))))
788 (or (string-match regexp name
)
789 ;; Tarballs created by some utilities don't list
790 ;; directories with a trailing slash (Bug#13136).
791 (and (string-equal dir name
)
792 (eq (tar-header-link-type tar-data
) 5))
793 (error "Package does not untar cleanly into directory %s/" dir
)))))
796 (defun package-generate-description-file (pkg-desc pkg-file
)
797 "Create the foo-pkg.el file for single-file packages."
798 (let* ((name (package-desc-name pkg-desc
)))
799 (let ((print-level nil
)
804 ";;; -*- no-byte-compile: t -*-\n"
807 (list 'define-package
809 (package-version-join (package-desc-version pkg-desc
))
810 (package-desc-summary pkg-desc
)
811 (let ((requires (package-desc-reqs pkg-desc
)))
813 ;; Turn version lists into string form.
817 (package-version-join (cadr elt
))))
819 (package--alist-to-plist-args
820 (package-desc-extras pkg-desc
))))
822 nil pkg-file nil
'silent
))))
824 (defun package--alist-to-plist-args (alist)
825 (mapcar 'macroexp-quote
827 (mapcar (lambda (pair) (list (car pair
) (cdr pair
))) alist
))))
828 (defun package-unpack (pkg-desc)
829 "Install the contents of the current buffer as a package."
830 (let* ((name (package-desc-name pkg-desc
))
831 (dirname (package-desc-full-name pkg-desc
))
832 (pkg-dir (expand-file-name dirname package-user-dir
)))
833 (pcase (package-desc-kind pkg-desc
)
835 (make-directory pkg-dir t
)
838 default-directory
'full
"\\`[^.].*\\.el\\'" 'nosort
)))
839 (dolist (source-file file-list
)
840 (let ((target-el-file
841 (expand-file-name (file-name-nondirectory source-file
) pkg-dir
)))
842 (copy-file source-file target-el-file t
)))
843 ;; Now that the files have been installed, this package is
844 ;; indistinguishable from a `tar' or a `single'. Let's make
845 ;; things simple by ensuring we're one of them.
846 (setf (package-desc-kind pkg-desc
)
847 (if (> (length file-list
) 1) 'tar
'single
))))
849 (make-directory package-user-dir t
)
850 ;; FIXME: should we delete PKG-DIR if it exists?
851 (let* ((default-directory (file-name-as-directory package-user-dir
)))
852 (package-untar-buffer dirname
)))
854 (let ((el-file (expand-file-name (format "%s.el" name
) pkg-dir
)))
855 (make-directory pkg-dir t
)
856 (package--write-file-no-coding el-file
)))
857 (kind (error "Unknown package kind: %S" kind
)))
858 (package--make-autoloads-and-stuff pkg-desc pkg-dir
)
859 ;; Update package-alist.
860 (let ((new-desc (package-load-descriptor pkg-dir
)))
861 ;; FIXME: Check that `new-desc' matches `desc'!
862 ;; FIXME: Compilation should be done as a separate, optional, step.
863 ;; E.g. for multi-package installs, we should first install all packages
864 ;; and then compile them.
865 (package--compile new-desc
))
866 ;; Try to activate it.
867 (package-activate name
'force
)
870 (defun package--make-autoloads-and-stuff (pkg-desc pkg-dir
)
871 "Generate autoloads, description file, etc.. for PKG-DESC installed at PKG-DIR."
872 (package-generate-autoloads (package-desc-name pkg-desc
) pkg-dir
)
873 (let ((desc-file (expand-file-name (package--description-file pkg-dir
)
875 (unless (file-exists-p desc-file
)
876 (package-generate-description-file pkg-desc desc-file
)))
877 ;; FIXME: Create foo.info and dir file from foo.texi?
880 (defun package--compile (pkg-desc)
881 "Byte-compile installed package PKG-DESC."
882 (package-activate-1 pkg-desc
)
883 (byte-recompile-directory (package-desc-dir pkg-desc
) 0 t
))
885 (defun package--write-file-no-coding (file-name)
886 (let ((buffer-file-coding-system 'no-conversion
))
887 (write-region (point-min) (point-max) file-name nil
'silent
)))
889 (defmacro package--with-work-buffer
(location file
&rest body
)
890 "Run BODY in a buffer containing the contents of FILE at LOCATION.
891 LOCATION is the base location of a package archive, and should be
892 one of the URLs (or file names) specified in `package-archives'.
893 FILE is the name of a file relative to that base location.
895 This macro retrieves FILE from LOCATION into a temporary buffer,
896 and evaluates BODY while that buffer is current. This work
897 buffer is killed afterwards. Return the last value in BODY."
898 (declare (indent 2) (debug t
))
900 (if (string-match-p "\\`https?:" ,location
)
901 (url-insert-file-contents (concat ,location
,file
))
902 (unless (file-name-absolute-p ,location
)
903 (error "Archive location %s is not an absolute file name"
905 (insert-file-contents (expand-file-name ,file
,location
)))
908 (defun package--archive-file-exists-p (location file
)
909 (let ((http (string-match "\\`https?:" location
)))
913 (url-http-file-exists-p (concat location file
)))
914 (file-exists-p (expand-file-name file location
)))))
916 (declare-function epg-make-context
"epg"
917 (&optional protocol armor textmode include-certs
921 (declare-function epg-verify-string
"epg" (context signature
922 &optional signed-text
))
923 (declare-function epg-context-result-for
"epg" (context name
))
924 (declare-function epg-signature-status
"epg" (signature))
925 (declare-function epg-signature-to-string
"epg" (signature))
927 (defun package--display-verify-error (context sig-file
)
928 (unless (equal (epg-context-error-output context
) "")
929 (with-output-to-temp-buffer "*Error*"
930 (with-current-buffer standard-output
931 (if (epg-context-result-for context
'verify
)
932 (insert (format "Failed to verify signature %s:\n" sig-file
)
933 (mapconcat #'epg-signature-to-string
934 (epg-context-result-for context
'verify
)
936 (insert (format "Error while verifying signature %s:\n" sig-file
)))
937 (insert "\nCommand output:\n" (epg-context-error-output context
))))))
939 (defun package--check-signature (location file
)
940 "Check signature of the current buffer.
941 GnuPG keyring is located under \"gnupg\" in `package-user-dir'."
942 (let* ((context (epg-make-context 'OpenPGP
))
943 (homedir (expand-file-name "gnupg" package-user-dir
))
944 (sig-file (concat file
".sig"))
945 (sig-content (package--with-work-buffer location sig-file
947 (setf (epg-context-home-directory context
) homedir
)
948 (condition-case error
949 (epg-verify-string context sig-content
(buffer-string))
951 (package--display-verify-error context sig-file
)
952 (signal (car error
) (cdr error
))))
953 (let (good-signatures had-fatal-error
)
954 ;; The .sig file may contain multiple signatures. Success if one
955 ;; of the signatures is good.
956 (dolist (sig (epg-context-result-for context
'verify
))
957 (if (eq (epg-signature-status sig
) 'good
)
958 (push sig good-signatures
)
959 ;; If package-check-signature is allow-unsigned, don't
960 ;; signal error when we can't verify signature because of
961 ;; missing public key. Other errors are still treated as
962 ;; fatal (bug#17625).
963 (unless (and (eq package-check-signature
'allow-unsigned
)
964 (eq (epg-signature-status sig
) 'no-pubkey
))
965 (setq had-fatal-error t
))))
966 (when (and (null good-signatures
) had-fatal-error
)
967 (package--display-verify-error context sig-file
)
968 (error "Failed to verify signature %s" sig-file
))
971 (defun package-install-from-archive (pkg-desc)
972 "Download and install a tar package."
973 ;; This won't happen, unless the archive is doing something wrong.
974 (when (eq (package-desc-kind pkg-desc
) 'dir
)
975 (error "Can't install directory package from archive"))
976 (let* ((location (package-archive-base pkg-desc
))
977 (file (concat (package-desc-full-name pkg-desc
)
978 (package-desc-suffix pkg-desc
)))
979 (sig-file (concat file
".sig"))
980 good-signatures pkg-descs
)
981 (package--with-work-buffer location file
982 (if (and package-check-signature
983 (not (member (package-desc-archive pkg-desc
)
984 package-unsigned-archives
)))
985 (if (package--archive-file-exists-p location sig-file
)
986 (setq good-signatures
(package--check-signature location file
))
987 (unless (eq package-check-signature
'allow-unsigned
)
988 (error "Unsigned package: `%s'"
989 (package-desc-name pkg-desc
)))))
990 (package-unpack pkg-desc
))
991 ;; Here the package has been installed successfully, mark it as
992 ;; signed if appropriate.
993 (when good-signatures
994 ;; Write out good signatures into NAME-VERSION.signed file.
995 (write-region (mapconcat #'epg-signature-to-string good-signatures
"\n")
998 (concat (package-desc-full-name pkg-desc
)
1002 ;; Update the old pkg-desc which will be shown on the description buffer.
1003 (setf (package-desc-signed pkg-desc
) t
)
1004 ;; Update the new (activated) pkg-desc as well.
1005 (setq pkg-descs
(cdr (assq (package-desc-name pkg-desc
) package-alist
)))
1007 (setf (package-desc-signed (car pkg-descs
)) t
)))))
1009 (defvar package--initialized nil
)
1011 (defun package-installed-p (package &optional min-version
)
1012 "Return true if PACKAGE, of MIN-VERSION or newer, is installed.
1013 If PACKAGE is a symbol, it is the package name and MIN-VERSION
1014 should be a version list.
1016 If PACKAGE is a package-desc object, MIN-VERSION is ignored."
1017 (unless package--initialized
(error "package.el is not yet initialized!"))
1018 (if (package-desc-p package
)
1019 (let ((dir (package-desc-dir package
)))
1021 (file-exists-p dir
)))
1023 (let ((pkg-descs (cdr (assq package package-alist
))))
1025 (version-list-<= min-version
1026 (package-desc-version (car pkg-descs
)))))
1027 ;; Also check built-in packages.
1028 (package-built-in-p package min-version
))))
1030 (defun package-compute-transaction (packages requirements
&optional seen
)
1031 "Return a list of packages to be installed, including PACKAGES.
1032 PACKAGES should be a list of `package-desc'.
1034 REQUIREMENTS should be a list of additional requirements; each
1035 element in this list should have the form (PACKAGE VERSION-LIST),
1036 where PACKAGE is a package name and VERSION-LIST is the required
1037 version of that package.
1039 This function recursively computes the requirements of the
1040 packages in REQUIREMENTS, and returns a list of all the packages
1041 that must be installed. Packages that are already installed are
1042 not included in this list.
1044 SEEN is used internally to detect infinite recursion."
1045 ;; FIXME: We really should use backtracking to explore the whole
1046 ;; search space (e.g. if foo require bar-1.3, and bar-1.4 requires toto-1.1
1047 ;; whereas bar-1.3 requires toto-1.0 and the user has put a hold on toto-1.0:
1048 ;; the current code might fail to see that it could install foo by using the
1050 (dolist (elt requirements
)
1051 (let* ((next-pkg (car elt
))
1052 (next-version (cadr elt
))
1054 (dolist (pkg packages
)
1055 (if (eq next-pkg
(package-desc-name pkg
))
1056 (setq already pkg
)))
1058 (if (version-list-<= next-version
(package-desc-version already
))
1059 ;; `next-pkg' is already in `packages', but its position there
1060 ;; means it might be installed too late: remove it from there, so
1061 ;; we re-add it (along with its dependencies) at an earlier place
1062 ;; below (bug#16994).
1063 (if (memq already seen
) ;Avoid inf-loop on dependency cycles.
1064 (message "Dependency cycle going through %S"
1065 (package-desc-full-name already
))
1066 (setq packages
(delq already packages
))
1068 (error "Need package `%s-%s', but only %s is being installed"
1069 next-pkg
(package-version-join next-version
)
1070 (package-version-join (package-desc-version already
)))))
1073 ((package-installed-p next-pkg next-version
) nil
)
1076 ;; A package is required, but not installed. It might also be
1077 ;; blocked via `package-load-list'.
1078 (let ((pkg-descs (cdr (assq next-pkg package-archive-contents
)))
1081 (while (and pkg-descs
(not found
))
1082 (let* ((pkg-desc (pop pkg-descs
))
1083 (version (package-desc-version pkg-desc
))
1084 (disabled (package-disabled-p next-pkg version
)))
1086 ((version-list-< version next-version
)
1088 "Need package `%s-%s', but only %s is available"
1089 next-pkg
(package-version-join next-version
)
1090 (package-version-join version
)))
1094 (if (stringp disabled
)
1095 (format "Package `%s' held at version %s, \
1096 but version %s required"
1098 (package-version-join next-version
))
1099 (format "Required package '%s' is disabled"
1101 (t (setq found pkg-desc
)))))
1104 (error "%s" problem
)
1105 (error "Package `%s-%s' is unavailable"
1106 next-pkg
(package-version-join next-version
))))
1108 (package-compute-transaction (cons found packages
)
1109 (package-desc-reqs found
)
1110 (cons found seen
))))))))
1113 (defun package-read-from-string (str)
1114 "Read a Lisp expression from STR.
1115 Signal an error if the entire string was not used."
1116 (let* ((read-data (read-from-string str
))
1119 ;; The call to `ignore' suppresses a compiler warning.
1120 (progn (ignore (read-from-string
1121 (substring str
(cdr read-data
))))
1123 (end-of-file nil
))))
1125 (error "Can't read whole string")
1128 (defun package--read-archive-file (file)
1129 "Re-read archive file FILE, if it exists.
1130 Will return the data from the file, or nil if the file does not exist.
1131 Will throw an error if the archive version is too new."
1132 (let ((filename (expand-file-name file package-user-dir
)))
1133 (when (file-exists-p filename
)
1135 (insert-file-contents-literally filename
)
1136 (let ((contents (read (current-buffer))))
1137 (if (> (car contents
) package-archive-version
)
1138 (error "Package archive version %d is higher than %d"
1139 (car contents
) package-archive-version
))
1142 (defun package-read-all-archive-contents ()
1143 "Re-read `archive-contents', if it exists.
1144 If successful, set `package-archive-contents'."
1145 (setq package-archive-contents nil
)
1146 (dolist (archive package-archives
)
1147 (package-read-archive-contents (car archive
))))
1149 (defun package-read-archive-contents (archive)
1150 "Re-read archive contents for ARCHIVE.
1151 If successful, set the variable `package-archive-contents'.
1152 If the archive version is too new, signal an error."
1153 ;; Version 1 of 'archive-contents' is identical to our internal
1155 (let* ((contents-file (format "archives/%s/archive-contents" archive
))
1156 (contents (package--read-archive-file contents-file
)))
1158 (dolist (package contents
)
1159 (package--add-to-archive-contents package archive
)))))
1161 ;; Package descriptor objects used inside the "archive-contents" file.
1162 ;; Changing this defstruct implies changing the format of the
1163 ;; "archive-contents" files.
1164 (cl-defstruct (package--ac-desc
1165 (:constructor package-make-ac-desc
(version reqs summary kind extras
))
1168 version reqs summary kind extras
)
1170 (defun package--add-to-archive-contents (package archive
)
1171 "Add the PACKAGE from the given ARCHIVE if necessary.
1172 PACKAGE should have the form (NAME . PACKAGE--AC-DESC).
1173 Also, add the originating archive to the `package-desc' structure."
1174 (let* ((name (car package
))
1175 (version (package--ac-desc-version (cdr package
)))
1177 (package-desc-create
1180 :reqs
(package--ac-desc-reqs (cdr package
))
1181 :summary
(package--ac-desc-summary (cdr package
))
1182 :kind
(package--ac-desc-kind (cdr package
))
1184 :extras
(and (> (length (cdr package
)) 4)
1185 ;; Older archive-contents files have only 4
1187 (package--ac-desc-extras (cdr package
)))))
1188 (pinned-to-archive (assoc name package-pinned-packages
)))
1189 ;; Skip entirely if pinned to another archive.
1190 (when (not (and pinned-to-archive
1191 (not (equal (cdr pinned-to-archive
) archive
))))
1192 (setq package-archive-contents
1193 (package--append-to-alist pkg-desc package-archive-contents
)))))
1195 (defun package--append-to-alist (pkg-desc alist
)
1196 "Append an entry for PKG-DESC to the start of ALIST and return it.
1197 This entry takes the form (`package-desc-name' PKG-DESC).
1199 If ALIST already has an entry with this name, destructively add
1200 PKG-DESC to the cdr of this entry instead, sorted by version
1202 (let* ((name (package-desc-name pkg-desc
))
1203 (priority-version (package-desc-priority-version pkg-desc
))
1204 (existing-packages (assq name alist
)))
1205 (if (not existing-packages
)
1206 (cons (list name pkg-desc
)
1208 (while (if (and (cdr existing-packages
)
1209 (version-list-< priority-version
1210 (package-desc-priority-version
1211 (cadr existing-packages
))))
1212 (setq existing-packages
(cdr existing-packages
))
1213 (push pkg-desc
(cdr existing-packages
))
1217 (defun package--user-selected-p (pkg)
1218 "Return non-nil if PKG is a package was installed by the user.
1219 PKG is a package name.
1220 This looks into `package-selected-packages', populating it first
1221 if it is still empty."
1222 (unless (consp package-selected-packages
)
1223 (customize-save-variable
1224 'package-selected-packages
1225 (setq package-selected-packages
(package--find-non-dependencies))))
1226 (memq pkg package-selected-packages
))
1228 (defun package-download-transaction (packages)
1229 "Download and install all the packages in PACKAGES.
1230 PACKAGES should be a list of package-desc.
1231 This function assumes that all package requirements in
1232 PACKAGES are satisfied, i.e. that PACKAGES is computed
1233 using `package-compute-transaction'."
1234 (mapc #'package-install-from-archive packages
))
1237 (defun package-install (pkg &optional dont-select
)
1238 "Install the package PKG.
1239 PKG can be a package-desc or the package name of one the available packages
1240 in an archive in `package-archives'. Interactively, prompt for its name.
1242 If called interactively or if DONT-SELECT nil, add PKG to
1243 `package-selected-packages'.
1245 If PKG is a package-desc and it is already installed, don't try
1246 to install it but still mark it as selected."
1249 ;; Initialize the package system to get the list of package
1250 ;; symbols for completion.
1251 (unless package--initialized
1252 (package-initialize t
))
1253 (unless package-archive-contents
1254 (package-refresh-contents))
1255 (list (intern (completing-read
1258 (mapcar (lambda (elt)
1259 (unless (package-installed-p (car elt
))
1260 (symbol-name (car elt
))))
1261 package-archive-contents
))
1264 (let ((name (if (package-desc-p pkg
)
1265 (package-desc-name pkg
)
1267 (unless (or dont-select
(package--user-selected-p name
))
1268 (customize-save-variable 'package-selected-packages
1269 (cons name package-selected-packages
))))
1270 (if (package-desc-p pkg
)
1271 (if (package-installed-p pkg
)
1272 (message "`%s' is already installed" (package-desc-full-name pkg
))
1273 (package-download-transaction
1274 (package-compute-transaction (list pkg
)
1275 (package-desc-reqs pkg
))))
1276 (package-download-transaction
1277 (package-compute-transaction ()
1278 (list (list pkg
))))))
1281 (defun package-reinstall (pkg)
1282 "Reinstall package PKG.
1283 PKG shoul be either a symbol, the package name, or a package-desc
1285 (interactive (list (intern (completing-read
1286 "Reinstall package: "
1287 (mapcar #'symbol-name
1288 (mapcar #'car package-alist
))))))
1290 (if (package-desc-p pkg
) pkg
(cadr (assq pkg package-alist
)))
1292 (package-install pkg
'dont-select
))
1294 (defun package-strip-rcs-id (str)
1295 "Strip RCS version ID from the version string STR.
1296 If the result looks like a dotted numeric version, return it.
1297 Otherwise return nil."
1299 (when (string-match "\\`[ \t]*[$]Revision:[ \t]+" str
)
1300 (setq str
(substring str
(match-end 0))))
1302 (if (version-to-list str
)
1306 (declare-function lm-homepage
"lisp-mnt" (&optional file
))
1308 (defun package--prepare-dependencies (deps)
1309 "Turn DEPS into an acceptable list of dependencies.
1311 Any parts missing a version string get a default version string
1312 of \"0\" (meaning any version) and an appropriate level of lists
1313 is wrapped around any parts requiring it."
1316 (error "Invalid requirement specifier: %S" deps
))
1317 (t (mapcar (lambda (dep)
1319 ((symbolp dep
) `(,dep
"0"))
1321 (error "Invalid requirement specifier: %S" dep
))
1322 ((and (listp dep
) (null (cdr dep
)))
1323 (list (car dep
) "0"))
1327 (defun package-buffer-info ()
1328 "Return a `package-desc' describing the package in the current buffer.
1330 If the buffer does not contain a conforming package, signal an
1331 error. If there is a package, narrow the buffer to the file's
1333 (goto-char (point-min))
1334 (unless (re-search-forward "^;;; \\([^ ]*\\)\\.el ---[ \t]*\\(.*?\\)[ \t]*\\(-\\*-.*-\\*-[ \t]*\\)?$" nil t
)
1335 (error "Package lacks a file header"))
1336 (let ((file-name (match-string-no-properties 1))
1337 (desc (match-string-no-properties 2))
1338 (start (line-beginning-position)))
1339 (unless (search-forward (concat ";;; " file-name
".el ends here"))
1340 (error "Package lacks a terminating comment"))
1341 ;; Try to include a trailing newline.
1343 (narrow-to-region start
(point))
1345 ;; Use some headers we've invented to drive the process.
1346 (let* ((requires-str (lm-header "package-requires"))
1347 ;; Prefer Package-Version; if defined, the package author
1348 ;; probably wants us to use it. Otherwise try Version.
1350 (or (package-strip-rcs-id (lm-header "package-version"))
1351 (package-strip-rcs-id (lm-header "version"))))
1352 (homepage (lm-homepage)))
1355 "Package lacks a \"Version\" or \"Package-Version\" header"))
1356 (package-desc-from-define
1357 file-name pkg-version desc
1359 (package--prepare-dependencies
1360 (package-read-from-string requires-str
)))
1364 (declare-function tar-get-file-descriptor
"tar-mode" (file))
1365 (declare-function tar--extract
"tar-mode" (descriptor))
1367 (defun package-tar-file-info ()
1368 "Find package information for a tar file.
1369 The return result is a `package-desc'."
1370 (cl-assert (derived-mode-p 'tar-mode
))
1371 (let* ((dir-name (file-name-directory
1372 (tar-header-name (car tar-parse-info
))))
1373 (desc-file (package--description-file dir-name
))
1374 (tar-desc (tar-get-file-descriptor (concat dir-name desc-file
))))
1376 (error "No package descriptor file found"))
1377 (with-current-buffer (tar--extract tar-desc
)
1379 (or (package--read-pkg-desc 'tar
)
1380 (error "Can't find define-package in %s"
1381 (tar-header-name tar-desc
)))
1382 (kill-buffer (current-buffer))))))
1384 (defun package-dir-info ()
1385 "Find package information for a directory.
1386 The return result is a `package-desc'."
1387 (cl-assert (derived-mode-p 'dired-mode
))
1388 (let* ((desc-file (package--description-file default-directory
)))
1389 (if (file-readable-p desc-file
)
1391 (insert-file-contents desc-file
)
1392 (package--read-pkg-desc 'dir
))
1393 (let ((files (directory-files default-directory t
"\\.el\\'" t
))
1397 (insert-file-contents (pop files
))
1398 ;; When we find the file with the data,
1399 (when (setq info
(ignore-errors (package-buffer-info)))
1402 ;; set the 'dir kind,
1403 (setf (package-desc-kind info
) 'dir
))))
1404 ;; and return the info.
1407 (defun package--read-pkg-desc (kind)
1408 "Read a `define-package' form in current buffer.
1409 Return the pkg-desc, with desc-kind set to KIND."
1410 (goto-char (point-min))
1412 (let* ((pkg-def-parsed (read (current-buffer)))
1414 (when (eq (car pkg-def-parsed
) 'define-package
)
1415 (apply #'package-desc-from-define
1416 (append (cdr pkg-def-parsed
))))))
1418 (setf (package-desc-kind pkg-desc
) kind
)
1423 (defun package-install-from-buffer ()
1424 "Install a package from the current buffer.
1425 The current buffer is assumed to be a single .el or .tar file or
1426 a directory. These must follow the packaging guidelines (see
1427 info node `(elisp)Packaging').
1429 Specially, if current buffer is a directory, the -pkg.el
1430 description file is not mandatory, in which case the information
1431 is derived from the main .el file in the directory.
1433 Downloads and installs required packages as needed."
1437 ((derived-mode-p 'dired-mode
)
1438 ;; This is the only way a package-desc object with a `dir'
1439 ;; desc-kind can be created. Such packages can't be
1440 ;; uploaded or installed from archives, they can only be
1441 ;; installed from local buffers or directories.
1443 ((derived-mode-p 'tar-mode
)
1444 (package-tar-file-info))
1446 (package-buffer-info))))
1447 (name (package-desc-name pkg-desc
)))
1448 ;; Download and install the dependencies.
1449 (let* ((requires (package-desc-reqs pkg-desc
))
1450 (transaction (package-compute-transaction nil requires
)))
1451 (package-download-transaction transaction
))
1452 ;; Install the package itself.
1453 (package-unpack pkg-desc
)
1454 (unless (package--user-selected-p name
)
1455 (customize-save-variable 'package-selected-packages
1456 (cons name package-selected-packages
)))
1460 (defun package-install-file (file)
1461 "Install a package from a file.
1462 The file can either be a tar file or an Emacs Lisp file."
1463 (interactive "fPackage file name: ")
1465 (if (file-directory-p file
)
1467 (setq default-directory file
)
1469 (insert-file-contents-literally file
)
1470 (when (string-match "\\.tar\\'" file
) (tar-mode)))
1471 (package-install-from-buffer)))
1473 (defun package--get-deps (pkg &optional only
)
1474 (let* ((pkg-desc (cadr (assq pkg package-alist
)))
1475 (direct-deps (cl-loop for p in
(package-desc-reqs pkg-desc
)
1477 when
(assq name package-alist
)
1479 (indirect-deps (unless (eq only
'direct
)
1481 (cl-loop for p in direct-deps
1482 append
(package--get-deps p
))))))
1484 (direct direct-deps
)
1485 (separate (list direct-deps indirect-deps
))
1486 (indirect indirect-deps
)
1487 (t (delete-dups (append direct-deps indirect-deps
))))))
1490 (defun package-install-user-selected-packages ()
1491 "Ensure packages in `package-selected-packages' are installed.
1492 If some packages are not installed propose to install them."
1494 ;; We don't need to populate `package-selected-packages' before
1495 ;; using here, because the outcome is the same either way (nothing
1497 (if (not package-selected-packages
)
1498 (message "`package-selected-packages' is empty, nothing to install")
1499 (cl-loop for p in package-selected-packages
1500 unless
(package-installed-p p
)
1505 (format "%s packages will be installed:\n%s, proceed?"
1507 (mapconcat #'symbol-name lst
", ")))
1508 (mapc #'package-install lst
))
1509 (message "All your packages are already installed")))))
1511 (defun package--used-elsewhere-p (pkg-desc &optional pkg-list
)
1512 "Non-nil if PKG-DESC is a dependency of a package in PKG-LIST.
1513 Return the first package found in PKG-LIST of which PKG is a
1516 When not specified, PKG-LIST defaults to `package-alist'
1517 with PKG-DESC entry removed."
1518 (unless (string= (package-desc-status pkg-desc
) "obsolete")
1519 (let ((pkg (package-desc-name pkg-desc
)))
1520 (cl-loop with alist
= (or pkg-list
1521 (remove (assq pkg package-alist
)
1523 for p in alist thereis
1524 (and (memq pkg
(mapcar #'car
(package-desc-reqs (cadr p
))))
1527 (defun package--newest-p (pkg)
1528 "Return t if PKG is the newest package with its name."
1529 (equal (cadr (assq (package-desc-name pkg
) package-alist
))
1532 (defun package-delete (pkg-desc &optional force nosave
)
1533 "Delete package PKG-DESC.
1535 Argument PKG-DESC is a full description of package as vector.
1536 When package is used elsewhere as dependency of another package,
1537 refuse deleting it and return an error.
1538 If FORCE is non-nil package will be deleted even if it is used
1540 If NOSAVE is non-nil, the package is not removed from
1541 `package-selected-packages'."
1542 (let ((dir (package-desc-dir pkg-desc
))
1543 (name (package-desc-name pkg-desc
))
1544 pkg-used-elsewhere-by
)
1545 ;; If the user is trying to delete this package, they definitely
1546 ;; don't want it marked as selected, so we remove it from
1547 ;; `package-selected-packages' even if it can't be deleted.
1548 (when (and (null nosave
)
1549 (package--user-selected-p name
)
1550 ;; Don't delesect if this is an older version of an
1551 ;; upgraded package.
1552 (package--newest-p pkg-desc
))
1553 (customize-save-variable
1554 'package-selected-packages
(remove name package-selected-packages
)))
1555 (cond ((not (string-prefix-p (file-name-as-directory
1556 (expand-file-name package-user-dir
))
1557 (expand-file-name dir
)))
1558 ;; Don't delete "system" packages.
1559 (error "Package `%s' is a system package, not deleting"
1560 (package-desc-full-name pkg-desc
)))
1562 (setq pkg-used-elsewhere-by
1563 (package--used-elsewhere-p pkg-desc
)))
1564 ;; Don't delete packages used as dependency elsewhere.
1565 (error "Package `%s' is used by `%s' as dependency, not deleting"
1566 (package-desc-full-name pkg-desc
)
1567 pkg-used-elsewhere-by
))
1569 (delete-directory dir t t
)
1570 ;; Remove NAME-VERSION.signed file.
1571 (let ((signed-file (concat dir
".signed")))
1572 (if (file-exists-p signed-file
)
1573 (delete-file signed-file
)))
1574 ;; Update package-alist.
1575 (let ((pkgs (assq name package-alist
)))
1576 (delete pkg-desc pkgs
)
1578 (setq package-alist
(delq pkgs package-alist
))))
1579 (message "Package `%s' deleted." (package-desc-full-name pkg-desc
))))))
1581 (defun package--removable-packages ()
1582 "Return a list of names of packages no longer needed.
1583 These are packages which are neither contained in
1584 `package-selected-packages' nor a dependency of one that is."
1585 (let ((needed (cl-loop for p in package-selected-packages
1586 if
(assq p package-alist
)
1587 ;; `p' and its dependencies are needed.
1588 append
(cons p
(package--get-deps p
)))))
1589 (cl-loop for p in
(mapcar #'car package-alist
)
1590 unless
(memq p needed
)
1594 (defun package-autoremove ()
1595 "Remove packages that are no more needed.
1597 Packages that are no more needed by other packages in
1598 `package-selected-packages' and their dependencies
1601 ;; If `package-selected-packages' is nil, it would make no sense to
1602 ;; try to populate it here, because then `package-autoremove' will
1603 ;; do absolutely nothing.
1604 (when (or package-selected-packages
1606 "`package-selected-packages' is empty! Really remove ALL packages? "))
1607 (let ((removable (package--removable-packages)))
1610 (format "%s packages will be deleted:\n%s, proceed? "
1612 (mapconcat #'symbol-name removable
", ")))
1614 (package-delete (cadr (assq p package-alist
)) t
))
1616 (message "Nothing to autoremove"))))))
1618 (defun package-archive-base (desc)
1619 "Return the archive containing the package NAME."
1620 (cdr (assoc (package-desc-archive desc
) package-archives
)))
1622 (defun package-archive-priority (archive)
1623 "Return the priority of ARCHIVE.
1625 The archive priorities are specified in
1626 `package-archive-priorities'. If not given there, the priority
1628 (or (cdr (assoc archive package-archive-priorities
))
1631 (defun package-desc-priority-version (pkg-desc)
1632 "Return the version PKG-DESC with the archive priority prepended.
1634 This allows for easy comparison of package versions from
1635 different archives if archive priorities are meant to be taken in
1637 (cons (package-archive-priority
1638 (package-desc-archive pkg-desc
))
1639 (package-desc-version pkg-desc
)))
1641 (defun package--download-one-archive (archive file
)
1642 "Retrieve an archive file FILE from ARCHIVE, and cache it.
1643 ARCHIVE should be a cons cell of the form (NAME . LOCATION),
1644 similar to an entry in `package-alist'. Save the cached copy to
1645 \"archives/NAME/archive-contents\" in `package-user-dir'."
1646 (let ((dir (expand-file-name (format "archives/%s" (car archive
))
1648 (sig-file (concat file
".sig"))
1650 (package--with-work-buffer (cdr archive
) file
1651 ;; Check signature of archive-contents, if desired.
1652 (if (and package-check-signature
1653 (not (member archive package-unsigned-archives
)))
1654 (if (package--archive-file-exists-p (cdr archive
) sig-file
)
1655 (setq good-signatures
(package--check-signature (cdr archive
)
1657 (unless (eq package-check-signature
'allow-unsigned
)
1658 (error "Unsigned archive `%s'"
1660 ;; Read the retrieved buffer to make sure it is valid (e.g. it
1661 ;; may fetch a URL redirect page).
1662 (when (listp (read (current-buffer)))
1663 (make-directory dir t
)
1664 (write-region nil nil
(expand-file-name file dir
) nil
'silent
)))
1665 (when good-signatures
1666 ;; Write out good signatures into archive-contents.signed file.
1667 (write-region (mapconcat #'epg-signature-to-string good-signatures
"\n")
1669 (expand-file-name (concat file
".signed") dir
)
1672 (declare-function epg-check-configuration
"epg-config"
1673 (config &optional minimum-version
))
1674 (declare-function epg-configuration
"epg-config" ())
1675 (declare-function epg-import-keys-from-file
"epg" (context keys
))
1678 (defun package-import-keyring (&optional file
)
1679 "Import keys from FILE."
1680 (interactive "fFile: ")
1681 (setq file
(expand-file-name file
))
1682 (let ((context (epg-make-context 'OpenPGP
))
1683 (homedir (expand-file-name "gnupg" package-user-dir
)))
1684 (with-file-modes 448
1685 (make-directory homedir t
))
1686 (setf (epg-context-home-directory context
) homedir
)
1687 (message "Importing %s..." (file-name-nondirectory file
))
1688 (epg-import-keys-from-file context file
)
1689 (message "Importing %s...done" (file-name-nondirectory file
))))
1691 (defun package--build-compatibility-table ()
1692 "Build `package--compatibility-table' with `package--mapc'."
1693 ;; Build compat table.
1694 (setq package--compatibility-table
(make-hash-table :test
'eq
))
1695 (package--mapc #'package--add-to-compatibility-table
))
1698 (defun package-refresh-contents ()
1699 "Download the ELPA archive description if needed.
1700 This informs Emacs about the latest versions of all packages, and
1701 makes them available for download."
1703 ;; FIXME: Do it asynchronously.
1704 (unless (file-exists-p package-user-dir
)
1705 (make-directory package-user-dir t
))
1706 (let ((default-keyring (expand-file-name "package-keyring.gpg"
1708 (when (and package-check-signature
(file-exists-p default-keyring
))
1709 (condition-case-unless-debug error
1711 (epg-check-configuration (epg-configuration))
1712 (package-import-keyring default-keyring
))
1713 (error (message "Cannot import default keyring: %S" (cdr error
))))))
1714 (dolist (archive package-archives
)
1715 (condition-case-unless-debug nil
1716 (package--download-one-archive archive
"archive-contents")
1717 (error (message "Failed to download `%s' archive."
1719 (package-read-all-archive-contents)
1720 (package--build-compatibility-table))
1722 (defun package--find-non-dependencies ()
1723 "Return a list of installed packages which are not dependencies.
1724 Finds all packages in `package-alist' which are not dependencies
1725 of any other packages.
1726 Used to populate `package-selected-packages'."
1730 (mapcar (lambda (p) (mapcar #'car
(package-desc-reqs (cadr p
))))
1732 (cl-loop for p in package-alist
1734 unless
(memq name dep-list
)
1738 (defun package-initialize (&optional no-activate
)
1739 "Load Emacs Lisp packages, and activate them.
1740 The variable `package-load-list' controls which packages to load.
1741 If optional arg NO-ACTIVATE is non-nil, don't activate packages."
1743 (setq package-alist nil
)
1744 (package-load-all-descriptors)
1745 (package-read-all-archive-contents)
1747 (dolist (elt package-alist
)
1748 (package-activate (car elt
))))
1749 (setq package--initialized t
)
1750 ;; This uses `package--mapc' so it must be called after
1751 ;; `package--initialized' is t.
1752 (package--build-compatibility-table))
1754 (defun package--add-to-compatibility-table (pkg)
1755 "If PKG is compatible (without dependencies), add to the compatibility table.
1756 PKG is a package-desc object.
1757 Only adds if its version is higher than what's already stored in
1759 (unless (package--incompatible-p pkg
'shallow
)
1760 (let* ((name (package-desc-name pkg
))
1761 (version (or (package-desc-version pkg
) '(0)))
1762 (table-version (gethash name package--compatibility-table
)))
1763 (when (or (not table-version
)
1764 (version-list-< table-version version
))
1765 (puthash name version package--compatibility-table
)))))
1768 ;;;; Package description buffer.
1771 (defun describe-package (package)
1772 "Display the full documentation of PACKAGE (a symbol)."
1774 (let* ((guess (function-called-at-point)))
1775 (require 'finder-inf nil t
)
1776 ;; Load the package list if necessary (but don't activate them).
1777 (unless package--initialized
1778 (package-initialize t
))
1779 (let ((packages (append (mapcar 'car package-alist
)
1780 (mapcar 'car package-archive-contents
)
1781 (mapcar 'car package--builtins
))))
1782 (unless (memq guess packages
)
1784 (setq packages
(mapcar 'symbol-name packages
))
1786 (completing-read (if guess
1787 (format "Describe package (default %s): "
1789 "Describe package: ")
1790 packages nil t nil nil guess
)))
1791 (list (intern val
))))))
1792 (if (not (or (package-desc-p package
) (and package
(symbolp package
))))
1793 (message "No package specified")
1794 (help-setup-xref (list #'describe-package package
)
1795 (called-interactively-p 'interactive
))
1796 (with-help-window (help-buffer)
1797 (with-current-buffer standard-output
1798 (describe-package-1 package
)))))
1800 (defun describe-package-1 (pkg)
1803 (if (package-desc-p pkg
) pkg
)
1804 (cadr (assq pkg package-alist
))
1805 (let ((built-in (assq pkg package--builtins
)))
1807 (package--from-builtin built-in
)
1808 (cadr (assq pkg package-archive-contents
))))))
1809 (name (if desc
(package-desc-name desc
) pkg
))
1810 (pkg-dir (if desc
(package-desc-dir desc
)))
1811 (reqs (if desc
(package-desc-reqs desc
)))
1812 (version (if desc
(package-desc-version desc
)))
1813 (archive (if desc
(package-desc-archive desc
)))
1814 (extras (and desc
(package-desc-extras desc
)))
1815 (homepage (cdr (assoc :url extras
)))
1816 (keywords (if desc
(package-desc--keywords desc
)))
1817 (built-in (eq pkg-dir
'builtin
))
1818 (installable (and archive
(not built-in
)))
1819 (status (if desc
(package-desc-status desc
) "orphan"))
1820 (incompatible-reason (package--incompatible-p desc
))
1821 (signed (if desc
(package-desc-signed desc
))))
1822 (when incompatible-reason
1823 (setq status
"incompatible"))
1826 (princ (if (memq (aref status
0) '(?a ?e ?i ?o ?u
)) "an " "a "))
1828 (princ " package.\n\n")
1830 (insert " " (propertize "Status" 'font-lock-face
'bold
) ": ")
1832 (insert (propertize (capitalize status
)
1833 'font-lock-face
'font-lock-builtin-face
)
1836 (insert (propertize (if (member status
'("unsigned" "dependency"))
1838 (capitalize status
)) ;FIXME: Why comment-face?
1839 'font-lock-face
'font-lock-comment-face
))
1841 ;; Todo: Add button for uninstalling.
1842 (help-insert-xref-button (abbreviate-file-name
1843 (file-name-as-directory pkg-dir
))
1844 'help-package-def pkg-dir
)
1845 (if (and (package-built-in-p name
)
1846 (not (package-built-in-p name version
)))
1847 (insert "',\n shadowing a "
1848 (propertize "built-in package"
1849 'font-lock-face
'font-lock-builtin-face
))
1853 (insert " (unsigned).")))
1854 (incompatible-reason
1855 (insert (propertize "Incompatible" 'face font-lock-warning-face
)
1856 " because it depends on ")
1857 (if (stringp incompatible-reason
)
1858 (insert "Emacs " incompatible-reason
".")
1859 (insert "uninstallable packages.")))
1861 (insert (capitalize status
))
1862 (insert " from " (format "%s" archive
))
1864 (package-make-button
1866 'action
'package-install-button-action
1867 'package-desc desc
))
1868 (t (insert (capitalize status
) ".")))
1870 (insert " " (propertize "Archive" 'font-lock-face
'bold
)
1871 ": " (or archive
"n/a") "\n")
1874 (propertize "Version" 'font-lock-face
'bold
) ": "
1875 (package-version-join version
) "\n"))
1877 (setq reqs
(if desc
(package-desc-reqs desc
)))
1879 (insert " " (propertize "Requires" 'font-lock-face
'bold
) ": ")
1882 (let* ((name (car req
))
1884 (text (format "%s-%s" (symbol-name name
)
1885 (package-version-join vers
)))
1886 (reason (if (and (listp incompatible-reason
)
1887 (assq name incompatible-reason
))
1888 " (not available)" "")))
1889 (cond (first (setq first nil
))
1890 ((>= (+ 2 (current-column) (length text
) (length reason
))
1894 (help-insert-xref-button text
'help-package name
)
1897 (insert " " (propertize "Summary" 'font-lock-face
'bold
)
1898 ": " (if desc
(package-desc-summary desc
)) "\n")
1900 (insert " " (propertize "Homepage" 'font-lock-face
'bold
) ": ")
1901 (help-insert-xref-button homepage
'help-url homepage
)
1904 (insert " " (propertize "Keywords" 'font-lock-face
'bold
) ": ")
1905 (dolist (k keywords
)
1906 (package-make-button
1909 'action
'package-keyword-button-action
)
1912 (let* ((all-pkgs (append (cdr (assq name package-alist
))
1913 (cdr (assq name package-archive-contents
))
1914 (let ((bi (assq name package--builtins
)))
1915 (if bi
(list (package--from-builtin bi
))))))
1916 (other-pkgs (delete desc all-pkgs
)))
1918 (insert " " (propertize "Other versions" 'font-lock-face
'bold
) ": "
1921 (let* ((ov (package-desc-version opkg
))
1922 (dir (package-desc-dir opkg
))
1923 (from (or (package-desc-archive opkg
)
1924 (if (stringp dir
) "installed" dir
))))
1925 (if (not ov
) (format "%s" from
)
1927 (make-text-button (package-version-join ov
) nil
1932 (describe-package opkg
)))
1940 ;; For built-in packages, insert the commentary.
1941 (let ((fn (locate-file (format "%s.el" name
) load-path
1942 load-file-rep-suffixes
))
1944 (insert (or (lm-commentary fn
) ""))
1947 (when (re-search-forward "^;;; Commentary:\n" nil t
)
1949 (while (re-search-forward "^\\(;+ ?\\)" nil t
)
1950 (replace-match ""))))
1951 (let ((readme (expand-file-name (format "%s-readme.txt" name
)
1954 ;; For elpa packages, try downloading the commentary. If that
1955 ;; fails, try an existing readme file in `package-user-dir'.
1956 (cond ((condition-case nil
1958 (package--with-work-buffer
1959 (package-archive-base desc
)
1960 (format "%s-readme.txt" name
)
1962 (goto-char (point-max))
1965 (write-region nil nil
1966 (expand-file-name readme package-user-dir
)
1968 (setq readme-string
(buffer-string))
1971 (insert readme-string
))
1972 ((file-readable-p readme
)
1973 (insert-file-contents readme
)
1974 (goto-char (point-max))))))))
1976 (defun package-install-button-action (button)
1977 (let ((pkg-desc (button-get button
'package-desc
)))
1978 (when (y-or-n-p (format "Install package `%s'? "
1979 (package-desc-full-name pkg-desc
)))
1980 (package-install pkg-desc nil
)
1981 (revert-buffer nil t
)
1982 (goto-char (point-min)))))
1984 (defun package-keyword-button-action (button)
1985 (let ((pkg-keyword (button-get button
'package-keyword
)))
1986 (package-show-package-list t
(list pkg-keyword
))))
1988 (defun package-make-button (text &rest props
)
1989 (let ((button-text (if (display-graphic-p) text
(concat "[" text
"]")))
1990 (button-face (if (display-graphic-p)
1991 '(:box
(:line-width
2 :color
"dark grey")
1992 :background
"light grey"
1993 :foreground
"black")
1995 (apply 'insert-text-button button-text
'face button-face
'follow-link t
1999 ;;;; Package menu mode.
2001 (defvar package-menu-mode-map
2002 (let ((map (make-sparse-keymap))
2003 (menu-map (make-sparse-keymap "Package")))
2004 (set-keymap-parent map tabulated-list-mode-map
)
2005 (define-key map
"\C-m" 'package-menu-describe-package
)
2006 (define-key map
"u" 'package-menu-mark-unmark
)
2007 (define-key map
"\177" 'package-menu-backup-unmark
)
2008 (define-key map
"d" 'package-menu-mark-delete
)
2009 (define-key map
"i" 'package-menu-mark-install
)
2010 (define-key map
"U" 'package-menu-mark-upgrades
)
2011 (define-key map
"r" 'package-menu-refresh
)
2012 (define-key map
"f" 'package-menu-filter
)
2013 (define-key map
"~" 'package-menu-mark-obsolete-for-deletion
)
2014 (define-key map
"x" 'package-menu-execute
)
2015 (define-key map
"h" 'package-menu-quick-help
)
2016 (define-key map
"?" 'package-menu-describe-package
)
2017 (define-key map
[menu-bar package-menu
] (cons "Package" menu-map
))
2018 (define-key menu-map
[mq]
2019 '(menu-item "Quit" quit-window
2020 :help "Quit package selection"))
2021 (define-key menu-map [s1] '("--"))
2022 (define-key menu-map [mn]
2023 '(menu-item "Next" next-line
2025 (define-key menu-map [mp]
2026 '(menu-item "Previous" previous-line
2027 :help "Previous Line"))
2028 (define-key menu-map [s2] '("--"))
2029 (define-key menu-map [mu]
2030 '(menu-item "Unmark" package-menu-mark-unmark
2031 :help "Clear any marks on a package and move to the next line"))
2032 (define-key menu-map [munm]
2033 '(menu-item "Unmark Backwards" package-menu-backup-unmark
2034 :help "Back up one line and clear any marks on that package"))
2035 (define-key menu-map [md]
2036 '(menu-item "Mark for Deletion" package-menu-mark-delete
2037 :help "Mark a package for deletion and move to the next line"))
2038 (define-key menu-map [mi]
2039 '(menu-item "Mark for Install" package-menu-mark-install
2040 :help "Mark a package for installation and move to the next line"))
2041 (define-key menu-map [mupgrades]
2042 '(menu-item "Mark Upgradable Packages" package-menu-mark-upgrades
2043 :help "Mark packages that have a newer version for upgrading"))
2044 (define-key menu-map [s3] '("--"))
2045 (define-key menu-map [mf]
2046 '(menu-item "Filter Package List..." package-menu-filter
2047 :help "Filter package selection (q to go back)"))
2048 (define-key menu-map [mg]
2049 '(menu-item "Update Package List" revert-buffer
2050 :help "Update the list of packages"))
2051 (define-key menu-map [mr]
2052 '(menu-item "Refresh Package List" package-menu-refresh
2053 :help "Download the ELPA archive"))
2054 (define-key menu-map [s4] '("--"))
2055 (define-key menu-map [mt]
2056 '(menu-item "Mark Obsolete Packages" package-menu-mark-obsolete-for-deletion
2057 :help "Mark all obsolete packages for deletion"))
2058 (define-key menu-map [mx]
2059 '(menu-item "Execute Actions" package-menu-execute
2060 :help "Perform all the marked actions"))
2061 (define-key menu-map [s5] '("--"))
2062 (define-key menu-map [mh]
2063 '(menu-item "Help" package-menu-quick-help
2064 :help "Show short key binding help for package-menu-mode"))
2065 (define-key menu-map [mc]
2066 '(menu-item "Describe Package" package-menu-describe-package
2067 :help "Display information about this package"))
2069 "Local keymap for `package-menu-mode' buffers.")
2071 (defvar package-menu--new-package-list nil
2072 "List of newly-available packages since `list-packages' was last called.")
2074 (define-derived-mode package-menu-mode tabulated-list-mode "Package Menu"
2075 "Major mode for browsing a list of packages.
2076 Letters do not insert themselves; instead, they are commands.
2077 \\<package-menu-mode-map>
2078 \\{package-menu-mode-map}"
2079 (setq tabulated-list-format
2080 `[("Package" 18 package-menu--name-predicate)
2082 ("Status" 10 package-menu--status-predicate)
2083 ,@(if (cdr package-archives)
2084 '(("Archive" 10 package-menu--archive-predicate)))
2085 ("Description" 0 nil)])
2086 (setq tabulated-list-padding 2)
2087 (setq tabulated-list-sort-key (cons "Status" nil))
2088 (add-hook 'tabulated-list-revert-hook 'package-menu--refresh nil t)
2089 (tabulated-list-init-header))
2091 (defmacro package--push (pkg-desc status listname)
2092 "Convenience macro for `package-menu--generate'.
2093 If the alist stored in the symbol LISTNAME lacks an entry for a
2094 package PKG-DESC, add one. The alist is keyed with PKG-DESC."
2095 `(unless (assoc ,pkg-desc ,listname)
2096 ;; FIXME: Should we move status into pkg-desc?
2097 (push (cons ,pkg-desc ,status) ,listname)))
2099 (defvar package-list-unversioned nil
2100 "If non-nil include packages that don't have a version in `list-package'.")
2102 (defvar package-list-unsigned nil
2103 "If non-nil, mention in the list which packages were installed w/o signature.")
2105 (defvar package--emacs-version-list (version-to-list emacs-version)
2106 "`emacs-version', as a list.")
2108 (defun package--incompatible-p (pkg &optional shallow)
2109 "Return non-nil if PKG has no chance of being installable.
2110 PKG is a package-desc object.
2112 If SHALLOW is non-nil, this only checks if PKG depends on a
2113 higher `emacs-version' than the one being used. Otherwise, also
2114 checks the viability of dependencies, according to
2115 `package--compatibility-table'.
2117 If PKG requires an incompatible Emacs version, the return value
2118 is this version (as a string).
2119 If PKG requires incompatible packages, the return value is a list
2120 of these dependencies, similar to the list returned by
2121 `package-desc-reqs'."
2122 (let* ((reqs (package-desc-reqs pkg))
2123 (version (cadr (assq 'emacs reqs))))
2124 (if (and version (version-list-< package--emacs-version-list version))
2125 (package-version-join version)
2128 (dolist (dep (package-desc-reqs pkg) out)
2129 (let ((dep-name (car dep)))
2130 (unless (eq 'emacs dep-name)
2131 (let ((cv (gethash dep-name package--compatibility-table)))
2132 (when (version-list-< (or cv '(0)) (or (cadr dep) '(0)))
2133 (push dep out)))))))))))
2135 (defun package-desc-status (pkg-desc)
2136 (let* ((name (package-desc-name pkg-desc))
2137 (dir (package-desc-dir pkg-desc))
2138 (lle (assq name package-load-list))
2140 (version (package-desc-version pkg-desc))
2141 (signed (or (not package-list-unsigned)
2142 (package-desc-signed pkg-desc))))
2144 ((eq dir 'builtin) "built-in")
2145 ((and lle (null held)) "disabled")
2147 (let ((hv (if (stringp held) (version-to-list held))))
2149 ((version-list-= version hv) "held")
2150 ((version-list-< version hv) "obsolete")
2152 ((package-built-in-p name version) "obsolete")
2153 ((package--incompatible-p pkg-desc) "incompat")
2154 (dir ;One of the installed packages.
2156 ((not (file-exists-p (package-desc-dir pkg-desc))) "deleted")
2157 ((eq pkg-desc (cadr (assq name package-alist)))
2158 (if (not signed) "unsigned"
2159 (if (package--user-selected-p name)
2160 "installed" "dependency")))
2163 (let* ((ins (cadr (assq name package-alist)))
2164 (ins-v (if ins (package-desc-version ins))))
2166 ((or (null ins) (version-list-< ins-v version))
2167 (if (memq name package-menu--new-package-list)
2169 ((version-list-< version ins-v) "obsolete")
2170 ((version-list-= version ins-v)
2171 (if (not signed) "unsigned"
2172 (if (package--user-selected-p name)
2173 "installed" "dependency")))))))))
2175 (defun package-menu--refresh (&optional packages keywords)
2176 "Re-populate the `tabulated-list-entries'.
2177 PACKAGES should be nil or t, which means to display all known packages.
2178 KEYWORDS should be nil or a list of keywords."
2179 ;; Construct list of (PKG-DESC . STATUS).
2180 (unless packages (setq packages t))
2181 (let (info-list name)
2182 ;; Installed packages:
2183 (dolist (elt package-alist)
2184 (setq name (car elt))
2185 (when (or (eq packages t) (memq name packages))
2186 (dolist (pkg (cdr elt))
2187 (when (package--has-keyword-p pkg keywords)
2188 (package--push pkg (package-desc-status pkg) info-list)))))
2190 ;; Built-in packages:
2191 (dolist (elt package--builtins)
2192 (setq name (car elt))
2193 (when (and (not (eq name 'emacs)) ; Hide the `emacs' package.
2194 (package--has-keyword-p (package--from-builtin elt) keywords)
2195 (or package-list-unversioned
2196 (package--bi-desc-version (cdr elt)))
2197 (or (eq packages t) (memq name packages)))
2198 (package--push (package--from-builtin elt) "built-in" info-list)))
2200 ;; Available and disabled packages:
2201 (dolist (elt package-archive-contents)
2202 (setq name (car elt))
2203 (when (or (eq packages t) (memq name packages))
2204 (dolist (pkg (cdr elt))
2205 ;; Hide obsolete packages.
2206 (when (and (not (package-installed-p (package-desc-name pkg)
2207 (package-desc-version pkg)))
2208 (package--has-keyword-p pkg keywords))
2209 (package--push pkg (package-desc-status pkg) info-list)))))
2211 ;; Print the result.
2212 (setq tabulated-list-entries
2213 (mapcar #'package-menu--print-info info-list))))
2215 (defun package-all-keywords ()
2216 "Collect all package keywords"
2218 (package--mapc (lambda (desc)
2219 (let* ((desc-keywords (and desc (package-desc--keywords desc))))
2220 (setq keywords (append keywords desc-keywords)))))
2223 (defun package--mapc (function &optional packages)
2224 "Call FUNCTION for all known PACKAGES.
2225 PACKAGES can be nil or t, which means to display all known
2226 packages, or a list of packages.
2228 Built-in packages are converted with `package--from-builtin'."
2229 (unless packages (setq packages t))
2231 ;; Installed packages:
2232 (dolist (elt package-alist)
2233 (setq name (car elt))
2234 (when (or (eq packages t) (memq name packages))
2235 (mapc function (cdr elt))))
2237 ;; Built-in packages:
2238 (dolist (elt package--builtins)
2239 (setq name (car elt))
2240 (when (and (not (eq name 'emacs)) ; Hide the `emacs' package.
2241 (or package-list-unversioned
2242 (package--bi-desc-version (cdr elt)))
2243 (or (eq packages t) (memq name packages)))
2244 (funcall function (package--from-builtin elt))))
2246 ;; Available and disabled packages:
2247 (dolist (elt package-archive-contents)
2248 (setq name (car elt))
2249 (when (or (eq packages t) (memq name packages))
2250 (dolist (pkg (cdr elt))
2251 ;; Hide obsolete packages.
2252 (unless (package-installed-p (package-desc-name pkg)
2253 (package-desc-version pkg))
2254 (funcall function pkg)))))))
2256 (defun package--has-keyword-p (desc &optional keywords)
2257 "Test if package DESC has any of the given KEYWORDS.
2258 When none are given, the package matches."
2260 (let* ((desc-keywords (and desc (package-desc--keywords desc)))
2262 (dolist (k keywords)
2263 (when (and (not found)
2264 (member k desc-keywords))
2269 (defun package-menu--generate (remember-pos packages &optional keywords)
2270 "Populate the Package Menu.
2271 If REMEMBER-POS is non-nil, keep point on the same entry.
2272 PACKAGES should be t, which means to display all known packages,
2273 or a list of package names (symbols) to display.
2275 With KEYWORDS given, only packages with those keywords are
2277 (package-menu--refresh packages keywords)
2278 (setf (car (aref tabulated-list-format 0))
2280 (let ((filters (mapconcat 'identity keywords ",")))
2281 (concat "Package[" filters "]"))
2284 (define-key package-menu-mode-map "q" 'package-show-package-list)
2285 (define-key package-menu-mode-map "q" 'quit-window))
2286 (tabulated-list-init-header)
2287 (tabulated-list-print remember-pos))
2289 (defun package-menu--print-info (pkg)
2290 "Return a package entry suitable for `tabulated-list-entries'.
2291 PKG has the form (PKG-DESC . STATUS).
2292 Return (PKG-DESC [NAME VERSION STATUS DOC])."
2293 (let* ((pkg-desc (car pkg))
2296 (`"built-in" 'font-lock-builtin-face)
2297 (`"available" 'default)
2299 (`"held" 'font-lock-constant-face)
2300 (`"disabled" 'font-lock-warning-face)
2301 (`"installed" 'font-lock-comment-face)
2302 (`"dependency" 'font-lock-comment-face)
2303 (`"unsigned" 'font-lock-warning-face)
2304 (`"incompat" 'font-lock-comment-face)
2305 (_ 'font-lock-warning-face)))) ; obsolete.
2307 `[,(list (symbol-name (package-desc-name pkg-desc))
2310 'package-desc pkg-desc
2311 'action 'package-menu-describe-package)
2312 ,(propertize (package-version-join
2313 (package-desc-version pkg-desc))
2314 'font-lock-face face)
2315 ,(propertize status 'font-lock-face face)
2316 ,@(if (cdr package-archives)
2317 (list (propertize (or (package-desc-archive pkg-desc) "")
2318 'font-lock-face face)))
2319 ,(propertize (package-desc-summary pkg-desc)
2320 'font-lock-face face)])))
2322 (defun package-menu-refresh ()
2323 "Download the Emacs Lisp package archive.
2324 This fetches the contents of each archive specified in
2325 `package-archives', and then refreshes the package menu."
2327 (unless (derived-mode-p 'package-menu-mode)
2328 (user-error "The current buffer is not a Package Menu"))
2329 (package-refresh-contents)
2330 (package-menu--generate t t))
2332 (defun package-menu-describe-package (&optional button)
2333 "Describe the current package.
2334 If optional arg BUTTON is non-nil, describe its associated package."
2336 (let ((pkg-desc (if button (button-get button 'package-desc)
2337 (tabulated-list-get-id))))
2339 (describe-package pkg-desc)
2340 (user-error "No package here"))))
2342 ;; fixme numeric argument
2343 (defun package-menu-mark-delete (&optional _num)
2344 "Mark a package for deletion and move to the next line."
2346 (if (member (package-menu-get-status)
2347 '("installed" "dependency" "obsolete" "unsigned"))
2348 (tabulated-list-put-tag "D" t)
2351 (defun package-menu-mark-install (&optional _num)
2352 "Mark a package for installation and move to the next line."
2354 (if (member (package-menu-get-status) '("available" "new" "dependency"))
2355 (tabulated-list-put-tag "I" t)
2358 (defun package-menu-mark-unmark (&optional _num)
2359 "Clear any marks on a package and move to the next line."
2361 (tabulated-list-put-tag " " t))
2363 (defun package-menu-backup-unmark ()
2364 "Back up one line and clear any marks on that package."
2367 (tabulated-list-put-tag " "))
2369 (defun package-menu-mark-obsolete-for-deletion ()
2370 "Mark all obsolete packages for deletion."
2373 (goto-char (point-min))
2375 (if (equal (package-menu-get-status) "obsolete")
2376 (tabulated-list-put-tag "D" t)
2377 (forward-line 1)))))
2379 (defun package-menu-quick-help ()
2380 "Show short key binding help for package-menu-mode."
2382 (message "n-ext, i-nstall, d-elete, u-nmark, x-ecute, r-efresh, h-elp"))
2384 (define-obsolete-function-alias
2385 'package-menu-view-commentary 'package-menu-describe-package "24.1")
2387 (defun package-menu-get-status ()
2388 (let* ((id (tabulated-list-get-id))
2389 (entry (and id (assq id tabulated-list-entries))))
2391 (aref (cadr entry) 2)
2394 (defun package-menu--find-upgrades ()
2395 (let (installed available upgrades)
2396 ;; Build list of installed/available packages in this buffer.
2397 (dolist (entry tabulated-list-entries)
2398 ;; ENTRY is (PKG-DESC [NAME VERSION STATUS DOC])
2399 (let ((pkg-desc (car entry))
2400 (status (aref (cadr entry) 2)))
2401 (cond ((member status '("installed" "dependency" "unsigned"))
2402 (push pkg-desc installed))
2403 ((member status '("available" "new"))
2404 (setq available (package--append-to-alist pkg-desc available))))))
2405 ;; Loop through list of installed packages, finding upgrades.
2406 (dolist (pkg-desc installed)
2407 (let* ((name (package-desc-name pkg-desc))
2408 (avail-pkg (cadr (assq name available))))
2410 (version-list-< (package-desc-priority-version pkg-desc)
2411 (package-desc-priority-version avail-pkg))
2412 (push (cons name avail-pkg) upgrades))))
2415 (defun package-menu-mark-upgrades ()
2416 "Mark all upgradable packages in the Package Menu.
2417 For each installed package with a newer version available, place
2418 an (I)nstall flag on the available version and a (D)elete flag on
2419 the installed version. A subsequent \\[package-menu-execute]
2420 call will upgrade the package."
2422 (unless (derived-mode-p 'package-menu-mode)
2423 (error "The current buffer is not a Package Menu"))
2424 (let ((upgrades (package-menu--find-upgrades)))
2426 (message "No packages to upgrade.")
2429 (goto-char (point-min))
2431 (let* ((pkg-desc (tabulated-list-get-id))
2432 (upgrade (cdr (assq (package-desc-name pkg-desc) upgrades))))
2433 (cond ((null upgrade)
2435 ((equal pkg-desc upgrade)
2436 (package-menu-mark-install))
2438 (package-menu-mark-delete))))))
2439 (message "%d package%s marked for upgrading."
2441 (if (= (length upgrades) 1) "" "s")))))
2443 (defun package--sort-deps-in-alist (package only)
2444 "Return a list of dependencies for PACKAGE sorted by dependency.
2445 PACKAGE is included as the first element of the returned list.
2446 ONLY is an alist associating package names to package objects.
2447 Only these packages will be in the return value an their cdrs are
2448 destructively set to nil in ONLY."
2450 (dolist (dep (package-desc-reqs package))
2451 (when-let ((cell (assq (car dep) only))
2452 (dep-package (cdr-safe cell)))
2454 (setq out (append (package--sort-deps-in-alist dep-package only)
2456 (cons package out)))
2458 (defun package--sort-by-dependence (package-list)
2459 "Return PACKAGE-LIST sorted by dependence.
2460 That is, any element of the returned list is guaranteed to not
2461 directly depend on any elements that come before it.
2463 PACKAGE-LIST is a list of package-desc objects.
2464 Indirect dependencies are guaranteed to be returned in order only
2465 if all the in-between dependencies are also in PACKAGE-LIST."
2466 (let ((alist (mapcar (lambda (p) (cons (package-desc-name p) p)) package-list))
2468 (dolist (cell alist out-list)
2469 ;; `package--sort-deps-in-alist' destructively changes alist, so
2470 ;; some cells might already be empty. We check this here.
2471 (when-let ((pkg-desc (cdr cell)))
2474 (append (package--sort-deps-in-alist pkg-desc alist)
2477 (defun package-menu-execute (&optional noquery)
2478 "Perform marked Package Menu actions.
2479 Packages marked for installation are downloaded and installed;
2480 packages marked for deletion are removed.
2481 Optional argument NOQUERY non-nil means do not ask the user to confirm."
2483 (unless (derived-mode-p 'package-menu-mode)
2484 (error "The current buffer is not in Package Menu mode"))
2485 (let (install-list delete-list cmd pkg-desc)
2487 (goto-char (point-min))
2489 (setq cmd (char-after))
2490 (unless (eq cmd ?\s)
2491 ;; This is the key PKG-DESC.
2492 (setq pkg-desc (tabulated-list-get-id))
2494 (push pkg-desc delete-list))
2496 (push pkg-desc install-list))))
2502 (if (= (length install-list) 1)
2503 (format "Install package `%s'? "
2504 (package-desc-full-name (car install-list)))
2505 (format "Install these %d packages (%s)? "
2506 (length install-list)
2507 (mapconcat #'package-desc-full-name
2508 install-list ", ")))))
2510 ;; Don't mark as selected if it's a new version of
2511 ;; an installed package.
2512 (package-install p (and (not (package-installed-p p))
2513 (package-installed-p
2514 (package-desc-name p)))))
2516 ;; Delete packages, prompting if necessary.
2521 (if (= (length delete-list) 1)
2522 (format "Delete package `%s'? "
2523 (package-desc-full-name (car delete-list)))
2524 (format "Delete these %d packages (%s)? "
2525 (length delete-list)
2526 (mapconcat #'package-desc-full-name
2527 delete-list ", ")))))
2528 (dolist (elt (package--sort-by-dependence delete-list))
2529 (condition-case-unless-debug err
2530 (package-delete elt)
2531 (error (message (cadr err)))))
2533 (if (not (or delete-list install-list))
2534 (message "No operations specified.")
2535 (when package-selected-packages
2536 (let ((removable (package--removable-packages)))
2537 (when (and removable
2539 (format "These %d packages are no longer needed, delete them (%s)? "
2541 (mapconcat #'symbol-name removable ", "))))
2542 ;; We know these are removable, so we can use force instead of sorting them.
2543 (mapc (lambda (p) (package-delete (cadr (assq p package-alist)) 'force 'nosave))
2545 (package-menu--generate t t))))
2547 (defun package-menu--version-predicate (A B)
2548 (let ((vA (or (aref (cadr A) 1) '(0)))
2549 (vB (or (aref (cadr B) 1) '(0))))
2550 (if (version-list-= vA vB)
2551 (package-menu--name-predicate A B)
2552 (version-list-< vA vB))))
2554 (defun package-menu--status-predicate (A B)
2555 (let ((sA (aref (cadr A) 2))
2556 (sB (aref (cadr B) 2)))
2557 (cond ((string= sA sB)
2558 (package-menu--name-predicate A B))
2559 ((string= sA "new") t)
2560 ((string= sB "new") nil)
2561 ((string= sA "available") t)
2562 ((string= sB "available") nil)
2563 ((string= sA "installed") t)
2564 ((string= sB "installed") nil)
2565 ((string= sA "dependency") t)
2566 ((string= sB "dependency") nil)
2567 ((string= sA "unsigned") t)
2568 ((string= sB "unsigned") nil)
2569 ((string= sA "held") t)
2570 ((string= sB "held") nil)
2571 ((string= sA "built-in") t)
2572 ((string= sB "built-in") nil)
2573 ((string= sA "obsolete") t)
2574 ((string= sB "obsolete") nil)
2575 ((string= sA "incompat") t)
2576 ((string= sB "incompat") nil)
2577 (t (string< sA sB)))))
2579 (defun package-menu--description-predicate (A B)
2580 (let ((dA (aref (cadr A) 3))
2581 (dB (aref (cadr B) 3)))
2583 (package-menu--name-predicate A B)
2586 (defun package-menu--name-predicate (A B)
2587 (string< (symbol-name (package-desc-name (car A)))
2588 (symbol-name (package-desc-name (car B)))))
2590 (defun package-menu--archive-predicate (A B)
2591 (string< (or (package-desc-archive (car A)) "")
2592 (or (package-desc-archive (car B)) "")))
2595 (defun list-packages (&optional no-fetch)
2596 "Display a list of packages.
2597 This first fetches the updated list of packages before
2598 displaying, unless a prefix argument NO-FETCH is specified.
2599 The list is displayed in a buffer named `*Packages*'."
2601 (require 'finder-inf nil t)
2602 ;; Initialize the package system if necessary.
2603 (unless package--initialized
2604 (package-initialize t))
2605 (let (old-archives new-packages)
2607 ;; Read the locally-cached archive-contents.
2608 (package-read-all-archive-contents)
2609 (setq old-archives package-archive-contents)
2610 ;; Fetch the remote list of packages.
2611 (package-refresh-contents)
2612 ;; Find which packages are new.
2613 (dolist (elt package-archive-contents)
2614 (unless (assq (car elt) old-archives)
2615 (push (car elt) new-packages))))
2617 ;; Generate the Package Menu.
2618 (let ((buf (get-buffer-create "*Packages*")))
2619 (with-current-buffer buf
2621 (set (make-local-variable 'package-menu--new-package-list)
2623 (package-menu--generate nil t))
2624 ;; The package menu buffer has keybindings. If the user types
2625 ;; `M-x list-packages', that suggests it should become current.
2626 (switch-to-buffer buf))
2628 (let ((upgrades (package-menu--find-upgrades)))
2630 (message "%d package%s can be upgraded; type `%s' to mark %s for upgrading."
2632 (if (= (length upgrades) 1) "" "s")
2633 (substitute-command-keys "\\[package-menu-mark-upgrades]")
2634 (if (= (length upgrades) 1) "it" "them"))))))
2637 (defalias 'package-list-packages 'list-packages)
2639 ;; Used in finder.el
2640 (defun package-show-package-list (&optional packages keywords)
2641 "Display PACKAGES in a *Packages* buffer.
2642 This is similar to `list-packages', but it does not fetch the
2643 updated list of packages, and it only displays packages with
2644 names in PACKAGES (which should be a list of symbols).
2646 When KEYWORDS are given, only packages with those KEYWORDS are
2649 (require 'finder-inf nil t)
2650 (let* ((buf (get-buffer-create "*Packages*"))
2651 (win (get-buffer-window buf)))
2652 (with-current-buffer buf
2654 (package-menu--generate nil packages keywords))
2657 (switch-to-buffer buf))))
2659 ;; package-menu--generate rebinds "q" on the fly, so we have to
2660 ;; hard-code the binding in the doc-string here.
2661 (defun package-menu-filter (keyword)
2662 "Filter the *Packages* buffer.
2663 Show only those items that relate to the specified KEYWORD.
2664 To restore the full package list, type `q'."
2665 (interactive (list (completing-read "Keyword: " (package-all-keywords))))
2666 (package-show-package-list t (list keyword)))
2668 (defun package-list-packages-no-fetch ()
2669 "Display a list of packages.
2670 Does not fetch the updated list of packages before displaying.
2671 The list is displayed in a buffer named `*Packages*'."
2677 ;;; package.el ends here