Created
October 4, 2016 15:04
-
-
Save felipeochoa/1f1512dba8fe24601bc1e75b7af1e2ee to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun fov-list-packages-and-versions () | |
"Returns a list of all installed packages and their versions" | |
(mapcar | |
(lambda (pkg) | |
`(,pkg ,(package-desc-version | |
(cadr (assq pkg package-alist))))) | |
package-activated-list)) | |
;; Unfortunately the following function does not work | |
;; if the specific versions you need aren't the latest | |
;; versions published by the archives, and I'm not sure | |
;; how to get earlier versions from them | |
(defun fov-install-packages (package-version-list) | |
"Install the packages in the given list with specific versions. | |
PACKAGE-VERSION-LIST should be a list of (NAME VERSION) lists, | |
where NAME is a symbol identifying the package and VERSION is | |
a list identifying the version to install." | |
(let* | |
((count-found 0) | |
(count-failed 0) | |
(transaction | |
(with-output-to-temp-buffer "*Package Sync*" | |
(princ "Synchronizing packages:\n\n") | |
(dolist (pkg-ver package-version-list) | |
(princ (format " - %s --> %s\n" (car pkg-ver) (package-version-join (cadr pkg-ver))))) | |
(princ "\n\n") | |
(delq | |
'skip | |
(mapcar | |
(lambda (elt) | |
(let ((pkg (car elt)) (required-version (cadr elt))) | |
(if (package-installed-p pkg required-version) | |
;; This allow versions greater than required as well | |
(progn | |
(princ (format "Package `%s-%s' (or newer) is already installed.\n" | |
pkg (package-version-join required-version))) | |
'skip) | |
(let | |
((result | |
(catch 'break | |
(dolist (pkg-desc | |
(cdr (assq pkg package-archive-contents)) | |
(format "Did not find any releases for package `%s'\n" pkg)) | |
(let* ((version (package-desc-version pkg-desc)) | |
(disabled (package-disabled-p pkg version))) | |
(cond | |
((version-list-= required-version version) | |
(throw 'break | |
(if disabled | |
(if (stringp disabled) | |
(format "Package `%s' found version %s, but version %s required\n" | |
pkg disabled (package-version-join required-version)) | |
(format "Package '%s' is disabled\n" pkg)) | |
pkg-desc))) | |
((version-list-< version required-version) | |
(throw 'break (format "Need package `%s-%s', but only %s is available\n" | |
pkg (package-version-join required-version) | |
(package-version-join version)))))))))) | |
(if (stringp result) | |
(progn (incf count-failed) (princ result) 'skip) | |
(progn (incf count-found) | |
(princ (format "Found package `%s-%s'\n" pkg | |
(package-version-join (package-desc-version result)))) | |
result)))))) package-version-list))))) | |
(cond | |
((= count-found 0) | |
(message "Could not find any packages to install")) | |
((= count-failed 0) (when (y-or-n-p "Would you like to install `%d' packages?") | |
(package-download-transaction transaction))) | |
((y-or-n-p (format "Could not find `%d' packages to install. Would you like to install the other `%d' packages?" count-failed count-found)) | |
(package-download-transaction transaction))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment