all repos — archive/dotfiles @ d81bf7b2b8f80b4d646a651b1218c8b18a2d9725

Superseded by nixfiles

Emacs: Create package archive query functions

Count packages installed from each archive
Show installed packages from an archive
Alan Pearce alan@alanpearce.co.uk
Fri, 11 Jul 2014 22:45:56 +0100
commit

d81bf7b2b8f80b4d646a651b1218c8b18a2d9725

parent

87fb552d62b2135fc6b11e1b073f0a901b639849

1 files changed, 30 insertions(+), 0 deletions(-)

jump to
M tag-emacs/emacs.d/init.eltag-emacs/emacs.d/init.el
@@ -55,6 +55,36 @@ :defer t   :config (progn
             (setq paradox-automatically-star t)))
 
+(defun package-list-installed ()
+  (loop for pkg in package-activated-list
+        collect (cadr (assq pkg package-archive-contents))))
+
+(defun package-archive-stats ()
+  (let ((archives (makehash))
+        (assoc '()))
+    (dolist (arc package-archives)
+      (puthash (car arc) 0 archives))
+    (maphash (lambda (k v)
+               (setq assoc (cons (cons k v) assoc)))
+             (dolist (pkg (package-list-installed) archives)
+               (let ((pkg-arc (package-desc-archive pkg)))
+                 (incf (gethash pkg-arc archives)))))
+    assoc))
+
+(defun package-show-installed-from-archive (archive)
+  (interactive (list (helm-comp-read "Archive: " (mapcar #'car package-archives)
+                                      :must-match t)))
+  (let ((from-arc (mapcar #'package-desc-name
+                          (--filter (equalp (package-desc-archive it) archive)
+                                    (package-list-installed)))))
+    (if (called-interactively-p)
+        (message "%s" from-arc)
+      from-arc)))
+
+(defun package-show-archive-stats ()
+  (interactive)
+  (message "%s" (package-archive-stats)))
+
 ;;;; Style
 
 (req-package linum