RNA
RNA

Reputation: 153381

how to get the version of addons installed by Package?

Using elisp, how can I get the version of a package installed by the Emacs package management tool - Package? There must be some way to do that, because the version information is given in package buffer created by list-packages.

Upvotes: 2

Views: 379

Answers (1)

Chris Barrett
Chris Barrett

Reputation: 3375

(defun get-package-version (name)
  (when (member name package-activated-list)
    (package-desc-vers (cdr (assoc name package-alist)))))

Most package versions are stored as a list of [major-version minor-version]. Melpa packages that are built from GitHub use a time of form [YYYYMMDD hhmm] If you want a string from these lists, you can do something like:

(defun* package-version-string ((major minor))
  (format "%s.%s" major minor))

(package-version-string (get-package-version 'pep8))  ; => "1.2"

Update: To get packages that aren't installed, we can test membership of package-archive-contents, like so:

(defun get-not-installed-packages ()
  (remove-if (lambda (x) (assoc (car x) package-alist)) package-archive-contents))

(defun get-not-installed-package-version (name)
  (let ((pkg (assoc name (get-not-installed-packages))))
    (when pkg
      (package-desc-vers (cdr pkg)))))

Upvotes: 3

Related Questions