use-package-list.el (2431B)
1 ;;; use-package-list.el --- List use-package declarations in config file 2 3 ;; Copyright (C) 2017 Matthew Bauer 4 5 ;; Author: Matthew Bauer <mjbauer95@gmail.com> 6 7 ;; This file is NOT part of GNU Emacs. 8 9 ;;; Commentary: 10 11 ;; ‘ensure’ packages at compile time. 12 13 ;;; Code: 14 15 (require 'json) 16 (require 'use-package) 17 (require 'package) 18 (eval-when-compile 19 (require 'cl)) 20 21 (defun use-package-list (script) 22 "Count use-package declarations listed in SCRIPT." 23 24 (defvar use-package-list--is-running t) 25 (lexical-let ((use-package-verbose t) 26 (use-package-debug t) 27 (use-package-always-ensure nil) 28 (use-package-always-defer t) 29 (use-package-list--packages nil) 30 (use-package-ensure-function 'ignore)) 31 (advice-add 'use-package 32 :before (lambda (name &rest args) 33 (unless (or (and (member :disabled args) 34 (plist-get args :disabled)) 35 (and (member :ensure args) 36 (not (plist-get args :ensure))) 37 (and (not (member :ensure args)) 38 (package-built-in-p name))) 39 (when (and (member :ensure args) 40 (not (eq (plist-get args :ensure) t)) 41 (symbolp (plist-get args :ensure))) 42 (setq name (plist-get args :ensure))) 43 (add-to-list 'use-package-list--packages name)))) 44 45 (advice-add 'use-package-handler/:defer 46 :around (lambda (x name keyword arg rest state) 47 (let ((body (use-package-process-keywords name rest 48 (plist-put state :deferred t))) 49 (name-string (use-package-as-string name))) 50 (dolist (command 51 (delete-dups (plist-get state :commands))) 52 (fset command (lambda (&rest args)))) 53 body))) 54 55 (advice-add 'use-package-load-name :override #'ignore) 56 57 (load script nil nil t) 58 59 (princ (json-encode use-package-list--packages)) 60 61 use-package-list--packages)) 62 63 (provide 'use-package-list) 64 ;;; use-package-list.el ends here