Skip to content

Instantly share code, notes, and snippets.

@ctanis
Created September 13, 2013 18:50
Show Gist options
  • Save ctanis/6554562 to your computer and use it in GitHub Desktop.
Save ctanis/6554562 to your computer and use it in GitHub Desktop.
here's a function for determining how many emacs packages (using emacs 24 package system) are ready to upgrade. this is suitable for execution in batch-mode, perhaps as part of a script that routes output to a system-wide notification
(require 'package)
(add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/") t)
(add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/" ))
;(package-initialize) ;; trigger elpa packages
(defun get-updatable-count ()
(let (old-archives new-packages)
;; Read the locally-cached archive-contents.
(package-read-all-archive-contents)
(setq old-archives package-archive-contents)
;; Fetch the remote list of packages.
(package-refresh-contents)
;; Find which packages are new.
(dolist (elt package-archive-contents)
(unless (assq (car elt) old-archives)
(push (car elt) new-packages)))
(let ((buf (get-buffer-create "*Packages*")))
(with-current-buffer buf
(with-current-buffer buf
(package-menu-mode)
(set (make-local-variable 'package-menu--new-package-list)
new-packages)
(package-menu--generate nil t)))))
(with-current-buffer "*Packages*"
(let ((lst (package-menu--find-upgrades)))
(print (apply 'concat
(append
(list (format "%d packages can be updated:\n" (length lst)))
(mapcar
(lambda (s) (format "%s\n" (car s)))
lst)))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment