diff options
Diffstat (limited to 'lisp/use-package/use-package-core.el')
-rw-r--r-- | lisp/use-package/use-package-core.el | 158 |
1 files changed, 125 insertions, 33 deletions
diff --git a/lisp/use-package/use-package-core.el b/lisp/use-package/use-package-core.el index b5671ee249f..0734dcf1c80 100644 --- a/lisp/use-package/use-package-core.el +++ b/lisp/use-package/use-package-core.el @@ -6,7 +6,7 @@ ;; Maintainer: John Wiegley <johnw@newartisans.com> ;; Created: 17 Jun 2012 ;; Modified: 29 Nov 2017 -;; Version: 2.4 +;; Version: 2.4.1 ;; Package-Requires: ((emacs "24.3")) ;; Keywords: dotemacs startup speed config package ;; URL: https://github.com/jwiegley/use-package @@ -43,6 +43,16 @@ (require 'cl-lib) (require 'tabulated-list) +(eval-and-compile + ;; Declare a synthetic theme for :custom variables. + ;; Necessary in order to avoid having those variables saved by custom.el. + (deftheme use-package)) + +(enable-theme 'use-package) +;; Remove the synthetic use-package theme from the enabled themes, so +;; iterating over them to "disable all themes" won't disable it. +(setq custom-enabled-themes (remq 'use-package custom-enabled-themes)) + (if (and (eq emacs-major-version 24) (eq emacs-minor-version 3)) (defsubst hash-table-keys (hash-table) "Return a list of keys in HASH-TABLE." @@ -56,7 +66,7 @@ "A use-package declaration for simplifying your `.emacs'." :group 'startup) -(defconst use-package-version "2.4" +(defconst use-package-version "2.4.1" "This version of use-package.") (defcustom use-package-keywords @@ -90,7 +100,8 @@ :load ;; This must occur almost last; the only forms which should appear after ;; are those that must happen directly after the config forms. - :config) + :config + :local) "The set of valid keywords, in the order they are processed in. The order of this list is *very important*, so it is only advisable to insert new keywords, never to delete or reorder @@ -125,6 +136,13 @@ arguments will be ignored in the `use-package' expansion." :type 'boolean :group 'use-package) +(defcustom use-package-use-theme t + "If non-nil, use a custom theme to avoid saving :custom +variables twice (once in the Custom file, once in the use-package +call)." + :type 'boolean + :group 'use-package) + (defcustom use-package-verbose nil "Whether to report about loading and configuration details. If you customize this, then you should require the `use-package' @@ -299,14 +317,15 @@ include support for finding `use-package' and `require' forms. Must be set before loading use-package." :type 'boolean :set - #'(lambda (_sym value) + #'(lambda (sym value) (eval-after-load 'lisp-mode (if value `(add-to-list 'lisp-imenu-generic-expression (list "Packages" ,use-package-form-regexp-eval 2)) `(setq lisp-imenu-generic-expression (remove (list "Packages" ,use-package-form-regexp-eval 2) - lisp-imenu-generic-expression))))) + lisp-imenu-generic-expression)))) + (set-default sym value)) :group 'use-package) (defcustom use-package-compute-statistics nil @@ -882,12 +901,12 @@ If RECURSED is non-nil, recurse into sublists." "A predicate that recognizes functional constructions: nil sym - 'sym + \\='sym (quote sym) #'sym (function sym) (lambda () ...) - '(lambda () ...) + \\='(lambda () ...) (quote (lambda () ...)) #'(lambda () ...) (function (lambda () ...))" @@ -974,11 +993,10 @@ If RECURSED is non-nil, recurse into sublists." (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 package) - (gethash :init package) - (gethash :preface package) - (gethash :use-package package)))) + (or (gethash :config package) + (gethash :init package) + (gethash :preface package) + (gethash :use-package package))) (defun use-package-statistics-time (package) "Return the time is took for PACKAGE to load." @@ -998,7 +1016,9 @@ The information is formatted in a way suitable for (vector (symbol-name package) (use-package-statistics-status statistics) - (use-package-statistics-last-event statistics) + (format-time-string + "%H:%M:%S.%6N" + (use-package-statistics-last-event statistics)) (format "%.2f" (use-package-statistics-time statistics)))))) (defun use-package-report () @@ -1018,15 +1038,43 @@ meaning: (tabulated-list-print) (display-buffer (current-buffer)))) +(defvar use-package-statistics-status-order + '(("Declared" . 0) + ("Prefaced" . 1) + ("Initialized" . 2) + ("Configured" . 3))) + (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 characters: [("Package" 25 t) - ("Status" 13 t) - ("Last Event" 23 t) - ("Time" 10 t)]) + ("Status" 13 + (lambda (a b) + (< (assoc-default + (use-package-statistics-status + (gethash (car a) use-package-statistics)) + use-package-statistics-status-order) + (assoc-default + (use-package-statistics-status + (gethash (car b) use-package-statistics)) + use-package-statistics-status-order)))) + ("Last Event" 23 + (lambda (a b) + (< (float-time + (use-package-statistics-last-event + (gethash (car a) use-package-statistics))) + (float-time + (use-package-statistics-last-event + (gethash (car b) use-package-statistics)))))) + ("Time" 10 + (lambda (a b) + (< (use-package-statistics-time + (gethash (car a) use-package-statistics)) + (use-package-statistics-time + (gethash (car b) use-package-statistics)))))]) + (setq tabulated-list-sort-key '("Time" . t)) (tabulated-list-init-header)) (defun use-package-statistics-gather (keyword name after) @@ -1260,9 +1308,13 @@ meaning: (concat (symbol-name sym) use-package-hook-name-suffix))) (function ,fun))) - (if (use-package-non-nil-symbolp syms) (list syms) syms))))) + (use-package-hook-handler-normalize-mode-symbols syms))))) (use-package-normalize-commands args)))) +(defun use-package-hook-handler-normalize-mode-symbols (syms) + "Ensure that `SYMS' turns into a list of modes." + (if (use-package-non-nil-symbolp syms) (list syms) syms)) + ;;;; :commands (defalias 'use-package-normalize/:commands 'use-package-normalize-symlist) @@ -1380,17 +1432,34 @@ no keyword implies `:all'." (defun use-package-handler/:custom (name _keyword args rest state) "Generate use-package custom keyword code." (use-package-concat - (mapcar - #'(lambda (def) - (let ((variable (nth 0 def)) - (value (nth 1 def)) - (comment (nth 2 def))) - (unless (and comment (stringp comment)) - (setq comment (format "Customized with use-package %s" name))) - `(funcall (or (get (quote ,variable) 'custom-set) #'set-default) - (quote ,variable) - ,value))) - args) + (if (bound-and-true-p use-package-use-theme) + `((let ((custom--inhibit-theme-enable nil)) + ;; Declare the theme here so use-package can be required inside + ;; eval-and-compile without warnings about unknown theme. + (unless (memq 'use-package custom-known-themes) + (deftheme use-package) + (enable-theme 'use-package) + (setq custom-enabled-themes (remq 'use-package custom-enabled-themes))) + (custom-theme-set-variables + 'use-package + ,@(mapcar + #'(lambda (def) + (let ((variable (nth 0 def)) + (value (nth 1 def)) + (comment (nth 2 def))) + (unless (and comment (stringp comment)) + (setq comment (format "Customized with use-package %s" name))) + `'(,variable ,value nil () ,comment))) + args)))) + (mapcar + #'(lambda (def) + (let ((variable (nth 0 def)) + (value (nth 1 def)) + (comment (nth 2 def))) + (unless (and comment (stringp comment)) + (setq comment (format "Customized with use-package %s" name))) + `(customize-set-variable (quote ,variable) ,value ,comment))) + args)) (use-package-process-keywords name rest state))) ;;;; :custom-face @@ -1476,6 +1545,31 @@ no keyword implies `:all'." (when use-package-compute-statistics `((use-package-statistics-gather :config ',name t)))))) +;;;; :local + +(defun use-package-normalize/:local (name keyword args) + (let ((first-arg-name (symbol-name (caar args)))) + (if (not (string-suffix-p "-hook" first-arg-name)) + (let* ((sym-name (symbol-name name)) + (addition (if (string-suffix-p "-mode" sym-name) + "-hook" + "-mode-hook")) + (hook (intern (concat sym-name addition)))) + `((,hook . ,(use-package-normalize-forms name keyword args)))) + (cl-loop for (hook . code) in args + collect `(,hook . ,(use-package-normalize-forms name keyword code)))))) + +(defun use-package-handler/:local (name _keyword arg rest state) + (let* ((body (use-package-process-keywords name rest state))) + (use-package-concat + body + (cl-loop for (hook . code) in arg + for func-name = (intern (concat "use-package-func/" (symbol-name hook))) + collect (progn + (push 'progn code) + `(defun ,func-name () ,code)) + collect `(add-hook ',hook ',func-name))))) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;;; The main macro @@ -1556,13 +1650,13 @@ this file. Usage: :load-path Add to the `load-path' before attempting to load the package. :diminish Support for diminish.el (if installed). :delight Support for delight.el (if installed). -:custom Call `custom-set' or `set-default' with each variable +:custom Call `Custom-set' or `set-default' with each variable definition without modifying the Emacs `custom-file'. (compare with `custom-set-variables'). -:custom-face Call `customize-set-faces' with each face definition. +:custom-face Call `custom-set-faces' with each face definition. :ensure Loads the package using package.el if necessary. :pin Pin the package to an archive." - (declare (indent 1)) + (declare (indent defun)) (unless (memq :disabled args) (macroexp-progn (use-package-concat @@ -1581,8 +1675,6 @@ this file. Usage: (when use-package-compute-statistics `((use-package-statistics-gather :use-package ',name t))))))) -(put 'use-package 'lisp-indent-function 'defun) - (provide 'use-package-core) ;; Local Variables: |