* emacs-lisp/package.el (package-delete): Remove package from
`package-selected-packages' even if it can't be deleted.
+ (package-installed-p): Accept package-desc objects.
+ (package-install): Can be used to mark dependencies as
+ selected. When given a package-desc object which is already
+ installed, the package is not downloaded again, but it is marked
+ as selected (if it wasn't already).
2015-02-03 Artur Malabarba <bruce.connor.am@gmail.com>
(defun package-installed-p (package &optional min-version)
"Return true if PACKAGE, of MIN-VERSION or newer, is installed.
-MIN-VERSION should be a version list."
+If PACKAGE is a symbol, it is the package name and MIN-VERSION
+should be a version list.
+
+If PACKAGE is a package-desc object, MIN-VERSION is ignored."
(unless package--initialized (error "package.el is not yet initialized!"))
- (or
- (let ((pkg-descs (cdr (assq package package-alist))))
- (and pkg-descs
- (version-list-<= min-version
- (package-desc-version (car pkg-descs)))))
- ;; Also check built-in packages.
- (package-built-in-p package min-version)))
+ (if (package-desc-p package)
+ (let ((dir (package-desc-dir pkg-desc)))
+ (and (stringp dir)
+ (file-exists-p dir)))
+ (or
+ (let ((pkg-descs (cdr (assq package package-alist))))
+ (and pkg-descs
+ (version-list-<= min-version
+ (package-desc-version (car pkg-descs)))))
+ ;; Also check built-in packages.
+ (package-built-in-p package min-version))))
(defun package-compute-transaction (packages requirements &optional seen)
"Return a list of packages to be installed, including PACKAGES.
in an archive in `package-archives'. Interactively, prompt for its name.
If called interactively or if MARK-SELECTED is non-nil, add PKG
-to `package-selected-packages'."
+to `package-selected-packages'.
+
+if PKG is a package-desc and it is already installed, don't try
+to install it but still mark it as selected."
(interactive
(progn
;; Initialize the package system to get the list of package
(when (and mark-selected (not (package--user-selected-p name)))
(customize-save-variable 'package-selected-packages
(cons name package-selected-packages))))
- (package-download-transaction
- (if (package-desc-p pkg)
- (package-compute-transaction (list pkg)
- (package-desc-reqs pkg))
+ (if (package-desc-p pkg)
+ (if (package-installed-p pkg)
+ (message "`%s' is already installed" (package-desc-full-name pkg))
+ (package-download-transaction
+ (package-compute-transaction (list pkg)
+ (package-desc-reqs pkg))))
+ (package-download-transaction
(package-compute-transaction ()
(list (list pkg))))))