As mentioned at how to automatically install emacs packages by specifying a list of package names?, it would be better to also record the version of the package you need. In order to do so, you can use the following function:
(defun 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))
That will give you a list of (NAME VERSION)
pairs. Unfortunately, I haven't been able to find a way to install a specific version of a package. It seems package.el
always grabs the latest available. What I'm doing now is:
(defun install-packages-with-specific-versions (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
the minimum version to install."
(package-download-transaction
(package-compute-transaction () package-version-list)))
I've written a longer function to install packages matching the exact version number, but it fails because package.el
by default only retrieves the latest versions available for each package. gist