diff options
| author | John Wiegley | 2017-12-03 03:07:30 -0800 |
|---|---|---|
| committer | John Wiegley | 2017-12-03 03:09:26 -0800 |
| commit | 9ab797cccdcb8bd583c0e3148e1aeb251bf05fec (patch) | |
| tree | 3e927a738cd483799c5eb3c49f5a8fb0f8dc2e78 | |
| parent | a9429350d53d4b408600e1b43542e09aa9dc503d (diff) | |
| download | emacs-9ab797cccdcb8bd583c0e3148e1aeb251bf05fec.tar.gz emacs-9ab797cccdcb8bd583c0e3148e1aeb251bf05fec.zip | |
A great deal of internal reorganization and simplification
All handlers now address their own domain of work; :after has become safer;
keyword normalization is multi-stage process; setting use-package-verbose to
`debug' produces useful output in the *use-package* buffer in the case of load
time errors; use-package errors (even internal) won't stop Emacs from
starting (though a serious internal bug that errors out every use-package form
may stop anything from being configured!); and more.
| -rw-r--r-- | etc/USE-PACKAGE-NEWS | 6 | ||||
| -rw-r--r-- | lisp/use-package/use-package.el | 875 | ||||
| -rw-r--r-- | test/lisp/use-package/use-package-tests.el | 420 |
3 files changed, 715 insertions, 586 deletions
diff --git a/etc/USE-PACKAGE-NEWS b/etc/USE-PACKAGE-NEWS index 06adac97188..c65aae64f10 100644 --- a/etc/USE-PACKAGE-NEWS +++ b/etc/USE-PACKAGE-NEWS | |||
| @@ -18,6 +18,12 @@ | |||
| 18 | - The `:defer-install` keyword has been remove. It may reappear as an add-on | 18 | - The `:defer-install` keyword has been remove. It may reappear as an add-on |
| 19 | module for use-package in a future release. See issue #442 for more details. | 19 | module for use-package in a future release. See issue #442 for more details. |
| 20 | 20 | ||
| 21 | - The ordering of several elements of `use-package-keywords' have changed; if | ||
| 22 | you have this customized you will need to rework your changes. | ||
| 23 | |||
| 24 | - There is no longer a `use-package-debug` option, since `use-package-verbose` | ||
| 25 | already has the possible value of `debug`. | ||
| 26 | |||
| 21 | ### Other changes | 27 | ### Other changes |
| 22 | 28 | ||
| 23 | - Upgrade license to GPL 3. | 29 | - Upgrade license to GPL 3. |
diff --git a/lisp/use-package/use-package.el b/lisp/use-package/use-package.el index bfaac24e48e..3dab8ec8521 100644 --- a/lisp/use-package/use-package.el +++ b/lisp/use-package/use-package.el | |||
| @@ -67,11 +67,6 @@ then the expanded macros do their job silently." | |||
| 67 | (const :tag "Debug" debug)) | 67 | (const :tag "Debug" debug)) |
| 68 | :group 'use-package) | 68 | :group 'use-package) |
| 69 | 69 | ||
| 70 | (defcustom use-package-debug nil | ||
| 71 | "Whether to display use-package expansions in a *use-package* buffer." | ||
| 72 | :type 'boolean | ||
| 73 | :group 'use-package) | ||
| 74 | |||
| 75 | (defcustom use-package-check-before-init nil | 70 | (defcustom use-package-check-before-init nil |
| 76 | "If non-nil, check that package exists before executing its `:init' block. | 71 | "If non-nil, check that package exists before executing its `:init' block. |
| 77 | The check is performed by looking for the module using `locate-library'." | 72 | The check is performed by looking for the module using `locate-library'." |
| @@ -136,15 +131,15 @@ the user specified." | |||
| 136 | '(:disabled | 131 | '(:disabled |
| 137 | :pin | 132 | :pin |
| 138 | :ensure | 133 | :ensure |
| 139 | :if | 134 | :if :when :unless |
| 140 | :when | ||
| 141 | :unless | ||
| 142 | :requires | 135 | :requires |
| 143 | :load-path | 136 | :load-path |
| 144 | :defines | ||
| 145 | :functions | ||
| 146 | :preface | ||
| 147 | :no-require | 137 | :no-require |
| 138 | :preface :defines :functions | ||
| 139 | :after | ||
| 140 | :custom | ||
| 141 | :custom-face | ||
| 142 | :init | ||
| 148 | :bind | 143 | :bind |
| 149 | :bind* | 144 | :bind* |
| 150 | :bind-keymap | 145 | :bind-keymap |
| @@ -153,14 +148,15 @@ the user specified." | |||
| 153 | :mode | 148 | :mode |
| 154 | :magic | 149 | :magic |
| 155 | :magic-fallback | 150 | :magic-fallback |
| 156 | :commands | ||
| 157 | :hook | 151 | :hook |
| 152 | ;; Any other keyword that also declares commands to be autoloaded (such as | ||
| 153 | ;; :bind) must appear before this keyword. | ||
| 154 | :commands | ||
| 158 | :defer | 155 | :defer |
| 159 | :custom | ||
| 160 | :custom-face | ||
| 161 | :init | ||
| 162 | :after | ||
| 163 | :demand | 156 | :demand |
| 157 | :load | ||
| 158 | ;; This must occur almost last; the only forms which should appear after | ||
| 159 | ;; are those that must happen directly after the config forms. | ||
| 164 | :config | 160 | :config |
| 165 | :diminish | 161 | :diminish |
| 166 | :delight) | 162 | :delight) |
| @@ -209,8 +205,23 @@ The default value uses package.el to install the package." | |||
| 209 | :group 'use-package) | 205 | :group 'use-package) |
| 210 | 206 | ||
| 211 | (defcustom use-package-defaults | 207 | (defcustom use-package-defaults |
| 212 | '((:config '(t) t) | 208 | '((:config '(t) t) ; this '(t) has special meaning; see |
| 213 | (:ensure use-package-always-ensure use-package-always-ensure) | 209 | ; the handler for :config |
| 210 | (:init nil t) | ||
| 211 | (:defer use-package-always-defer | ||
| 212 | (lambda (args) | ||
| 213 | (and use-package-always-defer | ||
| 214 | (not (plist-member args :defer)) | ||
| 215 | (not (plist-member args :demand))))) | ||
| 216 | (:demand use-package-always-demand | ||
| 217 | (lambda (args) | ||
| 218 | (and use-package-always-demand | ||
| 219 | (not (plist-member args :defer)) | ||
| 220 | (not (plist-member args :demand))))) | ||
| 221 | (:ensure use-package-always-ensure | ||
| 222 | (lambda (args) | ||
| 223 | (and use-package-always-ensure | ||
| 224 | (not (plist-member args :load-path))))) | ||
| 214 | (:pin use-package-always-pin use-package-always-pin)) | 225 | (:pin use-package-always-pin use-package-always-pin)) |
| 215 | "Alist of default values for `use-package' keywords. | 226 | "Alist of default values for `use-package' keywords. |
| 216 | Each entry in the alist is a list of three elements. The first | 227 | Each entry in the alist is a list of three elements. The first |
| @@ -219,9 +230,19 @@ that can be evaluated to get the default value. The third element | |||
| 219 | is a form that can be evaluated to determine whether or not to | 230 | is a form that can be evaluated to determine whether or not to |
| 220 | assign a default value; if it evaluates to nil, then the default | 231 | assign a default value; if it evaluates to nil, then the default |
| 221 | value is not assigned even if the keyword is not present in the | 232 | value is not assigned even if the keyword is not present in the |
| 222 | `use-package' form." | 233 | `use-package' form. This third element may also be a function, in |
| 223 | :type '(repeat (list symbol sexp sexp))) | 234 | which case it receives the list of keywords (in normalized form), |
| 235 | and should return nil or t according to whether defaulting should | ||
| 236 | be attempted." | ||
| 237 | :type `(repeat | ||
| 238 | (list (choice :tag "Keyword" | ||
| 239 | ,@(mapcar #'(lambda (k) (list 'const k)) | ||
| 240 | use-package-keywords)) | ||
| 241 | (choice :tag "Default value" sexp) | ||
| 242 | (choice :tag "Enable if non-nil" sexp function))) | ||
| 243 | :group 'use-package) | ||
| 224 | 244 | ||
| 245 | ;;; jww (2017-12-02): This should be in the :set for the option. | ||
| 225 | (when use-package-enable-imenu-support | 246 | (when use-package-enable-imenu-support |
| 226 | (eval-after-load 'lisp-mode | 247 | (eval-after-load 'lisp-mode |
| 227 | `(let ((sym-regexp (or (bound-and-true-p lisp-mode-symbol-regexp) | 248 | `(let ((sym-regexp (or (bound-and-true-p lisp-mode-symbol-regexp) |
| @@ -308,56 +329,35 @@ whether it's a string or symbol." | |||
| 308 | `(load ,name ,noerror) | 329 | `(load ,name ,noerror) |
| 309 | `(require ',name nil ,noerror))) | 330 | `(require ',name nil ,noerror))) |
| 310 | 331 | ||
| 311 | (defun use-package-expand (name label form) | ||
| 312 | "FORM is a list of forms, so `((foo))' if only `foo' is being called." | ||
| 313 | (declare (indent 1)) | ||
| 314 | (when form | ||
| 315 | (if use-package-expand-minimally | ||
| 316 | form | ||
| 317 | (let ((err (make-symbol "err"))) | ||
| 318 | (list | ||
| 319 | `(condition-case-unless-debug ,err | ||
| 320 | ,(macroexp-progn form) | ||
| 321 | (error | ||
| 322 | (ignore | ||
| 323 | (display-warning 'use-package | ||
| 324 | (format "%s %s: %s" | ||
| 325 | ,name ,label (error-message-string ,err)) | ||
| 326 | :error))))))))) | ||
| 327 | |||
| 328 | (put 'use-package-expand 'lisp-indent-function 'defun) | ||
| 329 | |||
| 330 | (defun use-package-hook-injector (name-string keyword body) | 332 | (defun use-package-hook-injector (name-string keyword body) |
| 331 | "Wrap pre/post hook injections around a given keyword form. | 333 | "Wrap pre/post hook injections around a given keyword form. |
| 332 | ARGS is a list of forms, so `((foo))' if only `foo' is being called." | 334 | ARGS is a list of forms, so `((foo))' if only `foo' is being called." |
| 333 | (if (not use-package-inject-hooks) | 335 | (if (not use-package-inject-hooks) |
| 334 | (use-package-expand name-string (format "%s" keyword) body) | 336 | body |
| 335 | (let ((keyword-name (substring (format "%s" keyword) 1))) | 337 | (let ((keyword-name (substring (format "%s" keyword) 1))) |
| 336 | `((when ,(macroexp-progn | 338 | `((when (run-hook-with-args-until-failure |
| 337 | (use-package-expand name-string (format "pre-%s hook" keyword) | 339 | ',(intern (concat "use-package--" name-string |
| 338 | `((run-hook-with-args-until-failure | 340 | "--pre-" keyword-name "-hook"))) |
| 339 | ',(intern (concat "use-package--" name-string | 341 | ,@body |
| 340 | "--pre-" keyword-name "-hook")))))) | 342 | (run-hooks |
| 341 | ,(macroexp-progn | 343 | ',(intern (concat "use-package--" name-string |
| 342 | (use-package-expand name-string (format "%s" keyword) body)) | 344 | "--post-" keyword-name "-hook")))))))) |
| 343 | ,(macroexp-progn | ||
| 344 | (use-package-expand name-string (format "post-%s hook" keyword) | ||
| 345 | `((run-hooks | ||
| 346 | ',(intern (concat "use-package--" name-string | ||
| 347 | "--post-" keyword-name "-hook"))))))))))) | ||
| 348 | 345 | ||
| 349 | (defun use-package--require (name &optional no-require body) | 346 | (defun use-package--require (name &optional no-require body) |
| 350 | (use-package--with-elapsed-timer | 347 | (if use-package-expand-minimally |
| 351 | (format "Loading package %s" name) | 348 | (use-package-concat |
| 352 | (if use-package-expand-minimally | 349 | (unless no-require |
| 353 | (use-package-concat | 350 | (list (use-package-load-name name))) |
| 354 | (unless no-require | 351 | body) |
| 355 | (list (use-package-load-name name))) | 352 | (if no-require |
| 356 | body) | 353 | body |
| 357 | (if no-require | 354 | (use-package--with-elapsed-timer |
| 358 | body | 355 | (format "Loading package %s" name) |
| 359 | `((if (not ,(use-package-load-name name t)) | 356 | `((if (not ,(use-package-load-name name t)) |
| 360 | (ignore (message (format "Cannot load %s" ',name))) | 357 | (ignore |
| 358 | (display-warning 'use-package | ||
| 359 | (format "Cannot load %s" ',name) | ||
| 360 | :error)) | ||
| 361 | ,@body)))))) | 361 | ,@body)))))) |
| 362 | 362 | ||
| 363 | (defun use-package--with-elapsed-timer (text body) | 363 | (defun use-package--with-elapsed-timer (text body) |
| @@ -408,6 +408,18 @@ This is in contrast to merely setting it to 0." | |||
| 408 | (setq plist (cddr plist))) | 408 | (setq plist (cddr plist))) |
| 409 | p)) | 409 | p)) |
| 410 | 410 | ||
| 411 | (defun use-package-plist-delete-first (plist property) | ||
| 412 | "Delete PROPERTY from PLIST. | ||
| 413 | This is in contrast to merely setting it to 0." | ||
| 414 | (let (p) | ||
| 415 | (while plist | ||
| 416 | (if (eq property (car plist)) | ||
| 417 | (setq p (nconc p (cddr plist)) | ||
| 418 | plist nil) | ||
| 419 | (setq p (nconc p (list (car plist) (cadr plist))) | ||
| 420 | plist (cddr plist)))) | ||
| 421 | p)) | ||
| 422 | |||
| 411 | (defun use-package-split-list (pred xs) | 423 | (defun use-package-split-list (pred xs) |
| 412 | (let ((ys (list nil)) (zs (list nil)) flip) | 424 | (let ((ys (list nil)) (zs (list nil)) flip) |
| 413 | (dolist (x xs) | 425 | (dolist (x xs) |
| @@ -445,7 +457,7 @@ This is in contrast to merely setting it to 0." | |||
| 445 | 457 | ||
| 446 | (defsubst use-package-concat (&rest elems) | 458 | (defsubst use-package-concat (&rest elems) |
| 447 | "Delete all empty lists from ELEMS (nil or (list nil)), and append them." | 459 | "Delete all empty lists from ELEMS (nil or (list nil)), and append them." |
| 448 | (apply #'nconc (delete nil (delete (list nil) elems)))) | 460 | (apply #'append (delete nil (delete (list nil) elems)))) |
| 449 | 461 | ||
| 450 | (defsubst use-package--non-nil-symbolp (sym) | 462 | (defsubst use-package--non-nil-symbolp (sym) |
| 451 | (and sym (symbolp sym))) | 463 | (and sym (symbolp sym))) |
| @@ -484,28 +496,32 @@ This is in contrast to merely setting it to 0." | |||
| 484 | (t | 496 | (t |
| 485 | (error "Not recognized as regular expression: %s" re)))) | 497 | (error "Not recognized as regular expression: %s" re)))) |
| 486 | 498 | ||
| 487 | (defun use-package-normalize-plist (name input) | 499 | (defun use-package-normalize-plist (name input &optional plist merge-function) |
| 488 | "Given a pseudo-plist, normalize it to a regular plist." | 500 | "Given a pseudo-plist, normalize it to a regular plist. |
| 489 | (unless (null input) | 501 | The normalized key/value pairs from input are added to PLIST, |
| 502 | extending any keys already present." | ||
| 503 | (when input | ||
| 490 | (let* ((keyword (car input)) | 504 | (let* ((keyword (car input)) |
| 491 | (xs (use-package-split-list #'keywordp (cdr input))) | 505 | (xs (use-package-split-list #'keywordp (cdr input))) |
| 492 | (args (car xs)) | 506 | (args (car xs)) |
| 493 | (tail (cdr xs)) | 507 | (tail (cdr xs)) |
| 494 | (normalizer (intern (concat "use-package-normalize/" | 508 | (normalizer (intern (concat "use-package-normalize/" |
| 495 | (symbol-name keyword)))) | 509 | (symbol-name keyword)))) |
| 496 | (arg | 510 | (arg (cond ((functionp normalizer) |
| 497 | (cond | 511 | (funcall normalizer name keyword args)) |
| 498 | ((eq keyword :disabled) | 512 | ((= (length args) 1) |
| 499 | (use-package-normalize-plist name tail)) | 513 | (car args)) |
| 500 | ((functionp normalizer) | 514 | (t |
| 501 | (funcall normalizer name keyword args)) | 515 | args)))) |
| 502 | ((= (length args) 1) | ||
| 503 | (car args)) | ||
| 504 | (t | ||
| 505 | args)))) | ||
| 506 | (if (memq keyword use-package-keywords) | 516 | (if (memq keyword use-package-keywords) |
| 507 | (cons keyword | 517 | (progn |
| 508 | (cons arg (use-package-normalize-plist name tail))) | 518 | (setq plist (use-package-normalize-plist |
| 519 | name tail plist merge-function)) | ||
| 520 | (plist-put plist keyword | ||
| 521 | (if (plist-member plist keyword) | ||
| 522 | (funcall merge-function keyword | ||
| 523 | arg (plist-get plist keyword)) | ||
| 524 | arg))) | ||
| 509 | (ignore | 525 | (ignore |
| 510 | (display-warning 'use-package | 526 | (display-warning 'use-package |
| 511 | (format "Unrecognized keyword: %s" keyword) | 527 | (format "Unrecognized keyword: %s" keyword) |
| @@ -542,6 +558,16 @@ next value for the STATE." | |||
| 542 | 558 | ||
| 543 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 559 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 544 | ;; | 560 | ;; |
| 561 | ;;; :disabled | ||
| 562 | ;; | ||
| 563 | |||
| 564 | (defalias 'use-package-normalize/:disabled 'ignore) | ||
| 565 | |||
| 566 | (defun use-package-handler/:disabled (name keyword arg rest state) | ||
| 567 | (use-package-process-keywords name rest state)) | ||
| 568 | |||
| 569 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
| 570 | ;; | ||
| 545 | ;;; :pin | 571 | ;;; :pin |
| 546 | ;; | 572 | ;; |
| 547 | 573 | ||
| @@ -560,13 +586,13 @@ next value for the STATE." | |||
| 560 | 586 | ||
| 561 | (defun use-package-normalize/:pin (name keyword args) | 587 | (defun use-package-normalize/:pin (name keyword args) |
| 562 | (use-package-only-one (symbol-name keyword) args | 588 | (use-package-only-one (symbol-name keyword) args |
| 563 | (lambda (label arg) | 589 | #'(lambda (label arg) |
| 564 | (cond | 590 | (cond |
| 565 | ((stringp arg) arg) | 591 | ((stringp arg) arg) |
| 566 | ((use-package--non-nil-symbolp arg) (symbol-name arg)) | 592 | ((use-package--non-nil-symbolp arg) (symbol-name arg)) |
| 567 | (t | 593 | (t |
| 568 | (use-package-error | 594 | (use-package-error |
| 569 | ":pin wants an archive name (a string)")))))) | 595 | ":pin wants an archive name (a string)")))))) |
| 570 | 596 | ||
| 571 | (eval-when-compile | 597 | (eval-when-compile |
| 572 | (defvar package-pinned-packages) | 598 | (defvar package-pinned-packages) |
| @@ -619,12 +645,12 @@ manually updated package." | |||
| 619 | (if (null args) | 645 | (if (null args) |
| 620 | t | 646 | t |
| 621 | (use-package-only-one (symbol-name keyword) args | 647 | (use-package-only-one (symbol-name keyword) args |
| 622 | (lambda (label arg) | 648 | #'(lambda (label arg) |
| 623 | (if (symbolp arg) | 649 | (if (symbolp arg) |
| 624 | arg | 650 | arg |
| 625 | (use-package-error | 651 | (use-package-error |
| 626 | (concat ":ensure wants an optional package name " | 652 | (concat ":ensure wants an optional package name " |
| 627 | "(an unquoted symbol name)"))))))) | 653 | "(an unquoted symbol name)"))))))) |
| 628 | 654 | ||
| 629 | (defun use-package-ensure-elpa (name ensure state &optional no-refresh) | 655 | (defun use-package-ensure-elpa (name ensure state &optional no-refresh) |
| 630 | (let ((package | 656 | (let ((package |
| @@ -675,6 +701,7 @@ manually updated package." | |||
| 675 | (defsubst use-package-normalize-value (label arg) | 701 | (defsubst use-package-normalize-value (label arg) |
| 676 | "Normalize a value." | 702 | "Normalize a value." |
| 677 | (cond ((null arg) nil) | 703 | (cond ((null arg) nil) |
| 704 | ((eq t arg) t) | ||
| 678 | ((use-package--non-nil-symbolp arg) | 705 | ((use-package--non-nil-symbolp arg) |
| 679 | `(symbol-value ',arg)) | 706 | `(symbol-value ',arg)) |
| 680 | ((functionp arg) | 707 | ((functionp arg) |
| @@ -756,9 +783,9 @@ If ALLOW-EMPTY is non-nil, it's OK for ARGS to be an empty list." | |||
| 756 | (let ((body (use-package-process-keywords name rest state))) | 783 | (let ((body (use-package-process-keywords name rest state))) |
| 757 | (if (null requires) | 784 | (if (null requires) |
| 758 | body | 785 | body |
| 759 | `((when ,(if (listp requires) | 786 | `((when ,(if (> (length requires) 1) |
| 760 | `(not (member nil (mapcar #'featurep ',requires))) | 787 | `(not (member nil (mapcar #'featurep ',requires))) |
| 761 | `(featurep ',requires)) | 788 | `(featurep ',(car requires))) |
| 762 | ,@body))))) | 789 | ,@body))))) |
| 763 | 790 | ||
| 764 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 791 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| @@ -809,9 +836,7 @@ If ALLOW-EMPTY is non-nil, it's OK for ARGS to be an empty list." | |||
| 809 | (defalias 'use-package-normalize/:no-require 'use-package-normalize-predicate) | 836 | (defalias 'use-package-normalize/:no-require 'use-package-normalize-predicate) |
| 810 | 837 | ||
| 811 | (defun use-package-handler/:no-require (name keyword arg rest state) | 838 | (defun use-package-handler/:no-require (name keyword arg rest state) |
| 812 | ;; This keyword has no functional meaning. | 839 | (use-package-process-keywords name rest state)) |
| 813 | (use-package-process-keywords name rest | ||
| 814 | (plist-put state :no-require t))) | ||
| 815 | 840 | ||
| 816 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 841 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 817 | ;; | 842 | ;; |
| @@ -842,6 +867,26 @@ If ALLOW-EMPTY is non-nil, it's OK for ARGS to be an empty list." | |||
| 842 | 867 | ||
| 843 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 868 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 844 | ;; | 869 | ;; |
| 870 | ;;; :defines | ||
| 871 | ;; | ||
| 872 | |||
| 873 | (defalias 'use-package-normalize/:defines 'use-package-normalize-symlist) | ||
| 874 | |||
| 875 | (defun use-package-handler/:defines (name keyword arg rest state) | ||
| 876 | (use-package-process-keywords name rest state)) | ||
| 877 | |||
| 878 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
| 879 | ;; | ||
| 880 | ;;; :functions | ||
| 881 | ;; | ||
| 882 | |||
| 883 | (defalias 'use-package-normalize/:functions 'use-package-normalize-symlist) | ||
| 884 | |||
| 885 | (defun use-package-handler/:functions (name keyword arg rest state) | ||
| 886 | (use-package-process-keywords name rest state)) | ||
| 887 | |||
| 888 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
| 889 | ;; | ||
| 845 | ;;; :bind, :bind* | 890 | ;;; :bind, :bind* |
| 846 | ;; | 891 | ;; |
| 847 | 892 | ||
| @@ -948,18 +993,18 @@ representing symbols (that may need to be autloaded)." | |||
| 948 | 993 | ||
| 949 | (defun use-package-normalize-binder (name keyword args) | 994 | (defun use-package-normalize-binder (name keyword args) |
| 950 | (use-package-as-one (symbol-name keyword) args | 995 | (use-package-as-one (symbol-name keyword) args |
| 951 | (lambda (label arg) | 996 | #'(lambda (label arg) |
| 952 | (unless (consp arg) | 997 | (unless (consp arg) |
| 953 | (use-package-error | 998 | (use-package-error |
| 954 | (concat label " a (<string or vector> . <symbol, string or function>)" | 999 | (concat label " a (<string or vector> . <symbol, string or function>)" |
| 955 | " or list of these"))) | 1000 | " or list of these"))) |
| 956 | (use-package-normalize-pairs | 1001 | (use-package-normalize-pairs |
| 957 | #'(lambda (k) | 1002 | #'(lambda (k) |
| 958 | (pcase k | 1003 | (pcase k |
| 959 | ((pred stringp) t) | 1004 | ((pred stringp) t) |
| 960 | ((pred vectorp) t))) | 1005 | ((pred vectorp) t))) |
| 961 | #'(lambda (v) (use-package--recognize-function v t #'stringp)) | 1006 | #'(lambda (v) (use-package--recognize-function v t #'stringp)) |
| 962 | name label arg)))) | 1007 | name label arg)))) |
| 963 | 1008 | ||
| 964 | (defalias 'use-package-normalize/:bind 'use-package-normalize-binder) | 1009 | (defalias 'use-package-normalize/:bind 'use-package-normalize-binder) |
| 965 | (defalias 'use-package-normalize/:bind* 'use-package-normalize-binder) | 1010 | (defalias 'use-package-normalize/:bind* 'use-package-normalize-binder) |
| @@ -971,8 +1016,8 @@ representing symbols (that may need to be autloaded)." | |||
| 971 | (use-package-concat | 1016 | (use-package-concat |
| 972 | (use-package-process-keywords name | 1017 | (use-package-process-keywords name |
| 973 | (use-package-sort-keywords | 1018 | (use-package-sort-keywords |
| 974 | (use-package-plist-maybe-put rest :defer t)) | 1019 | (use-package-plist-append rest :commands commands)) |
| 975 | (use-package-plist-append state :commands commands)) | 1020 | state) |
| 976 | `((ignore | 1021 | `((ignore |
| 977 | (,(if bind-macro bind-macro 'bind-keys) | 1022 | (,(if bind-macro bind-macro 'bind-keys) |
| 978 | :package ,name ,@nargs)))))) | 1023 | :package ,name ,@nargs)))))) |
| @@ -1031,10 +1076,7 @@ representing symbols (that may need to be autloaded)." | |||
| 1031 | ',(cdr binding) ',(use-package-as-symbol name) | 1076 | ',(cdr binding) ',(use-package-as-symbol name) |
| 1032 | ,override)))) arg))) | 1077 | ,override)))) arg))) |
| 1033 | (use-package-concat | 1078 | (use-package-concat |
| 1034 | (use-package-process-keywords name | 1079 | (use-package-process-keywords name rest state) |
| 1035 | (use-package-sort-keywords | ||
| 1036 | (use-package-plist-maybe-put rest :defer t)) | ||
| 1037 | state) | ||
| 1038 | `((ignore ,@form))))) | 1080 | `((ignore ,@form))))) |
| 1039 | 1081 | ||
| 1040 | (defun use-package-handler/:bind-keymap* (name keyword arg rest state) | 1082 | (defun use-package-handler/:bind-keymap* (name keyword arg rest state) |
| @@ -1057,20 +1099,18 @@ representing symbols (that may need to be autloaded)." | |||
| 1057 | "Handle keywords which add regexp/mode pairs to an alist." | 1099 | "Handle keywords which add regexp/mode pairs to an alist." |
| 1058 | (cl-destructuring-bind (nargs . commands) | 1100 | (cl-destructuring-bind (nargs . commands) |
| 1059 | (use-package--normalize-commands args) | 1101 | (use-package--normalize-commands args) |
| 1060 | (let ((form | 1102 | (use-package-concat |
| 1061 | (mapcar | 1103 | (mapcar |
| 1062 | #'(lambda (thing) | 1104 | #'(lambda (thing) |
| 1063 | `(add-to-list | 1105 | `(add-to-list |
| 1064 | ',alist | 1106 | ',alist |
| 1065 | ',(cons (use-package-normalize-regex (car thing)) | 1107 | ',(cons (use-package-normalize-regex (car thing)) |
| 1066 | (cdr thing)))) | 1108 | (cdr thing)))) |
| 1067 | nargs))) | 1109 | nargs) |
| 1068 | (use-package-concat | 1110 | (use-package-process-keywords name |
| 1069 | (use-package-process-keywords name | 1111 | (use-package-sort-keywords |
| 1070 | (use-package-sort-keywords | 1112 | (use-package-plist-append rest :commands commands)) |
| 1071 | (use-package-plist-maybe-put rest :defer t)) | 1113 | state)))) |
| 1072 | (use-package-plist-append state :commands commands)) | ||
| 1073 | `((ignore ,@form)))))) | ||
| 1074 | 1114 | ||
| 1075 | (defalias 'use-package-normalize/:interpreter 'use-package-normalize-mode) | 1115 | (defalias 'use-package-normalize/:interpreter 'use-package-normalize-mode) |
| 1076 | 1116 | ||
| @@ -1109,37 +1149,74 @@ representing symbols (that may need to be autloaded)." | |||
| 1109 | 1149 | ||
| 1110 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 1150 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 1111 | ;; | 1151 | ;; |
| 1112 | ;;; :commands | 1152 | ;;; :hook |
| 1113 | ;; | ||
| 1114 | |||
| 1115 | (defalias 'use-package-normalize/:commands 'use-package-normalize-symlist) | ||
| 1116 | |||
| 1117 | (defun use-package-handler/:commands (name keyword arg rest state) | ||
| 1118 | ;; The actual processing for commands is done in :defer | ||
| 1119 | (use-package-process-keywords name | ||
| 1120 | (use-package-sort-keywords | ||
| 1121 | (use-package-plist-maybe-put rest :defer t)) | ||
| 1122 | (use-package-plist-append state :commands arg))) | ||
| 1123 | |||
| 1124 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
| 1125 | ;; | ||
| 1126 | ;;; :defines | ||
| 1127 | ;; | 1153 | ;; |
| 1128 | 1154 | ||
| 1129 | (defalias 'use-package-normalize/:defines 'use-package-normalize-symlist) | 1155 | (defun use-package-normalize/:hook (name keyword args) |
| 1156 | (use-package-as-one (symbol-name keyword) args | ||
| 1157 | #'(lambda (label arg) | ||
| 1158 | (unless (or (use-package--non-nil-symbolp arg) (consp arg)) | ||
| 1159 | (use-package-error | ||
| 1160 | (concat label " a <symbol> or (<symbol or list of symbols> . <symbol or function>)" | ||
| 1161 | " or list of these"))) | ||
| 1162 | (use-package-normalize-pairs | ||
| 1163 | #'(lambda (k) | ||
| 1164 | (or (use-package--non-nil-symbolp k) | ||
| 1165 | (and k (let ((every t)) | ||
| 1166 | (while (and every k) | ||
| 1167 | (if (and (consp k) | ||
| 1168 | (use-package--non-nil-symbolp (car k))) | ||
| 1169 | (setq k (cdr k)) | ||
| 1170 | (setq every nil))) | ||
| 1171 | every)))) | ||
| 1172 | #'use-package--recognize-function | ||
| 1173 | name label arg)))) | ||
| 1130 | 1174 | ||
| 1131 | (defun use-package-handler/:defines (name keyword arg rest state) | 1175 | (defun use-package-handler/:hook (name keyword args rest state) |
| 1132 | (use-package-process-keywords name rest state)) | 1176 | "Generate use-package custom keyword code." |
| 1177 | (cl-destructuring-bind (nargs . commands) | ||
| 1178 | (use-package--normalize-commands args) | ||
| 1179 | (use-package-concat | ||
| 1180 | (cl-mapcan | ||
| 1181 | #'(lambda (def) | ||
| 1182 | (let ((syms (car def)) | ||
| 1183 | (fun (cdr def))) | ||
| 1184 | (when fun | ||
| 1185 | (mapcar | ||
| 1186 | #'(lambda (sym) | ||
| 1187 | `(add-hook (quote ,(intern (format "%s-hook" sym))) | ||
| 1188 | (function ,fun))) | ||
| 1189 | (if (use-package--non-nil-symbolp syms) (list syms) syms))))) | ||
| 1190 | nargs) | ||
| 1191 | (use-package-process-keywords name | ||
| 1192 | (use-package-sort-keywords | ||
| 1193 | (use-package-plist-append rest :commands commands)) | ||
| 1194 | state)))) | ||
| 1133 | 1195 | ||
| 1134 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 1196 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 1135 | ;; | 1197 | ;; |
| 1136 | ;;; :functions | 1198 | ;;; :commands |
| 1137 | ;; | 1199 | ;; |
| 1138 | 1200 | ||
| 1139 | (defalias 'use-package-normalize/:functions 'use-package-normalize-symlist) | 1201 | (defalias 'use-package-normalize/:commands 'use-package-normalize-symlist) |
| 1140 | 1202 | ||
| 1141 | (defun use-package-handler/:functions (name keyword arg rest state) | 1203 | (defun use-package-handler/:commands (name keyword arg rest state) |
| 1142 | (use-package-process-keywords name rest state)) | 1204 | (use-package-concat |
| 1205 | (unless (plist-get state :demand) | ||
| 1206 | ;; Since we deferring load, establish any necessary autoloads, and also | ||
| 1207 | ;; keep the byte-compiler happy. | ||
| 1208 | (let ((name-string (use-package-as-string name))) | ||
| 1209 | (cl-mapcan | ||
| 1210 | #'(lambda (command) | ||
| 1211 | (when (symbolp command) | ||
| 1212 | (append | ||
| 1213 | `((unless (fboundp ',command) | ||
| 1214 | (autoload #',command ,name-string nil t))) | ||
| 1215 | (when (bound-and-true-p byte-compile-current-file) | ||
| 1216 | `((eval-when-compile | ||
| 1217 | (declare-function ,command ,name-string))))))) | ||
| 1218 | (delete-dups arg)))) | ||
| 1219 | (use-package-process-keywords name rest state))) | ||
| 1143 | 1220 | ||
| 1144 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 1221 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 1145 | ;; | 1222 | ;; |
| @@ -1149,77 +1226,89 @@ representing symbols (that may need to be autloaded)." | |||
| 1149 | (defalias 'use-package-normalize/:defer 'use-package-normalize-predicate) | 1226 | (defalias 'use-package-normalize/:defer 'use-package-normalize-predicate) |
| 1150 | 1227 | ||
| 1151 | (defun use-package-handler/:defer (name keyword arg rest state) | 1228 | (defun use-package-handler/:defer (name keyword arg rest state) |
| 1152 | (let ((body (use-package-process-keywords name rest | 1229 | (let ((body (use-package-process-keywords name rest state))) |
| 1153 | (plist-put state :deferred t))) | ||
| 1154 | (name-string (use-package-as-string name))) | ||
| 1155 | (use-package-concat | 1230 | (use-package-concat |
| 1156 | ;; Load the package after a set amount of idle time, if the argument to | 1231 | ;; Load the package after a set amount of idle time, if the argument to |
| 1157 | ;; `:defer' was a number. | 1232 | ;; `:defer' was a number. |
| 1158 | (when (numberp arg) | 1233 | (when (numberp arg) |
| 1159 | `((run-with-idle-timer ,arg nil #'require | 1234 | `((run-with-idle-timer ,arg nil #'require |
| 1160 | ',(use-package-as-symbol name) nil t))) | 1235 | ',(use-package-as-symbol name) nil t))) |
| 1161 | ;; Since we deferring load, establish any necessary autoloads, and also | 1236 | (if (or (not arg) (null body)) |
| 1162 | ;; keep the byte-compiler happy. | 1237 | body |
| 1163 | (cl-mapcan | 1238 | (list (use-package--require-after-load |
| 1164 | #'(lambda (command) | 1239 | name (macroexp-progn body))))))) |
| 1165 | (when (symbolp command) | ||
| 1166 | (append | ||
| 1167 | `((unless (fboundp ',command) | ||
| 1168 | (autoload #',command ,name-string nil t))) | ||
| 1169 | (when (bound-and-true-p byte-compile-current-file) | ||
| 1170 | `((eval-when-compile | ||
| 1171 | (declare-function ,command ,name-string))))))) | ||
| 1172 | (delete-dups (plist-get state :commands))) | ||
| 1173 | |||
| 1174 | body))) | ||
| 1175 | |||
| 1176 | 1240 | ||
| 1177 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 1241 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 1178 | ;; | 1242 | ;; |
| 1179 | ;;; :after | 1243 | ;;; :after |
| 1180 | ;; | 1244 | ;; |
| 1181 | 1245 | ||
| 1182 | (defalias 'use-package-normalize/:after 'use-package-normalize-recursive-symlist) | 1246 | (defun use-package-normalize/:after (name keyword args) |
| 1247 | (setq args (use-package-normalize-recursive-symlist name keyword args)) | ||
| 1248 | (if (consp args) | ||
| 1249 | args | ||
| 1250 | (list args))) | ||
| 1183 | 1251 | ||
| 1184 | (defun use-package-require-after-load (features) | 1252 | (defun use-package--after-count-uses (features) |
| 1185 | "Return form for after any of FEATURES require NAME." | 1253 | "Count the number of time the body would appear in the result." |
| 1186 | (pcase features | 1254 | (pcase features |
| 1187 | ((and (pred use-package--non-nil-symbolp) feat) | 1255 | ((and (pred use-package--non-nil-symbolp) feat) |
| 1188 | `(lambda (body) | 1256 | 1) |
| 1189 | (list 'eval-after-load (list 'quote ',feat) | 1257 | (`(,(or `:or `:any) . ,rest) |
| 1190 | (list 'quote body)))) | 1258 | (let ((num 0)) |
| 1191 | (`(,(or :or :any) . ,rest) | 1259 | (dolist (next rest) |
| 1192 | `(lambda (body) | 1260 | (setq num (+ num (use-package--after-count-uses next)))) |
| 1193 | (append (list 'progn) | 1261 | num)) |
| 1194 | (mapcar (lambda (form) | 1262 | (`(,(or `:and `:all) . ,rest) |
| 1195 | (funcall form body)) | 1263 | (apply #'max (mapcar #'use-package--after-count-uses rest))) |
| 1196 | (list ,@(use-package-require-after-load rest)))))) | ||
| 1197 | (`(,(or :and :all) . ,rest) | ||
| 1198 | `(lambda (body) | ||
| 1199 | (let ((result body)) | ||
| 1200 | (dolist (form (list ,@(use-package-require-after-load rest))) | ||
| 1201 | (setq result (funcall form result))) | ||
| 1202 | result))) | ||
| 1203 | (`(,feat . ,rest) | 1264 | (`(,feat . ,rest) |
| 1204 | (if rest | 1265 | (use-package--after-count-uses (cons :all (cons feat rest)))))) |
| 1205 | (cons (use-package-require-after-load feat) | 1266 | |
| 1206 | (use-package-require-after-load rest)) | 1267 | (defun use-package--require-after-load (features body) |
| 1207 | (list (use-package-require-after-load feat)))))) | 1268 | "Generate `eval-after-load' statements to represents FEATURES. |
| 1269 | FEATURES is a list containing keywords `:and' and `:all', where | ||
| 1270 | no keyword implies `:all'." | ||
| 1271 | (pcase features | ||
| 1272 | ((and (pred use-package--non-nil-symbolp) feat) | ||
| 1273 | `(eval-after-load ',feat | ||
| 1274 | ,(if (member (car body) '(quote backquote \' \`)) | ||
| 1275 | body | ||
| 1276 | (list 'quote body)))) | ||
| 1277 | (`(,(or `:or `:any) . ,rest) | ||
| 1278 | (macroexp-progn | ||
| 1279 | (mapcar #'(lambda (x) (use-package--require-after-load x body)) rest))) | ||
| 1280 | (`(,(or `:and `:all) . ,rest) | ||
| 1281 | (dolist (next rest) | ||
| 1282 | (setq body (use-package--require-after-load next body))) | ||
| 1283 | body) | ||
| 1284 | (`(,feat . ,rest) | ||
| 1285 | (use-package--require-after-load (cons :all (cons feat rest)) body)))) | ||
| 1286 | |||
| 1287 | (defun use-package--memoize (f arg) | ||
| 1288 | "Ensure the macro-expansion of F applied to ARG evaluates ARG | ||
| 1289 | no more than once." | ||
| 1290 | (let ((loaded (gensym "use-package--loaded")) | ||
| 1291 | (result (gensym "use-package--result")) | ||
| 1292 | (next (gensym "use-package--next"))) | ||
| 1293 | `((lexical-let (,loaded ,result) | ||
| 1294 | (lexical-let ((,next (lambda () | ||
| 1295 | (if ,loaded | ||
| 1296 | ,result | ||
| 1297 | (setq ,loaded t) | ||
| 1298 | (setq ,result ,arg))))) | ||
| 1299 | ,(funcall f ``(funcall ,,next))))))) | ||
| 1208 | 1300 | ||
| 1209 | (defun use-package-handler/:after (name keyword arg rest state) | 1301 | (defun use-package-handler/:after (name keyword arg rest state) |
| 1210 | (let ((body (use-package-process-keywords name rest | 1302 | (let ((body (use-package-process-keywords name rest state)) |
| 1211 | (plist-put state :deferred t))) | 1303 | (uses (use-package--after-count-uses arg))) |
| 1212 | (name-string (use-package-as-string name))) | 1304 | (if (or (null uses) (null body)) |
| 1213 | (if (and (consp arg) | 1305 | body |
| 1214 | (not (memq (car arg) '(:or :any :and :all)))) | 1306 | (if (<= uses 1) |
| 1215 | (setq arg (cons :all arg))) | 1307 | (list (use-package--require-after-load |
| 1216 | (use-package-concat | 1308 | arg (list 'quote (macroexp-progn body)))) |
| 1217 | (when arg | 1309 | (use-package--memoize |
| 1218 | (list (funcall | 1310 | (apply-partially #'use-package--require-after-load arg) |
| 1219 | (use-package-require-after-load arg) | 1311 | (macroexp-progn body)))))) |
| 1220 | (macroexp-progn | ||
| 1221 | (use-package--require name))))) | ||
| 1222 | body))) | ||
| 1223 | 1312 | ||
| 1224 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 1313 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 1225 | ;; | 1314 | ;; |
| @@ -1229,105 +1318,7 @@ representing symbols (that may need to be autloaded)." | |||
| 1229 | (defalias 'use-package-normalize/:demand 'use-package-normalize-predicate) | 1318 | (defalias 'use-package-normalize/:demand 'use-package-normalize-predicate) |
| 1230 | 1319 | ||
| 1231 | (defun use-package-handler/:demand (name keyword arg rest state) | 1320 | (defun use-package-handler/:demand (name keyword arg rest state) |
| 1232 | (use-package-process-keywords name rest | 1321 | (use-package-process-keywords name rest state)) |
| 1233 | (use-package-plist-delete state :deferred))) | ||
| 1234 | |||
| 1235 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
| 1236 | ;; | ||
| 1237 | ;;; :init | ||
| 1238 | ;; | ||
| 1239 | |||
| 1240 | (defalias 'use-package-normalize/:init 'use-package-normalize-forms) | ||
| 1241 | |||
| 1242 | (defun use-package-handler/:init (name keyword arg rest state) | ||
| 1243 | (let ((body (use-package-process-keywords name rest state))) | ||
| 1244 | (use-package-concat | ||
| 1245 | ;; The user's initializations | ||
| 1246 | (let ((init-body | ||
| 1247 | (use-package-hook-injector (use-package-as-string name) | ||
| 1248 | :init arg))) | ||
| 1249 | (if use-package-check-before-init | ||
| 1250 | `((if (locate-library ,(use-package-as-string name)) | ||
| 1251 | ,(macroexp-progn init-body))) | ||
| 1252 | init-body)) | ||
| 1253 | body))) | ||
| 1254 | |||
| 1255 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
| 1256 | ;; | ||
| 1257 | ;;; :config | ||
| 1258 | ;; | ||
| 1259 | |||
| 1260 | (defalias 'use-package-normalize/:config 'use-package-normalize-forms) | ||
| 1261 | |||
| 1262 | (defun use-package-handler/:config (name keyword arg rest state) | ||
| 1263 | (let* ((body (use-package-process-keywords name rest state)) | ||
| 1264 | (name-symbol (use-package-as-symbol name)) | ||
| 1265 | (config-body | ||
| 1266 | (if (equal arg '(t)) | ||
| 1267 | body | ||
| 1268 | (use-package--with-elapsed-timer | ||
| 1269 | (format "Configuring package %s" name-symbol) | ||
| 1270 | (use-package-concat | ||
| 1271 | (use-package-hook-injector (symbol-name name-symbol) | ||
| 1272 | :config arg) | ||
| 1273 | body | ||
| 1274 | (list t)))))) | ||
| 1275 | (if (plist-get state :deferred) | ||
| 1276 | (unless (or (null config-body) (equal config-body '(t))) | ||
| 1277 | `((eval-after-load ,(if (symbolp name) `',name name) | ||
| 1278 | ',(macroexp-progn config-body)))) | ||
| 1279 | (use-package--require name (plist-get state ':no-require) | ||
| 1280 | config-body)))) | ||
| 1281 | |||
| 1282 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
| 1283 | ;; | ||
| 1284 | ;;; :hook | ||
| 1285 | ;; | ||
| 1286 | |||
| 1287 | (defun use-package-normalize/:hook (name keyword args) | ||
| 1288 | (use-package-as-one (symbol-name keyword) args | ||
| 1289 | (lambda (label arg) | ||
| 1290 | (unless (or (use-package--non-nil-symbolp arg) (consp arg)) | ||
| 1291 | (use-package-error | ||
| 1292 | (concat label " a <symbol> or (<symbol or list of symbols> . <symbol or function>)" | ||
| 1293 | " or list of these"))) | ||
| 1294 | (use-package-normalize-pairs | ||
| 1295 | #'(lambda (k) | ||
| 1296 | (or (use-package--non-nil-symbolp k) | ||
| 1297 | (and k (let ((every t)) | ||
| 1298 | (while (and every k) | ||
| 1299 | (if (and (consp k) | ||
| 1300 | (use-package--non-nil-symbolp (car k))) | ||
| 1301 | (setq k (cdr k)) | ||
| 1302 | (setq every nil))) | ||
| 1303 | every)))) | ||
| 1304 | #'use-package--recognize-function | ||
| 1305 | name label arg)))) | ||
| 1306 | |||
| 1307 | (defun use-package-handler/:hook (name keyword args rest state) | ||
| 1308 | "Generate use-package custom keyword code." | ||
| 1309 | (cl-destructuring-bind (nargs . commands) | ||
| 1310 | (use-package--normalize-commands args) | ||
| 1311 | (use-package-concat | ||
| 1312 | (use-package-process-keywords name | ||
| 1313 | (if commands | ||
| 1314 | (use-package-sort-keywords | ||
| 1315 | (use-package-plist-maybe-put rest :defer t)) | ||
| 1316 | rest) | ||
| 1317 | (if commands | ||
| 1318 | (use-package-plist-append state :commands commands) | ||
| 1319 | state)) | ||
| 1320 | (cl-mapcan | ||
| 1321 | (lambda (def) | ||
| 1322 | (let ((syms (car def)) | ||
| 1323 | (fun (cdr def))) | ||
| 1324 | (when fun | ||
| 1325 | (mapcar | ||
| 1326 | #'(lambda (sym) | ||
| 1327 | `(add-hook (quote ,(intern (format "%s-hook" sym))) | ||
| 1328 | (function ,fun))) | ||
| 1329 | (if (use-package--non-nil-symbolp syms) (list syms) syms))))) | ||
| 1330 | nargs)))) | ||
| 1331 | 1322 | ||
| 1332 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 1323 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 1333 | ;; | 1324 | ;; |
| @@ -1337,28 +1328,27 @@ representing symbols (that may need to be autloaded)." | |||
| 1337 | (defun use-package-normalize/:custom (name keyword args) | 1328 | (defun use-package-normalize/:custom (name keyword args) |
| 1338 | "Normalize use-package custom keyword." | 1329 | "Normalize use-package custom keyword." |
| 1339 | (use-package-as-one (symbol-name keyword) args | 1330 | (use-package-as-one (symbol-name keyword) args |
| 1340 | (lambda (label arg) | 1331 | #'(lambda (label arg) |
| 1341 | (unless (listp arg) | 1332 | (unless (listp arg) |
| 1342 | (use-package-error | 1333 | (use-package-error |
| 1343 | (concat label " a (<symbol> <value> [comment])" | 1334 | (concat label " a (<symbol> <value> [comment])" |
| 1344 | " or list of these"))) | 1335 | " or list of these"))) |
| 1345 | (if (use-package--non-nil-symbolp (car arg)) | 1336 | (if (use-package--non-nil-symbolp (car arg)) |
| 1346 | (list arg) | 1337 | (list arg) |
| 1347 | arg)))) | 1338 | arg)))) |
| 1348 | 1339 | ||
| 1349 | (defun use-package-handler/:custom (name keyword args rest state) | 1340 | (defun use-package-handler/:custom (name keyword args rest state) |
| 1350 | "Generate use-package custom keyword code." | 1341 | "Generate use-package custom keyword code." |
| 1351 | (let ((body (use-package-process-keywords name rest state))) | 1342 | (use-package-concat |
| 1352 | (use-package-concat | 1343 | (mapcar #'(lambda (def) |
| 1353 | (mapcar (lambda (def) | ||
| 1354 | (let ((variable (nth 0 def)) | 1344 | (let ((variable (nth 0 def)) |
| 1355 | (value (nth 1 def)) | 1345 | (value (nth 1 def)) |
| 1356 | (comment (nth 2 def))) | 1346 | (comment (nth 2 def))) |
| 1357 | (unless (and comment (stringp comment)) | 1347 | (unless (and comment (stringp comment)) |
| 1358 | (setq comment (format "Customized with use-package %s" name))) | 1348 | (setq comment (format "Customized with use-package %s" name))) |
| 1359 | `(customize-set-variable (quote ,variable) ,value ,comment))) | 1349 | `(customize-set-variable (quote ,variable) ,value ,comment))) |
| 1360 | args) | 1350 | args) |
| 1361 | body))) | 1351 | (use-package-process-keywords name rest state))) |
| 1362 | 1352 | ||
| 1363 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 1353 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 1364 | ;; | 1354 | ;; |
| @@ -1382,12 +1372,66 @@ representing symbols (that may need to be autloaded)." | |||
| 1382 | 1372 | ||
| 1383 | (defun use-package-handler/:custom-face (name keyword args rest state) | 1373 | (defun use-package-handler/:custom-face (name keyword args rest state) |
| 1384 | "Generate use-package custom-face keyword code." | 1374 | "Generate use-package custom-face keyword code." |
| 1375 | (use-package-concat | ||
| 1376 | (mapcar #'(lambda (def) `(custom-set-faces (quote ,def))) args) | ||
| 1377 | (use-package-process-keywords name rest state))) | ||
| 1378 | |||
| 1379 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
| 1380 | ;; | ||
| 1381 | ;;; :init | ||
| 1382 | ;; | ||
| 1383 | |||
| 1384 | (defalias 'use-package-normalize/:init 'use-package-normalize-forms) | ||
| 1385 | |||
| 1386 | (defun use-package-handler/:init (name keyword arg rest state) | ||
| 1387 | (use-package-concat | ||
| 1388 | ;; The user's initializations | ||
| 1389 | (let ((init-body | ||
| 1390 | (use-package-hook-injector (use-package-as-string name) | ||
| 1391 | :init arg))) | ||
| 1392 | (if use-package-check-before-init | ||
| 1393 | `((if (locate-library ,(use-package-as-string name)) | ||
| 1394 | ,(macroexp-progn init-body))) | ||
| 1395 | init-body)) | ||
| 1396 | (use-package-process-keywords name rest state))) | ||
| 1397 | |||
| 1398 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
| 1399 | ;; | ||
| 1400 | ;;; :load | ||
| 1401 | ;; | ||
| 1402 | |||
| 1403 | (defun use-package-normalize/:load (name keyword args) | ||
| 1404 | (setq args (use-package-normalize-recursive-symlist name keyword args)) | ||
| 1405 | (if (consp args) | ||
| 1406 | args | ||
| 1407 | (list args))) | ||
| 1408 | |||
| 1409 | (defun use-package-handler/:load (name keyword arg rest state) | ||
| 1385 | (let ((body (use-package-process-keywords name rest state))) | 1410 | (let ((body (use-package-process-keywords name rest state))) |
| 1386 | (use-package-concat | 1411 | (dolist (pkg arg) |
| 1387 | (mapcar (lambda (def) | 1412 | (setq body (use-package--require pkg nil body))) |
| 1388 | `(custom-set-faces (quote ,def))) | 1413 | body)) |
| 1389 | args) | 1414 | |
| 1390 | body))) | 1415 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 1416 | ;; | ||
| 1417 | ;;; :config | ||
| 1418 | ;; | ||
| 1419 | |||
| 1420 | (defalias 'use-package-normalize/:config 'use-package-normalize-forms) | ||
| 1421 | |||
| 1422 | (defun use-package-handler/:config (name keyword arg rest state) | ||
| 1423 | (let* ((body (use-package-process-keywords name rest state)) | ||
| 1424 | (name-symbol (use-package-as-symbol name))) | ||
| 1425 | (if (or (null arg) | ||
| 1426 | (equal arg '(t))) | ||
| 1427 | body | ||
| 1428 | (use-package--with-elapsed-timer | ||
| 1429 | (format "Configuring package %s" name-symbol) | ||
| 1430 | (use-package-concat | ||
| 1431 | (use-package-hook-injector | ||
| 1432 | (symbol-name name-symbol) :config arg) | ||
| 1433 | body | ||
| 1434 | (list t)))))) | ||
| 1391 | 1435 | ||
| 1392 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 1436 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 1393 | ;; | 1437 | ;; |
| @@ -1487,6 +1531,119 @@ representing symbols (that may need to be autloaded)." | |||
| 1487 | ;;; The main macro | 1531 | ;;; The main macro |
| 1488 | ;; | 1532 | ;; |
| 1489 | 1533 | ||
| 1534 | (defun use-package-unalias-keywords (name args) | ||
| 1535 | (setq args (cl-nsubstitute :if :when args)) | ||
| 1536 | (let (temp) | ||
| 1537 | (while (setq temp (plist-get args :unless)) | ||
| 1538 | (setq args (use-package-plist-delete-first args :unless) | ||
| 1539 | args (append args `(:if (not ,temp)))))) | ||
| 1540 | args) | ||
| 1541 | |||
| 1542 | (defun use-package--merge-keys (key new old) | ||
| 1543 | (pcase key | ||
| 1544 | (`:if `(and ,new ,old)) | ||
| 1545 | (`:after `(:all ,new ,old)) | ||
| 1546 | (`:defer old) | ||
| 1547 | (_ (append new old)))) | ||
| 1548 | |||
| 1549 | (defun use-package-normalize-keywords (name args) | ||
| 1550 | (let* ((name-symbol (if (stringp name) (intern name) name)) | ||
| 1551 | (name-string (symbol-name name-symbol))) | ||
| 1552 | |||
| 1553 | ;; Reduce the set of keywords down to its most fundamental expression. | ||
| 1554 | (setq args (use-package-unalias-keywords name-symbol args)) | ||
| 1555 | |||
| 1556 | ;; Normalize keyword values, coalescing multiple occurrences. | ||
| 1557 | (setq args (use-package-normalize-plist name-symbol args nil | ||
| 1558 | #'use-package--merge-keys)) | ||
| 1559 | |||
| 1560 | ;; Add default values for keywords not specified, when applicable. | ||
| 1561 | (dolist (spec use-package-defaults) | ||
| 1562 | (when (pcase (nth 2 spec) | ||
| 1563 | ((and func (pred functionp)) (funcall func args)) | ||
| 1564 | (sexp (eval sexp))) | ||
| 1565 | (setq args (use-package-plist-maybe-put | ||
| 1566 | args (nth 0 spec) (eval (nth 1 spec)))))) | ||
| 1567 | |||
| 1568 | ;; If byte-compiling, pre-load the package so all its symbols are in | ||
| 1569 | ;; scope. This is done by prepending statements to the :preface. | ||
| 1570 | (when (bound-and-true-p byte-compile-current-file) | ||
| 1571 | (setq args | ||
| 1572 | (use-package-plist-append | ||
| 1573 | args :preface | ||
| 1574 | (use-package-concat | ||
| 1575 | (mapcar #'(lambda (var) `(defvar ,var)) | ||
| 1576 | (plist-get args :defines)) | ||
| 1577 | (mapcar #'(lambda (fn) `(declare-function ,fn ,name-string)) | ||
| 1578 | (plist-get args :functions)) | ||
| 1579 | `((eval-when-compile | ||
| 1580 | (with-demoted-errors | ||
| 1581 | ,(format "Cannot load %s: %%S" name-string) | ||
| 1582 | ,(when (eq use-package-verbose 'debug) | ||
| 1583 | `(message ,(format "Compiling package %s" name-string))) | ||
| 1584 | ,(unless (plist-get args :no-require) | ||
| 1585 | `(load ,name-string nil t))))))))) | ||
| 1586 | |||
| 1587 | ;; Certain keywords imply :defer, if :demand was not specified. | ||
| 1588 | (when (and (not (plist-member args :demand)) | ||
| 1589 | (not (plist-member args :defer)) | ||
| 1590 | (or (plist-member args :bind) | ||
| 1591 | (plist-member args :bind*) | ||
| 1592 | (plist-member args :bind-keymap) | ||
| 1593 | (plist-member args :bind-keymap*) | ||
| 1594 | (plist-member args :interpreter) | ||
| 1595 | (plist-member args :mode) | ||
| 1596 | (plist-member args :magic) | ||
| 1597 | (plist-member args :magic-fallback) | ||
| 1598 | (plist-member args :commands) | ||
| 1599 | (plist-member args :hook))) | ||
| 1600 | (setq args (append args '(:defer t)))) | ||
| 1601 | |||
| 1602 | (when (and (plist-member args :load) | ||
| 1603 | (plist-member args :no-require)) | ||
| 1604 | (setq args (use-package-plist-delete args :no-require))) | ||
| 1605 | |||
| 1606 | (when (and (not (plist-member args :load)) | ||
| 1607 | (not (plist-member args :defer)) | ||
| 1608 | (not (plist-member args :no-require))) | ||
| 1609 | (setq args (append args `(:load (,name))))) | ||
| 1610 | |||
| 1611 | ;; Sort the list of keywords based on the order of `use-package-keywords'. | ||
| 1612 | (use-package-sort-keywords args))) | ||
| 1613 | |||
| 1614 | (defun use-package--core (name args) | ||
| 1615 | (let ((orig-args (cl-copy-list args))) | ||
| 1616 | (setq args (use-package-normalize-keywords name args)) | ||
| 1617 | (let ((body (macroexp-progn | ||
| 1618 | (use-package-process-keywords name args | ||
| 1619 | (and (plist-get args :demand) | ||
| 1620 | (list :demand t)))))) | ||
| 1621 | (if (not (eq use-package-verbose 'debug)) | ||
| 1622 | body | ||
| 1623 | `(condition-case-unless-debug err | ||
| 1624 | ,body | ||
| 1625 | (error | ||
| 1626 | (let ((msg (format "%s: %s" ',name (error-message-string err)))) | ||
| 1627 | (with-current-buffer (get-buffer-create "*use-package*") | ||
| 1628 | (goto-char (point-max)) | ||
| 1629 | (insert "-----\n" msg "\n\n" | ||
| 1630 | (pp-to-string ',`(use-package ,name ,@orig-args)) | ||
| 1631 | "\n -->\n\n" | ||
| 1632 | (pp-to-string ',`(use-package ,name ,@args)) | ||
| 1633 | "\n ==>\n\n" | ||
| 1634 | (pp-to-string | ||
| 1635 | ',(let ((use-package-verbose 'errors) | ||
| 1636 | (use-package-expand-minimally t)) | ||
| 1637 | (macroexp-progn | ||
| 1638 | (use-package-process-keywords name args | ||
| 1639 | (and (plist-get args :demand) | ||
| 1640 | (list :demand t))))))) | ||
| 1641 | (emacs-lisp-mode)) | ||
| 1642 | (ignore | ||
| 1643 | (display-warning | ||
| 1644 | 'use-package (concat msg " (see the *use-package* buffer)") | ||
| 1645 | :error))))))))) | ||
| 1646 | |||
| 1490 | ;;;###autoload | 1647 | ;;;###autoload |
| 1491 | (defmacro use-package (name &rest args) | 1648 | (defmacro use-package (name &rest args) |
| 1492 | "Declare an Emacs package by specifying a group of configuration options. | 1649 | "Declare an Emacs package by specifying a group of configuration options. |
| @@ -1543,72 +1700,18 @@ this file. Usage: | |||
| 1543 | :ensure Loads the package using package.el if necessary. | 1700 | :ensure Loads the package using package.el if necessary. |
| 1544 | :pin Pin the package to an archive." | 1701 | :pin Pin the package to an archive." |
| 1545 | (declare (indent 1)) | 1702 | (declare (indent 1)) |
| 1546 | (unless (member :disabled args) | 1703 | (unless (memq :disabled args) |
| 1547 | (let ((name-symbol (if (stringp name) (intern name) name)) | 1704 | (if (eq use-package-verbose 'errors) |
| 1548 | (orig-args args) | 1705 | (use-package--core name args) |
| 1549 | (args (use-package-normalize-plist name args))) | 1706 | (condition-case-unless-debug err |
| 1550 | (dolist (spec use-package-defaults) | 1707 | (use-package--core name args) |
| 1551 | (setq args (if (eval (nth 2 spec)) | 1708 | (error |
| 1552 | (use-package-plist-maybe-put | 1709 | (ignore |
| 1553 | args (nth 0 spec) (eval (nth 1 spec))) | 1710 | (display-warning |
| 1554 | args))) | 1711 | 'use-package |
| 1555 | 1712 | (format "Failed to parse package %s %s: %s" | |
| 1556 | ;; When byte-compiling, pre-load the package so all its symbols are in | 1713 | name args (error-message-string err)) |
| 1557 | ;; scope. | 1714 | :error))))))) |
| 1558 | (if (bound-and-true-p byte-compile-current-file) | ||
| 1559 | (setq args | ||
| 1560 | (use-package-plist-append | ||
| 1561 | args :preface | ||
| 1562 | (use-package-concat | ||
| 1563 | (mapcar #'(lambda (var) `(defvar ,var)) | ||
| 1564 | (plist-get args :defines)) | ||
| 1565 | (mapcar #'(lambda (fn) `(declare-function | ||
| 1566 | ,fn ,(use-package-as-string name))) | ||
| 1567 | (plist-get args :functions)) | ||
| 1568 | `((eval-when-compile | ||
| 1569 | (with-demoted-errors | ||
| 1570 | ,(format "Cannot load %s: %%S" name) | ||
| 1571 | ,(if (eq use-package-verbose 'debug) | ||
| 1572 | `(message "Compiling package %s" ',name-symbol)) | ||
| 1573 | ,(unless (plist-get args :no-require) | ||
| 1574 | `(load ,(if (stringp name) | ||
| 1575 | name | ||
| 1576 | (symbol-name name)) nil t))))))))) | ||
| 1577 | |||
| 1578 | (let ((body | ||
| 1579 | `(progn | ||
| 1580 | ,@(use-package-process-keywords name | ||
| 1581 | (let ((args* | ||
| 1582 | (use-package-sort-keywords | ||
| 1583 | (if (and use-package-always-demand | ||
| 1584 | (not (memq :defer args))) | ||
| 1585 | (plist-put args :demand t) | ||
| 1586 | args)))) | ||
| 1587 | ;; The :demand keyword should not override :after | ||
| 1588 | (if (and (plist-member args* :after) | ||
| 1589 | (plist-member args* :demand)) | ||
| 1590 | (setq args* (use-package-plist-delete args* :demand))) | ||
| 1591 | (when (and use-package-always-ensure | ||
| 1592 | (plist-member args* :load-path) | ||
| 1593 | (not (plist-member orig-args :ensure))) | ||
| 1594 | (plist-put args* :ensure nil)) | ||
| 1595 | (unless (plist-member args* :init) | ||
| 1596 | (plist-put args* :init nil)) | ||
| 1597 | (unless (plist-member args* :config) | ||
| 1598 | (plist-put args* :config '(t))) | ||
| 1599 | args*) | ||
| 1600 | (and use-package-always-defer | ||
| 1601 | (list :deferred t)))))) | ||
| 1602 | (when use-package-debug | ||
| 1603 | (display-buffer | ||
| 1604 | (save-current-buffer | ||
| 1605 | (with-current-buffer (get-buffer-create "*use-package*") | ||
| 1606 | (goto-char (point-max)) | ||
| 1607 | (emacs-lisp-mode) | ||
| 1608 | (insert (pp-to-string body)) | ||
| 1609 | (current-buffer))))) | ||
| 1610 | body)))) | ||
| 1611 | |||
| 1612 | 1715 | ||
| 1613 | (put 'use-package 'lisp-indent-function 'defun) | 1716 | (put 'use-package 'lisp-indent-function 'defun) |
| 1614 | 1717 | ||
diff --git a/test/lisp/use-package/use-package-tests.el b/test/lisp/use-package/use-package-tests.el index 7bc2a486b79..5cf7a342b36 100644 --- a/test/lisp/use-package/use-package-tests.el +++ b/test/lisp/use-package/use-package-tests.el | |||
| @@ -26,23 +26,36 @@ | |||
| 26 | (require 'use-package) | 26 | (require 'use-package) |
| 27 | 27 | ||
| 28 | (setq use-package-always-ensure nil | 28 | (setq use-package-always-ensure nil |
| 29 | use-package-verbose nil | 29 | use-package-verbose 'errors |
| 30 | use-package-expand-minimally t | 30 | use-package-expand-minimally t |
| 31 | max-lisp-eval-depth 8000) | 31 | max-lisp-eval-depth 8000 |
| 32 | 32 | max-specpdl-size 8000) | |
| 33 | ;; (let ((byte-compile-current-file nil)) (expand-minimally ())) | ||
| 34 | (fset 'insert-expansion | ||
| 35 | [?\C-\M- ?\M-w ?\M-: ?\M-p ?\C-e ?\C-b ?\C-b ?\C-\M-b ?\C-y ?\C-\M-k return ?\C-\M- ?\M-w C-return ?\C-z ?\C-n ?\C-f ?\C-y ?\C-\M-k]) | ||
| 36 | 33 | ||
| 37 | (defmacro expand-minimally (form) | 34 | (defmacro expand-minimally (form) |
| 38 | `(let ((use-package-verbose nil) | 35 | `(let ((use-package-verbose 'errors) |
| 39 | (use-package-expand-minimally t)) | 36 | (use-package-expand-minimally t)) |
| 40 | (macroexpand ',form))) | 37 | (macroexpand-1 ',form))) |
| 41 | 38 | ||
| 42 | (defmacro match-expansion (form &rest value) | 39 | (defmacro match-expansion (form &rest value) |
| 43 | `(should (pcase (expand-minimally ,form) | 40 | `(should (pcase (expand-minimally ,form) |
| 44 | ,@(mapcar #'(lambda (x) (list x t)) value)))) | 41 | ,@(mapcar #'(lambda (x) (list x t)) value)))) |
| 45 | 42 | ||
| 43 | (defun fix-expansion () | ||
| 44 | (interactive) | ||
| 45 | (save-excursion | ||
| 46 | (unless (looking-at "(match-expansion") | ||
| 47 | (backward-up-list)) | ||
| 48 | (when (looking-at "(match-expansion") | ||
| 49 | (search-forward "(use-package") | ||
| 50 | (goto-char (match-beginning 0)) | ||
| 51 | (let ((decl (read (current-buffer)))) | ||
| 52 | (kill-sexp) | ||
| 53 | (let ((use-package-verbose 'errors) | ||
| 54 | (use-package-expand-minimally t)) | ||
| 55 | (insert ?\n ?\` (pp-to-string (macroexpand-1 decl)))))))) | ||
| 56 | |||
| 57 | (bind-key "C-c C-u" #'fix-expansion emacs-lisp-mode-map) | ||
| 58 | |||
| 46 | (eval-when-compile | 59 | (eval-when-compile |
| 47 | (defun plist-delete (plist property) | 60 | (defun plist-delete (plist property) |
| 48 | "Delete PROPERTY from PLIST" | 61 | "Delete PROPERTY from PLIST" |
| @@ -87,11 +100,6 @@ | |||
| 87 | (ert-deftest use-package-test/:disabled () | 100 | (ert-deftest use-package-test/:disabled () |
| 88 | (match-expansion | 101 | (match-expansion |
| 89 | (use-package foo :disabled t) | 102 | (use-package foo :disabled t) |
| 90 | `()) | ||
| 91 | |||
| 92 | (match-expansion | ||
| 93 | ;; jww (2017-11-30): Should :disabled ignore its argument? | ||
| 94 | (use-package foo :disabled nil) | ||
| 95 | `())) | 103 | `())) |
| 96 | 104 | ||
| 97 | (ert-deftest use-package-test/:preface () | 105 | (ert-deftest use-package-test/:preface () |
| @@ -176,8 +184,7 @@ | |||
| 176 | (ert-deftest use-package-test/:defer-install () | 184 | (ert-deftest use-package-test/:defer-install () |
| 177 | (match-expansion | 185 | (match-expansion |
| 178 | (use-package foo :defer-install t) | 186 | (use-package foo :defer-install t) |
| 179 | `(progn | 187 | `(require 'foo nil nil))) |
| 180 | (require 'foo nil nil)))) | ||
| 181 | 188 | ||
| 182 | (ert-deftest use-package-test-normalize/:ensure () | 189 | (ert-deftest use-package-test-normalize/:ensure () |
| 183 | (flet ((norm (&rest args) | 190 | (flet ((norm (&rest args) |
| @@ -230,7 +237,6 @@ | |||
| 230 | (match-expansion | 237 | (match-expansion |
| 231 | (use-package foo :load-path "foo") | 238 | (use-package foo :load-path "foo") |
| 232 | `(progn | 239 | `(progn |
| 233 | (use-package-ensure-elpa 'foo 'nil 'nil) | ||
| 234 | (eval-and-compile | 240 | (eval-and-compile |
| 235 | (add-to-list 'load-path ,(pred stringp))) | 241 | (add-to-list 'load-path ,(pred stringp))) |
| 236 | (require 'foo nil nil)))) | 242 | (require 'foo nil nil)))) |
| @@ -283,77 +289,82 @@ | |||
| 283 | (ert-deftest use-package-test/:if () | 289 | (ert-deftest use-package-test/:if () |
| 284 | (match-expansion | 290 | (match-expansion |
| 285 | (use-package foo :if t) | 291 | (use-package foo :if t) |
| 286 | `(progn | 292 | `(when t |
| 287 | (when (symbol-value 't) | 293 | (require 'foo nil nil))) |
| 288 | (require 'foo nil nil)))) | ||
| 289 | 294 | ||
| 290 | (match-expansion | 295 | (match-expansion |
| 291 | (use-package foo :if (and t t)) | 296 | (use-package foo :if (and t t)) |
| 292 | `(progn | 297 | `(when (and t t) |
| 293 | (when (and t t) | 298 | (require 'foo nil nil))) |
| 294 | (require 'foo nil nil)))) | ||
| 295 | 299 | ||
| 296 | (match-expansion | 300 | (match-expansion |
| 297 | (use-package foo :if nil) | 301 | (use-package foo :if nil) |
| 298 | `(progn | 302 | `(when nil |
| 299 | (when nil | 303 | (require 'foo nil nil)))) |
| 300 | (require 'foo nil nil))))) | ||
| 301 | 304 | ||
| 302 | (ert-deftest use-package-test/:when () | 305 | (ert-deftest use-package-test/:when () |
| 303 | (match-expansion | 306 | (match-expansion |
| 304 | (use-package foo :when t) | 307 | (use-package foo :when t) |
| 305 | `(progn | 308 | `(when t |
| 306 | (when (symbol-value 't) | 309 | (require 'foo nil nil))) |
| 307 | (require 'foo nil nil)))) | ||
| 308 | 310 | ||
| 309 | (match-expansion | 311 | (match-expansion |
| 310 | (use-package foo :when (and t t)) | 312 | (use-package foo :when (and t t)) |
| 311 | `(progn | 313 | `(when (and t t) |
| 312 | (when (and t t) | 314 | (require 'foo nil nil))) |
| 313 | (require 'foo nil nil)))) | ||
| 314 | 315 | ||
| 315 | (match-expansion | 316 | (match-expansion |
| 316 | (use-package foo :when nil) | 317 | (use-package foo :when nil) |
| 317 | `(progn | 318 | `(when nil |
| 318 | (when nil | 319 | (require 'foo nil nil)))) |
| 319 | (require 'foo nil nil))))) | ||
| 320 | 320 | ||
| 321 | (ert-deftest use-package-test/:unless () | 321 | (ert-deftest use-package-test/:unless () |
| 322 | (match-expansion | 322 | (match-expansion |
| 323 | (use-package foo :unless t) | 323 | (use-package foo :unless t) |
| 324 | `(progn | 324 | `(when (not t) |
| 325 | (unless (symbol-value 't) | 325 | (require 'foo nil nil))) |
| 326 | (require 'foo nil nil)))) | ||
| 327 | 326 | ||
| 328 | (match-expansion | 327 | (match-expansion |
| 329 | (use-package foo :unless (and t t)) | 328 | (use-package foo :unless (and t t)) |
| 330 | `(progn | 329 | `(when (not (and t t)) |
| 331 | (unless (and t t) | 330 | (require 'foo nil nil))) |
| 332 | (require 'foo nil nil)))) | ||
| 333 | 331 | ||
| 334 | (match-expansion | 332 | (match-expansion |
| 335 | (use-package foo :unless nil) | 333 | (use-package foo :unless nil) |
| 336 | `(progn | 334 | `(unless nil |
| 337 | (unless nil | 335 | (require 'foo nil nil)))) |
| 338 | (require 'foo nil nil))))) | ||
| 339 | 336 | ||
| 340 | (ert-deftest use-package-test/:requires () | 337 | (ert-deftest use-package-test/:requires () |
| 341 | (match-expansion | 338 | (match-expansion |
| 342 | (use-package foo :requires bar) | 339 | (use-package foo :requires bar) |
| 343 | `(progn | 340 | `(when (featurep 'bar) |
| 344 | (when (not (member nil (mapcar #'featurep '(bar)))) | 341 | (require 'foo nil nil))) |
| 342 | |||
| 343 | (let ((byte-compile-current-file t)) | ||
| 344 | (match-expansion | ||
| 345 | (use-package foo :requires bar) | ||
| 346 | `(when (featurep 'bar) | ||
| 347 | (eval-and-compile | ||
| 348 | (eval-when-compile | ||
| 349 | (with-demoted-errors | ||
| 350 | "Cannot load foo: %S" nil | ||
| 351 | (load "foo" nil t)))) | ||
| 345 | (require 'foo nil nil)))) | 352 | (require 'foo nil nil)))) |
| 346 | 353 | ||
| 354 | (match-expansion | ||
| 355 | (use-package foo :requires (bar quux)) | ||
| 356 | `(when (not (member nil (mapcar #'featurep '(bar quux)))) | ||
| 357 | (require 'foo nil nil))) | ||
| 358 | |||
| 347 | (let ((byte-compile-current-file t)) | 359 | (let ((byte-compile-current-file t)) |
| 348 | (match-expansion | 360 | (match-expansion |
| 349 | (use-package foo :requires bar) | 361 | (use-package foo :requires bar) |
| 350 | `(progn | 362 | `(when (featurep 'bar) |
| 351 | (when (not (member nil (mapcar #'featurep '(bar)))) | 363 | (eval-and-compile |
| 352 | (eval-and-compile | 364 | (eval-when-compile |
| 353 | (eval-when-compile | 365 | (with-demoted-errors "Cannot load foo: %S" nil |
| 354 | (with-demoted-errors "Cannot load foo: %S" nil | 366 | (load "foo" nil t)))) |
| 355 | (load "foo" nil t)))) | 367 | (require 'foo nil nil))))) |
| 356 | (require 'foo nil nil)))))) | ||
| 357 | 368 | ||
| 358 | (ert-deftest use-package-test/:load-path () | 369 | (ert-deftest use-package-test/:load-path () |
| 359 | (match-expansion | 370 | (match-expansion |
| @@ -420,7 +431,7 @@ | |||
| 420 | (ert-deftest use-package-test/:no-require () | 431 | (ert-deftest use-package-test/:no-require () |
| 421 | (match-expansion | 432 | (match-expansion |
| 422 | (use-package foo :no-require t) | 433 | (use-package foo :no-require t) |
| 423 | `(progn)) | 434 | `nil) |
| 424 | 435 | ||
| 425 | (match-expansion | 436 | (match-expansion |
| 426 | (use-package foo :no-require t :config (config)) | 437 | (use-package foo :no-require t :config (config)) |
| @@ -431,10 +442,9 @@ | |||
| 431 | (let ((byte-compile-current-file t)) | 442 | (let ((byte-compile-current-file t)) |
| 432 | (match-expansion | 443 | (match-expansion |
| 433 | (use-package foo :no-require t) | 444 | (use-package foo :no-require t) |
| 434 | `(progn | 445 | `(eval-and-compile |
| 435 | (eval-and-compile | 446 | (eval-when-compile |
| 436 | (eval-when-compile | 447 | (with-demoted-errors "Cannot load foo: %S" nil nil)))))) |
| 437 | (with-demoted-errors "Cannot load foo: %S" nil nil))))))) | ||
| 438 | 448 | ||
| 439 | (ert-deftest use-package-test-normalize/:bind () | 449 | (ert-deftest use-package-test-normalize/:bind () |
| 440 | (flet ((norm (&rest args) | 450 | (flet ((norm (&rest args) |
| @@ -469,41 +479,35 @@ | |||
| 469 | (ert-deftest use-package-test/:bind-keymap () | 479 | (ert-deftest use-package-test/:bind-keymap () |
| 470 | (match-expansion | 480 | (match-expansion |
| 471 | (use-package foo :bind-keymap ("C-k" . key)) | 481 | (use-package foo :bind-keymap ("C-k" . key)) |
| 472 | `(progn | 482 | `(ignore |
| 473 | (ignore | 483 | (bind-key "C-k" |
| 474 | (bind-key "C-k" | 484 | #'(lambda nil |
| 475 | #'(lambda () | 485 | (interactive) |
| 476 | (interactive) | 486 | (use-package-autoload-keymap 'key 'foo nil)))))) |
| 477 | (use-package-autoload-keymap 'key 'foo nil))))))) | ||
| 478 | 487 | ||
| 479 | (ert-deftest use-package-test/:bind-keymap* () | 488 | (ert-deftest use-package-test/:bind-keymap* () |
| 480 | (match-expansion | 489 | (match-expansion |
| 481 | (use-package foo :bind-keymap* ("C-k" . key)) | 490 | (use-package foo :bind-keymap* ("C-k" . key)) |
| 482 | `(progn | 491 | `(ignore |
| 483 | (ignore | 492 | (bind-key* "C-k" |
| 484 | (bind-key* "C-k" | 493 | #'(lambda () |
| 485 | #'(lambda () | 494 | (interactive) |
| 486 | (interactive) | 495 | (use-package-autoload-keymap 'key 'foo t)))))) |
| 487 | (use-package-autoload-keymap 'key 'foo t))))))) | ||
| 488 | 496 | ||
| 489 | (ert-deftest use-package-test/:interpreter () | 497 | (ert-deftest use-package-test/:interpreter () |
| 490 | (match-expansion | 498 | (match-expansion |
| 491 | (use-package foo :interpreter "interp") | 499 | (use-package foo :interpreter "interp") |
| 492 | `(progn | 500 | `(progn |
| 501 | (add-to-list 'interpreter-mode-alist '("interp" . foo)) | ||
| 493 | (unless (fboundp 'foo) | 502 | (unless (fboundp 'foo) |
| 494 | (autoload #'foo "foo" nil t)) | 503 | (autoload #'foo "foo" nil t)))) |
| 495 | (ignore | ||
| 496 | (add-to-list 'interpreter-mode-alist | ||
| 497 | '("interp" . foo))))) | ||
| 498 | 504 | ||
| 499 | (match-expansion | 505 | (match-expansion |
| 500 | (use-package foo :interpreter ("interp" . fun)) | 506 | (use-package foo :interpreter ("interp" . fun)) |
| 501 | `(progn | 507 | `(progn |
| 508 | (add-to-list 'interpreter-mode-alist '("interp" . fun)) | ||
| 502 | (unless (fboundp 'fun) | 509 | (unless (fboundp 'fun) |
| 503 | (autoload #'fun "foo" nil t)) | 510 | (autoload #'fun "foo" nil t))))) |
| 504 | (ignore | ||
| 505 | (add-to-list 'interpreter-mode-alist | ||
| 506 | '("interp" . fun)))))) | ||
| 507 | 511 | ||
| 508 | (ert-deftest use-package-test-normalize/:mode () | 512 | (ert-deftest use-package-test-normalize/:mode () |
| 509 | (flet ((norm (&rest args) | 513 | (flet ((norm (&rest args) |
| @@ -524,65 +528,52 @@ | |||
| 524 | (match-expansion | 528 | (match-expansion |
| 525 | (use-package foo :mode "interp") | 529 | (use-package foo :mode "interp") |
| 526 | `(progn | 530 | `(progn |
| 531 | (add-to-list 'auto-mode-alist '("interp" . foo)) | ||
| 527 | (unless (fboundp 'foo) | 532 | (unless (fboundp 'foo) |
| 528 | (autoload #'foo "foo" nil t)) | 533 | (autoload #'foo "foo" nil t)))) |
| 529 | (ignore | ||
| 530 | (add-to-list 'auto-mode-alist | ||
| 531 | '("interp" . foo))))) | ||
| 532 | 534 | ||
| 533 | (match-expansion | 535 | (match-expansion |
| 534 | (use-package foo :mode ("interp" . fun)) | 536 | (use-package foo :mode ("interp" . fun)) |
| 535 | `(progn | 537 | `(progn |
| 538 | (add-to-list 'auto-mode-alist '("interp" . fun)) | ||
| 536 | (unless (fboundp 'fun) | 539 | (unless (fboundp 'fun) |
| 537 | (autoload #'fun "foo" nil t)) | 540 | (autoload #'fun "foo" nil t))))) |
| 538 | (ignore | ||
| 539 | (add-to-list 'auto-mode-alist | ||
| 540 | '("interp" . fun)))))) | ||
| 541 | 541 | ||
| 542 | (ert-deftest use-package-test/:magic () | 542 | (ert-deftest use-package-test/:magic () |
| 543 | (match-expansion | 543 | (match-expansion |
| 544 | (use-package foo :magic "interp") | 544 | (use-package foo :magic "interp") |
| 545 | `(progn | 545 | `(progn |
| 546 | (add-to-list 'magic-mode-alist '("interp" . foo)) | ||
| 546 | (unless (fboundp 'foo) | 547 | (unless (fboundp 'foo) |
| 547 | (autoload #'foo "foo" nil t)) | 548 | (autoload #'foo "foo" nil t)))) |
| 548 | (ignore | ||
| 549 | (add-to-list 'magic-mode-alist | ||
| 550 | '("interp" . foo))))) | ||
| 551 | 549 | ||
| 552 | (match-expansion | 550 | (match-expansion |
| 553 | (use-package foo :magic ("interp" . fun)) | 551 | (use-package foo :magic ("interp" . fun)) |
| 554 | `(progn | 552 | `(progn |
| 553 | (add-to-list 'magic-mode-alist '("interp" . fun)) | ||
| 555 | (unless (fboundp 'fun) | 554 | (unless (fboundp 'fun) |
| 556 | (autoload #'fun "foo" nil t)) | 555 | (autoload #'fun "foo" nil t))))) |
| 557 | (ignore | ||
| 558 | (add-to-list 'magic-mode-alist | ||
| 559 | '("interp" . fun)))))) | ||
| 560 | 556 | ||
| 561 | (ert-deftest use-package-test/:magic-fallback () | 557 | (ert-deftest use-package-test/:magic-fallback () |
| 562 | (match-expansion | 558 | (match-expansion |
| 563 | (use-package foo :magic-fallback "interp") | 559 | (use-package foo :magic-fallback "interp") |
| 564 | `(progn | 560 | `(progn |
| 561 | (add-to-list 'magic-fallback-mode-alist '("interp" . foo)) | ||
| 565 | (unless (fboundp 'foo) | 562 | (unless (fboundp 'foo) |
| 566 | (autoload #'foo "foo" nil t)) | 563 | (autoload #'foo "foo" nil t)))) |
| 567 | (ignore | ||
| 568 | (add-to-list 'magic-fallback-mode-alist | ||
| 569 | '("interp" . foo))))) | ||
| 570 | 564 | ||
| 571 | (match-expansion | 565 | (match-expansion |
| 572 | (use-package foo :magic-fallback ("interp" . fun)) | 566 | (use-package foo :magic-fallback ("interp" . fun)) |
| 573 | `(progn | 567 | `(progn |
| 568 | (add-to-list 'magic-fallback-mode-alist '("interp" . fun)) | ||
| 574 | (unless (fboundp 'fun) | 569 | (unless (fboundp 'fun) |
| 575 | (autoload #'fun "foo" nil t)) | 570 | (autoload #'fun "foo" nil t))))) |
| 576 | (ignore | ||
| 577 | (add-to-list 'magic-fallback-mode-alist | ||
| 578 | '("interp" . fun)))))) | ||
| 579 | 571 | ||
| 580 | (ert-deftest use-package-test/:commands () | 572 | (ert-deftest use-package-test/:commands () |
| 581 | (match-expansion | 573 | (match-expansion |
| 582 | (use-package foo :commands bar) | 574 | (use-package foo :commands bar) |
| 583 | `(progn | 575 | `(unless (fboundp 'bar) |
| 584 | (unless (fboundp 'bar) | 576 | (autoload #'bar "foo" nil t))) |
| 585 | (autoload #'bar "foo" nil t)))) | ||
| 586 | 577 | ||
| 587 | (match-expansion | 578 | (match-expansion |
| 588 | (use-package foo :commands (bar quux)) | 579 | (use-package foo :commands (bar quux)) |
| @@ -612,8 +603,7 @@ | |||
| 612 | (ert-deftest use-package-test/:defines () | 603 | (ert-deftest use-package-test/:defines () |
| 613 | (match-expansion | 604 | (match-expansion |
| 614 | (use-package foo :defines bar) | 605 | (use-package foo :defines bar) |
| 615 | `(progn | 606 | `(require 'foo nil nil)) |
| 616 | (require 'foo nil nil))) | ||
| 617 | 607 | ||
| 618 | (let ((byte-compile-current-file t)) | 608 | (let ((byte-compile-current-file t)) |
| 619 | (match-expansion | 609 | (match-expansion |
| @@ -630,8 +620,7 @@ | |||
| 630 | (ert-deftest use-package-test/:functions () | 620 | (ert-deftest use-package-test/:functions () |
| 631 | (match-expansion | 621 | (match-expansion |
| 632 | (use-package foo :functions bar) | 622 | (use-package foo :functions bar) |
| 633 | `(progn | 623 | `(require 'foo nil nil)) |
| 634 | (require 'foo nil nil))) | ||
| 635 | 624 | ||
| 636 | (let ((byte-compile-current-file t)) | 625 | (let ((byte-compile-current-file t)) |
| 637 | (match-expansion | 626 | (match-expansion |
| @@ -647,17 +636,16 @@ | |||
| 647 | 636 | ||
| 648 | (match-expansion | 637 | (match-expansion |
| 649 | (use-package foo :defer t :functions bar) | 638 | (use-package foo :defer t :functions bar) |
| 650 | `(progn)) | 639 | `nil) |
| 651 | 640 | ||
| 652 | (let ((byte-compile-current-file t)) | 641 | (let ((byte-compile-current-file t)) |
| 653 | (match-expansion | 642 | (match-expansion |
| 654 | (use-package foo :defer t :functions bar) | 643 | (use-package foo :defer t :functions bar) |
| 655 | `(progn | 644 | `(eval-and-compile |
| 656 | (eval-and-compile | 645 | (declare-function bar "foo") |
| 657 | (declare-function bar "foo") | 646 | (eval-when-compile |
| 658 | (eval-when-compile | 647 | (with-demoted-errors "Cannot load foo: %S" nil |
| 659 | (with-demoted-errors "Cannot load foo: %S" nil | 648 | (load "foo" nil t)))))) |
| 660 | (load "foo" nil t))))))) | ||
| 661 | 649 | ||
| 662 | (let ((byte-compile-current-file t)) | 650 | (let ((byte-compile-current-file t)) |
| 663 | (match-expansion | 651 | (match-expansion |
| @@ -677,8 +665,7 @@ | |||
| 677 | (ert-deftest use-package-test/:defer () | 665 | (ert-deftest use-package-test/:defer () |
| 678 | (match-expansion | 666 | (match-expansion |
| 679 | (use-package foo) | 667 | (use-package foo) |
| 680 | `(progn | 668 | `(require 'foo nil nil)) |
| 681 | (require 'foo nil nil))) | ||
| 682 | 669 | ||
| 683 | (let ((byte-compile-current-file t)) | 670 | (let ((byte-compile-current-file t)) |
| 684 | (match-expansion | 671 | (match-expansion |
| @@ -692,16 +679,15 @@ | |||
| 692 | 679 | ||
| 693 | (match-expansion | 680 | (match-expansion |
| 694 | (use-package foo :defer t) | 681 | (use-package foo :defer t) |
| 695 | `(progn)) | 682 | `nil) |
| 696 | 683 | ||
| 697 | (let ((byte-compile-current-file t)) | 684 | (let ((byte-compile-current-file t)) |
| 698 | (match-expansion | 685 | (match-expansion |
| 699 | (use-package foo :defer t) | 686 | (use-package foo :defer t) |
| 700 | `(progn | 687 | `(eval-and-compile |
| 701 | (eval-and-compile | 688 | (eval-when-compile |
| 702 | (eval-when-compile | 689 | (with-demoted-errors "Cannot load foo: %S" nil |
| 703 | (with-demoted-errors "Cannot load foo: %S" nil | 690 | (load "foo" nil t))))))) |
| 704 | (load "foo" nil t)))))))) | ||
| 705 | 691 | ||
| 706 | (ert-deftest use-package-test-normalize/:hook () | 692 | (ert-deftest use-package-test-normalize/:hook () |
| 707 | (flet ((norm (&rest args) | 693 | (flet ((norm (&rest args) |
| @@ -726,7 +712,7 @@ | |||
| 726 | (ert-deftest use-package-test/:hook () | 712 | (ert-deftest use-package-test/:hook () |
| 727 | (let ((byte-compile-current-file t)) | 713 | (let ((byte-compile-current-file t)) |
| 728 | (should | 714 | (should |
| 729 | (equal ; pcase crashes | 715 | (equal |
| 730 | (expand-minimally | 716 | (expand-minimally |
| 731 | (use-package foo | 717 | (use-package foo |
| 732 | :bind (("C-a" . key)) | 718 | :bind (("C-a" . key)) |
| @@ -734,8 +720,10 @@ | |||
| 734 | '(progn | 720 | '(progn |
| 735 | (eval-and-compile | 721 | (eval-and-compile |
| 736 | (eval-when-compile | 722 | (eval-when-compile |
| 737 | (with-demoted-errors "Cannot load foo: %S" nil | 723 | (with-demoted-errors |
| 738 | (load "foo" nil t)))) | 724 | "Cannot load foo: %S" nil |
| 725 | (load "foo" nil t)))) | ||
| 726 | (add-hook 'hook-hook #'fun) | ||
| 739 | (unless (fboundp 'fun) | 727 | (unless (fboundp 'fun) |
| 740 | (autoload #'fun "foo" nil t)) | 728 | (autoload #'fun "foo" nil t)) |
| 741 | (eval-when-compile | 729 | (eval-when-compile |
| @@ -744,7 +732,6 @@ | |||
| 744 | (autoload #'key "foo" nil t)) | 732 | (autoload #'key "foo" nil t)) |
| 745 | (eval-when-compile | 733 | (eval-when-compile |
| 746 | (declare-function key "foo")) | 734 | (declare-function key "foo")) |
| 747 | (add-hook 'hook-hook #'fun) | ||
| 748 | (ignore | 735 | (ignore |
| 749 | (bind-keys :package foo ("C-a" . key)))))))) | 736 | (bind-keys :package foo ("C-a" . key)))))))) |
| 750 | 737 | ||
| @@ -796,9 +783,8 @@ | |||
| 796 | (ert-deftest use-package-test/:after () | 783 | (ert-deftest use-package-test/:after () |
| 797 | (match-expansion | 784 | (match-expansion |
| 798 | (use-package foo :after bar) | 785 | (use-package foo :after bar) |
| 799 | `(progn | 786 | `(eval-after-load 'bar |
| 800 | (eval-after-load 'bar | 787 | '(require 'foo nil nil))) |
| 801 | '(require 'foo nil nil)))) | ||
| 802 | 788 | ||
| 803 | (let ((byte-compile-current-file t)) | 789 | (let ((byte-compile-current-file t)) |
| 804 | (match-expansion | 790 | (match-expansion |
| @@ -813,93 +799,96 @@ | |||
| 813 | 799 | ||
| 814 | (match-expansion | 800 | (match-expansion |
| 815 | (use-package foo :after (bar quux)) | 801 | (use-package foo :after (bar quux)) |
| 816 | `(progn | 802 | `(eval-after-load 'quux |
| 817 | (eval-after-load 'quux | 803 | '(eval-after-load 'bar |
| 818 | '(eval-after-load 'bar | 804 | '(require 'foo nil nil)))) |
| 819 | '(require 'foo nil nil))))) | ||
| 820 | 805 | ||
| 821 | (match-expansion | 806 | (match-expansion |
| 822 | (use-package foo :after (:all bar quux)) | 807 | (use-package foo :after (:all bar quux)) |
| 823 | `(progn | 808 | `(eval-after-load 'quux |
| 824 | (eval-after-load 'quux | 809 | '(eval-after-load 'bar |
| 825 | '(eval-after-load 'bar | 810 | '(require 'foo nil nil)))) |
| 826 | '(require 'foo nil nil))))) | ||
| 827 | 811 | ||
| 828 | (match-expansion | 812 | (match-expansion |
| 829 | (use-package foo :after (:any bar quux)) | 813 | (use-package foo :after (:any bar quux)) |
| 830 | `(progn | 814 | `(lexical-let ,_ |
| 831 | (progn | 815 | (lexical-let ,_ |
| 832 | (eval-after-load 'bar | 816 | (progn |
| 833 | '(require 'foo nil nil)) | 817 | (eval-after-load 'bar |
| 834 | (eval-after-load 'quux | 818 | `(funcall ,_)) |
| 835 | '(require 'foo nil nil))))) | 819 | (eval-after-load 'quux |
| 820 | `(funcall ,_)))))) | ||
| 836 | 821 | ||
| 837 | (match-expansion | 822 | (match-expansion |
| 838 | (use-package foo :after (:all (:any bar quux) bow)) | 823 | (use-package foo :after (:all (:any bar quux) bow)) |
| 839 | `(progn | 824 | `(lexical-let ,_ |
| 840 | (eval-after-load 'bow | 825 | (lexical-let ,_ |
| 841 | '(progn | 826 | (eval-after-load 'bow |
| 842 | (eval-after-load 'bar | 827 | '(progn |
| 843 | '(require 'foo nil nil)) | 828 | (eval-after-load 'bar |
| 844 | (eval-after-load 'quux | 829 | `(funcall ,_)) |
| 845 | '(require 'foo nil nil)))))) | 830 | (eval-after-load 'quux |
| 831 | `(funcall ,_))))))) | ||
| 846 | 832 | ||
| 847 | (match-expansion | 833 | (match-expansion |
| 848 | (use-package foo :after (:any (:all bar quux) bow)) | 834 | (use-package foo :after (:any (:all bar quux) bow)) |
| 849 | `(progn | 835 | `(lexical-let ,_ |
| 850 | (progn | 836 | (lexical-let ,_ |
| 851 | (eval-after-load 'quux | 837 | (progn |
| 852 | '(eval-after-load 'bar | 838 | (eval-after-load 'quux |
| 853 | '(require 'foo nil nil))) | 839 | '(eval-after-load 'bar |
| 854 | (eval-after-load 'bow | 840 | `(funcall ,_))) |
| 855 | '(require 'foo nil nil))))) | 841 | (eval-after-load 'bow |
| 842 | `(funcall ,_)))))) | ||
| 856 | 843 | ||
| 857 | (match-expansion | 844 | (match-expansion |
| 858 | (use-package foo :after (:all (:any bar quux) (:any bow baz))) | 845 | (use-package foo :after (:all (:any bar quux) (:any bow baz))) |
| 859 | `(progn | 846 | `(lexical-let ,_ |
| 860 | (progn | 847 | (lexical-let ,_ |
| 861 | (eval-after-load 'bow | 848 | (progn |
| 862 | '(progn | 849 | (eval-after-load 'bow |
| 863 | (eval-after-load 'bar | 850 | '(progn |
| 864 | '(require 'foo nil nil)) | 851 | (eval-after-load 'bar |
| 865 | (eval-after-load 'quux | 852 | `(funcall ,_)) |
| 866 | '(require 'foo nil nil)))) | 853 | (eval-after-load 'quux |
| 867 | (eval-after-load 'baz | 854 | `(funcall ,_)))) |
| 868 | '(progn | 855 | (eval-after-load 'baz |
| 869 | (eval-after-load 'bar | 856 | '(progn |
| 870 | '(require 'foo nil nil)) | 857 | (eval-after-load 'bar |
| 871 | (eval-after-load 'quux | 858 | `(funcall ,_)) |
| 872 | '(require 'foo nil nil))))))) | 859 | (eval-after-load 'quux |
| 860 | `(funcall ,_)))))))) | ||
| 873 | 861 | ||
| 874 | (match-expansion | 862 | (match-expansion |
| 875 | (use-package foo :after (:any (:all bar quux) (:all bow baz))) | 863 | (use-package foo :after (:any (:all bar quux) (:all bow baz))) |
| 876 | `(progn | 864 | `(lexical-let ,_ |
| 877 | (progn | 865 | (lexical-let ,_ |
| 878 | (eval-after-load 'quux | 866 | (progn |
| 879 | '(eval-after-load 'bar | 867 | (eval-after-load 'quux |
| 880 | '(require 'foo nil nil))) | 868 | '(eval-after-load 'bar |
| 881 | (eval-after-load 'baz | 869 | `(funcall ,_))) |
| 882 | '(eval-after-load 'bow | 870 | (eval-after-load 'baz |
| 883 | '(require 'foo nil nil)))))) | 871 | '(eval-after-load 'bow |
| 872 | `(funcall ,_))))))) | ||
| 884 | 873 | ||
| 885 | (match-expansion | 874 | (match-expansion |
| 886 | (use-package foo :after (:any (:all bar quux) (:any bow baz))) | 875 | (use-package foo :after (:any (:all bar quux) (:any bow baz))) |
| 887 | `(progn | 876 | `(lexical-let ,_ |
| 888 | (progn | 877 | (lexical-let ,_ |
| 889 | (eval-after-load 'quux | ||
| 890 | '(eval-after-load 'bar | ||
| 891 | '(require 'foo nil nil))) | ||
| 892 | (progn | 878 | (progn |
| 893 | (eval-after-load 'bow | 879 | (eval-after-load 'quux |
| 894 | '(require 'foo nil nil)) | 880 | '(eval-after-load 'bar |
| 895 | (eval-after-load 'baz | 881 | `(funcall ,_))) |
| 896 | '(require 'foo nil nil))))))) | 882 | (progn |
| 883 | (eval-after-load 'bow | ||
| 884 | `(funcall ,use-package--next142993)) | ||
| 885 | (eval-after-load 'baz | ||
| 886 | `(funcall ,_)))))))) | ||
| 897 | 887 | ||
| 898 | (ert-deftest use-package-test/:demand () | 888 | (ert-deftest use-package-test/:demand () |
| 899 | (match-expansion | 889 | (match-expansion |
| 900 | (use-package foo :demand t) | 890 | (use-package foo :demand t) |
| 901 | `(progn | 891 | `(require 'foo nil nil)) |
| 902 | (require 'foo nil nil))) | ||
| 903 | 892 | ||
| 904 | (let ((byte-compile-current-file t)) | 893 | (let ((byte-compile-current-file t)) |
| 905 | (match-expansion | 894 | (match-expansion |
| @@ -933,9 +922,8 @@ | |||
| 933 | ;; #529 - :demand should not override an explicit use of :after | 922 | ;; #529 - :demand should not override an explicit use of :after |
| 934 | (match-expansion | 923 | (match-expansion |
| 935 | (use-package foo :demand t :after bar) | 924 | (use-package foo :demand t :after bar) |
| 936 | `(progn | 925 | `(eval-after-load 'bar |
| 937 | (eval-after-load 'bar | 926 | '(require 'foo nil nil))) |
| 938 | '(require 'foo nil nil)))) | ||
| 939 | 927 | ||
| 940 | (let ((byte-compile-current-file t)) | 928 | (let ((byte-compile-current-file t)) |
| 941 | (match-expansion | 929 | (match-expansion |
| @@ -946,7 +934,40 @@ | |||
| 946 | (with-demoted-errors "Cannot load foo: %S" nil | 934 | (with-demoted-errors "Cannot load foo: %S" nil |
| 947 | (load "foo" nil t)))) | 935 | (load "foo" nil t)))) |
| 948 | (eval-after-load 'bar | 936 | (eval-after-load 'bar |
| 949 | '(require 'foo nil nil)))))) | 937 | '(require 'foo nil nil))))) |
| 938 | |||
| 939 | (match-expansion | ||
| 940 | (use-package counsel | ||
| 941 | :load-path "site-lisp/swiper" | ||
| 942 | :after ivy | ||
| 943 | :demand t | ||
| 944 | :diminish | ||
| 945 | :bind (("C-*" . counsel-org-agenda-headlines) | ||
| 946 | ("M-x" . counsel-M-x)) | ||
| 947 | :commands (counsel-minibuffer-history | ||
| 948 | counsel-find-library | ||
| 949 | counsel-unicode-char) | ||
| 950 | :preface (preface-code) | ||
| 951 | :init | ||
| 952 | ;; This is actually wrong, but it's just part of the example. | ||
| 953 | (define-key minibuffer-local-map (kbd "M-r") | ||
| 954 | 'counsel-minibuffer-history)) | ||
| 955 | `(progn | ||
| 956 | (eval-and-compile | ||
| 957 | (add-to-list 'load-path "/Users/johnw/.emacs.d/site-lisp/swiper")) | ||
| 958 | (eval-and-compile | ||
| 959 | (preface-code)) | ||
| 960 | (eval-after-load 'ivy | ||
| 961 | '(progn | ||
| 962 | (define-key minibuffer-local-map (kbd "M-r") | ||
| 963 | 'counsel-minibuffer-history) | ||
| 964 | (require 'counsel nil nil) | ||
| 965 | (if (fboundp 'diminish) | ||
| 966 | (diminish 'counsel-mode)) | ||
| 967 | (ignore | ||
| 968 | (bind-keys :package counsel | ||
| 969 | ("C-*" . counsel-org-agenda-headlines) | ||
| 970 | ("M-x" . counsel-M-x)))))))) | ||
| 950 | 971 | ||
| 951 | (ert-deftest use-package-test/:config () | 972 | (ert-deftest use-package-test/:config () |
| 952 | (match-expansion | 973 | (match-expansion |
| @@ -970,11 +991,10 @@ | |||
| 970 | 991 | ||
| 971 | (match-expansion | 992 | (match-expansion |
| 972 | (use-package foo :defer t :config (config)) | 993 | (use-package foo :defer t :config (config)) |
| 973 | `(progn | 994 | `(eval-after-load 'foo |
| 974 | (eval-after-load 'foo | 995 | '(progn |
| 975 | '(progn | 996 | (config) |
| 976 | (config) | 997 | t))) |
| 977 | t)))) | ||
| 978 | 998 | ||
| 979 | (let ((byte-compile-current-file t)) | 999 | (let ((byte-compile-current-file t)) |
| 980 | (match-expansion | 1000 | (match-expansion |