From 5687ac9f013618052bdf324e0751059c9d00ff87 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 4 Feb 2015 14:51:39 +0000 Subject: [PATCH] emacs-lisp/package.el (package-install): Mark dependencies as selected. In particular, when given a package-desc object which is already installed, the package is not downloaded again. --- lisp/ChangeLog | 5 +++++ lisp/emacs-lisp/package.el | 39 +++++++++++++++++++++++++------------- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 88abb4ff5f3..375304bff9e 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -2,6 +2,11 @@ * 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 diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el index b07362e6a5e..3d44755f46a 100644 --- a/lisp/emacs-lisp/package.el +++ b/lisp/emacs-lisp/package.el @@ -996,15 +996,22 @@ GnuPG keyring is located under \"gnupg\" in `package-user-dir'." (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. @@ -1219,7 +1226,10 @@ PKG can be a package-desc or the package name of one the available 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 @@ -1243,10 +1253,13 @@ to `package-selected-packages'." (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)))))) -- 2.39.2