diff options
author | John Wiegley <johnw@newartisans.com> | 2018-03-08 14:45:02 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-08 14:45:02 -0800 |
commit | 4cc7f9127058bc5847543e9f741824920f4eda74 (patch) | |
tree | 2477b1533d340550b65d63ec4b7c4d33ae8edce0 /lisp/use-package/use-package-core.el | |
parent | 76e6d3e8bc348abc48f1bbb2ea100f069e18380c (diff) | |
parent | ae22d74a166da46eb3ac689e75383508b17cb3f8 (diff) | |
download | emacs-4cc7f9127058bc5847543e9f741824920f4eda74.tar.gz emacs-4cc7f9127058bc5847543e9f741824920f4eda74.tar.bz2 emacs-4cc7f9127058bc5847543e9f741824920f4eda74.zip |
Merge pull request from DamienCassou/tabulated-list
Use a tabulated-list to display package configuration statistics
GitHub-reference: https://github.com/jwiegley/use-package/issues/642
Diffstat (limited to 'lisp/use-package/use-package-core.el')
-rw-r--r-- | lisp/use-package/use-package-core.el | 78 |
1 files changed, 54 insertions, 24 deletions
diff --git a/lisp/use-package/use-package-core.el b/lisp/use-package/use-package-core.el index a649d087fae..83630b80785 100644 --- a/lisp/use-package/use-package-core.el +++ b/lisp/use-package/use-package-core.el @@ -41,6 +41,7 @@ (require 'bytecomp) (require 'cl-lib) +(require 'tabulated-list) (eval-when-compile (require 'cl) @@ -964,6 +965,43 @@ If RECURSED is non-nil, recurse into sublists." (interactive) (setq use-package-statistics (make-hash-table))) +(defun use-package-statistics-status (package) + "Return loading configuration status of PACKAGE." + (cond ((gethash :config statistics) "Configured") + ((gethash :init statistics) "Initialized") + ((gethash :preface statistics) "Prefaced") + ((gethash :use-package statistics) "Declared"))) + +(defun use-package-statistics-last-event (package) + "Return the date when package's status last changed. +The date is returned as a string." + (format-time-string "%Y-%m-%d %a %H:%M" + (or (gethash :config statistics) + (gethash :init statistics) + (gethash :preface statistics) + (gethash :use-package statistics)))) + +(defun use-package-statistics-time (package) + "Return the time is took for package to load." + (+ (float-time (gethash :config-secs statistics 0)) + (float-time (gethash :init-secs statistics 0)) + (float-time (gethash :preface-secs statistics 0)) + (float-time (gethash :use-package-secs statistics 0)))) + +(defun use-package-statistics-convert (package) + "Return information about PACKAGE. + +The information is formatted in a way suitable for +`use-package-statistics-mode'." + (let ((statistics (gethash package use-package-statistics))) + (list + package + (vector + (symbol-name package) + (use-package-statistics-status package) + (use-package-statistics-last-event package) + (format "%.2f" (use-package-statistics-time package)))))) + (defun use-package-report () "Show current statistics gathered about use-package declarations. In the table that's generated, the status field has the following @@ -974,32 +1012,24 @@ meaning: Declared the use-package declaration was seen" (interactive) (with-current-buffer (get-buffer-create "*use-package statistics*") - (delete-region (point-min) (point-max)) - (insert "|Package|Status|Last Event|Time|\n") - (insert "|-\n") - (maphash - #'(lambda (key hash) - (insert - (format "|%s |%s|%s |%.2f|\n" key - (cond ((gethash :config hash) "Configured") - ((gethash :init hash) "Initialized") - ((gethash :preface hash) "Prefaced") - ((gethash :use-package hash) "Declared")) - (format-time-string "[%Y-%m-%d %a %H:%M]" - (or (gethash :config hash) - (gethash :init hash) - (gethash :preface hash) - (gethash :use-package hash))) - (+ (float-time (gethash :config-secs hash 0)) - (float-time (gethash :init-secs hash 0)) - (float-time (gethash :preface-secs hash 0)) - (float-time (gethash :use-package-secs hash 0)))))) - use-package-statistics) - (goto-char (point-min)) - (orgtbl-mode) - (org-table-align) + (setq tabulated-list-entries + (mapcar #'use-package-statistics-convert + (hash-table-keys use-package-statistics))) + (use-package-statistics-mode) + (tabulated-list-print) (display-buffer (current-buffer)))) +(define-derived-mode use-package-statistics-mode tabulated-list-mode + "use-package statistics" + "Show current statistics gathered about use-package declarations." + (setq tabulated-list-format + ;; The sum of column width is 80 caracters: + #[("Package" 25 t) + ("Status" 13 t) + ("Last Event" 23 t) + ("Time" 10 t)]) + (tabulated-list-init-header)) + (defun use-package-statistics-gather (keyword name after) (let* ((hash (gethash name use-package-statistics (make-hash-table))) |