From 5ed9a6b5a5dad3563a4aeab0fe3b79f92b3d59d8 Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Thu, 26 May 2016 15:00:56 -0400 Subject: [PATCH 1/9] Remove obsolete mplist tests The mplist functions were removed in the 2.0 refactoring (4ae584f3ff0e9bda05420ec3b8598e59374b0899). --- test/lisp/use-package/use-package-tests.el | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/test/lisp/use-package/use-package-tests.el b/test/lisp/use-package/use-package-tests.el index 0644a5ee493..0cd389b20aa 100644 --- a/test/lisp/use-package/use-package-tests.el +++ b/test/lisp/use-package/use-package-tests.el @@ -25,24 +25,6 @@ (require 'ert) (require 'use-package) -(ert-deftest use-package-mplist-get () - (let ((mplist '(:foo bar baz bal :blob plap plup :blam)) - (tests '((:foo . (bar baz bal)) - (:blob . (plap plup)) - (:blam . t) - (:blow . nil)))) - (mapc (lambda (test) - (should - (equal - (use-package-mplist-get mplist - (car test)) - (cdr test)))) - tests))) - -(ert-deftest use-package-mplist-keys () - (should (equal (use-package-mplist-keys - '(:foo bar baz bal :blob plap plup :blam)) - '(:foo :blob :blam)))) ;; Local Variables: ;; indent-tabs-mode: nil From fc57b342991b94640d5ff565a47b5603adec0a6f Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Thu, 26 May 2016 15:08:32 -0400 Subject: [PATCH 2/9] Refactor pair normalizers; add tests for them This is not a pure refactoring, it also fixes a bug where :bind ([keysym] . "string") would actually bind keysym to nil (i.e., unbind it). It now binds to "string" as expected. --- lisp/use-package/use-package.el | 45 ++++++++++------------ test/lisp/use-package/use-package-tests.el | 21 ++++++++++ 2 files changed, 41 insertions(+), 25 deletions(-) diff --git a/lisp/use-package/use-package.el b/lisp/use-package/use-package.el index 4928ece0b0d..aeb39b4c343 100644 --- a/lisp/use-package/use-package.el +++ b/lisp/use-package/use-package.el @@ -681,47 +681,40 @@ manually updated package." ;; :bind, :bind* ;; -(defsubst use-package-is-sympair (x &optional allow-vector) - "Return t if X has the type (STRING . SYMBOL)." +(defsubst use-package-is-pair (x car-pred cdr-pred) + "Return non-nil if X is a cons satisfying the given predicates. +CAR-PRED and CDR-PRED are applied to X's `car' and `cdr', +respectively." (and (consp x) - (or (stringp (car x)) - (and allow-vector (vectorp (car x)))) - (symbolp (cdr x)))) - -(defsubst use-package-is-string-pair (x) - "Return t if X has the type (STRING . STRING)." - (and (consp x) - (stringp (car x)) - (stringp (cdr x)))) + (funcall car-pred (car x)) + (funcall cdr-pred (cdr x)))) (defun use-package-normalize-pairs - (name label arg &optional recursed allow-vector allow-string-cdrs) - "Normalize a list of string/symbol pairs. -If RECURSED is non-nil, recurse into sublists. -If ALLOW-VECTOR is non-nil, then the key to bind may specify a -vector of keys, as accepted by `define-key'. -If ALLOW-STRING-CDRS is non-nil, then the command name to bind to -may also be a string, as accepted by `define-key'." + (key-pred val-pred name label arg &optional recursed) + "Normalize a list of pairs. +KEY-PRED and VAL-PRED are predicates recognizing valid keys and +values, respectively. +If RECURSED is non-nil, recurse into sublists." (cond - ((or (stringp arg) (and allow-vector (vectorp arg))) + ((funcall key-pred arg) (list (cons arg (use-package-as-symbol name)))) - ((use-package-is-sympair arg allow-vector) + ((use-package-is-pair arg key-pred val-pred) (list arg)) ((and (not recursed) (listp arg) (listp (cdr arg))) (mapcar #'(lambda (x) (let ((ret (use-package-normalize-pairs - name label x t allow-vector allow-string-cdrs))) + key-pred val-pred name label x t))) (if (listp ret) (car ret) ret))) arg)) - ((and allow-string-cdrs (use-package-is-string-pair arg)) - (list arg)) (t arg))) (defun use-package-normalize-binder (name keyword args) (use-package-as-one (symbol-name keyword) args (lambda (label arg) - (use-package-normalize-pairs name label arg nil t t)))) + (use-package-normalize-pairs (lambda (k) (or (stringp k) (vectorp k))) + (lambda (b) (or (symbolp b) (stringp b))) + name label arg)))) (defalias 'use-package-normalize/:bind 'use-package-normalize-binder) (defalias 'use-package-normalize/:bind* 'use-package-normalize-binder) @@ -809,7 +802,9 @@ deferred until the prefix key sequence is pressed." (defun use-package-normalize-mode (name keyword args) (use-package-as-one (symbol-name keyword) args - (apply-partially #'use-package-normalize-pairs name))) + (apply-partially #'use-package-normalize-pairs + #'stringp #'symbolp + name))) (defalias 'use-package-normalize/:interpreter 'use-package-normalize-mode) diff --git a/test/lisp/use-package/use-package-tests.el b/test/lisp/use-package/use-package-tests.el index 0cd389b20aa..aa9f542a803 100644 --- a/test/lisp/use-package/use-package-tests.el +++ b/test/lisp/use-package/use-package-tests.el @@ -25,6 +25,27 @@ (require 'ert) (require 'use-package) +(ert-deftest use-package-normalize-binder () + (let ((good-values '(:map map-sym + ("str" . sym) ("str" . "str") + ([vec] . sym) ([vec] . "str")))) + (should (equal (use-package-normalize-binder + 'foopkg :bind good-values) + good-values))) + (should-error (use-package-normalize-binder + 'foopkg :bind '("foo" . 99))) + (should-error (use-package-normalize-binder + 'foopkg :bind '(99 . sym)))) + +(ert-deftest use-package-normalize-mode () + (should (equal (use-package-normalize-mode 'foopkg :mode '(".foo")) + '((".foo" . foopkg)))) + (should (equal (use-package-normalize-mode 'foopkg :mode '(".foo" ".bar")) + '((".foo" . foopkg) (".bar" . foopkg)))) + (should (equal (use-package-normalize-mode 'foopkg :mode '((".foo" ".bar"))) + '((".foo" . foopkg) (".bar" . foopkg)))) + (should (equal (use-package-normalize-mode 'foopkg :mode '((".foo" . foo) (".bar" . bar))) + '((".foo" . foo) (".bar" . bar))))) ;; Local Variables: ;; indent-tabs-mode: nil From 65c7b42a14c5ad42d4b6c6e6547c793e0ccbfe80 Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Thu, 26 May 2016 15:09:46 -0400 Subject: [PATCH 3/9] Don't allow nil as a mode function This means (use-package foopkg :mode (".foo")) will add (".foo" . foopkg) into auto-mode-alist instead of the broken (".foo" . nil), this is more consistent with the behaviour of (use-package foopkg :mode (".foo" ".bar")). --- lisp/use-package/use-package.el | 2 +- test/lisp/use-package/use-package-tests.el | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lisp/use-package/use-package.el b/lisp/use-package/use-package.el index aeb39b4c343..96137c3c78d 100644 --- a/lisp/use-package/use-package.el +++ b/lisp/use-package/use-package.el @@ -803,7 +803,7 @@ deferred until the prefix key sequence is pressed." (defun use-package-normalize-mode (name keyword args) (use-package-as-one (symbol-name keyword) args (apply-partially #'use-package-normalize-pairs - #'stringp #'symbolp + #'stringp (lambda (m) (and (not (null m)) (symbolp m))) name))) (defalias 'use-package-normalize/:interpreter 'use-package-normalize-mode) diff --git a/test/lisp/use-package/use-package-tests.el b/test/lisp/use-package/use-package-tests.el index aa9f542a803..d3deef995b1 100644 --- a/test/lisp/use-package/use-package-tests.el +++ b/test/lisp/use-package/use-package-tests.el @@ -44,6 +44,8 @@ '((".foo" . foopkg) (".bar" . foopkg)))) (should (equal (use-package-normalize-mode 'foopkg :mode '((".foo" ".bar"))) '((".foo" . foopkg) (".bar" . foopkg)))) + (should (equal (use-package-normalize-mode 'foopkg :mode '((".foo"))) + '((".foo" . foopkg)))) (should (equal (use-package-normalize-mode 'foopkg :mode '((".foo" . foo) (".bar" . bar))) '((".foo" . foo) (".bar" . bar))))) From 9688d2f64bd01b86a98ccd87138e6fc0a345e62b Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Fri, 5 Aug 2016 18:43:34 -0400 Subject: [PATCH 4/9] Don't allow implicit package name arg for binders It's unlikely that (use-package foopkg :bind "") intendes to bind to 'foopkg command. --- lisp/use-package/use-package.el | 4 ++++ test/lisp/use-package/use-package-tests.el | 2 ++ 2 files changed, 6 insertions(+) diff --git a/lisp/use-package/use-package.el b/lisp/use-package/use-package.el index 96137c3c78d..f99a3767777 100644 --- a/lisp/use-package/use-package.el +++ b/lisp/use-package/use-package.el @@ -712,6 +712,10 @@ If RECURSED is non-nil, recurse into sublists." (defun use-package-normalize-binder (name keyword args) (use-package-as-one (symbol-name keyword) args (lambda (label arg) + (unless (consp arg) + (use-package-error + (concat label " a ( . )" + " or list of these"))) (use-package-normalize-pairs (lambda (k) (or (stringp k) (vectorp k))) (lambda (b) (or (symbolp b) (stringp b))) name label arg)))) diff --git a/test/lisp/use-package/use-package-tests.el b/test/lisp/use-package/use-package-tests.el index d3deef995b1..00682e9e0fc 100644 --- a/test/lisp/use-package/use-package-tests.el +++ b/test/lisp/use-package/use-package-tests.el @@ -32,6 +32,8 @@ (should (equal (use-package-normalize-binder 'foopkg :bind good-values) good-values))) + (should-error (use-package-normalize-binder + 'foopkg :bind '("foo"))) (should-error (use-package-normalize-binder 'foopkg :bind '("foo" . 99))) (should-error (use-package-normalize-binder From 61d6a8e449739e443f224e223c6187a37440ca6b Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Thu, 16 Feb 2017 11:33:29 -0800 Subject: [PATCH 5/9] Add autoload cookie for use-package-autoload-keymap Fixes https://github.com/jwiegley/use-package/issues/337 --- lisp/use-package/use-package.el | 1 + 1 file changed, 1 insertion(+) diff --git a/lisp/use-package/use-package.el b/lisp/use-package/use-package.el index b20d149cb86..bb9fb4855ff 100644 --- a/lisp/use-package/use-package.el +++ b/lisp/use-package/use-package.el @@ -819,6 +819,7 @@ If RECURSED is non-nil, recurse into sublists." (defalias 'use-package-normalize/:bind-keymap 'use-package-normalize-binder) (defalias 'use-package-normalize/:bind-keymap* 'use-package-normalize-binder) +;;;###autoload (defun use-package-autoload-keymap (keymap-symbol package override) "Loads PACKAGE and then binds the key sequence used to invoke this function to KEYMAP-SYMBOL. It then simulates pressing the From 87a8ff6d693f3cc79ea423ca8c8e0a60b0bc596c Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Thu, 16 Feb 2017 11:44:41 -0800 Subject: [PATCH 6/9] Return `t' after calling `eval-after-load' Fixes https://github.com/jwiegley/use-package/issues/174 --- lisp/use-package/use-package.el | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lisp/use-package/use-package.el b/lisp/use-package/use-package.el index bb9fb4855ff..733a6316647 100644 --- a/lisp/use-package/use-package.el +++ b/lisp/use-package/use-package.el @@ -1070,8 +1070,10 @@ deferred until the prefix key sequence is pressed." (list t)))))) (if (plist-get state :deferred) (unless (or (null config-body) (equal config-body '(t))) - `((eval-after-load ,(if (symbolp name) `',name name) - ',(macroexp-progn config-body)))) + `((progn + (eval-after-load ,(if (symbolp name) `',name name) + ',(macroexp-progn config-body)) + t))) (use-package--with-elapsed-timer (format "Loading package %s" name) (if use-package-expand-minimally From f1fa65d7733ece85490d037775d73e1a3a4dae69 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Thu, 16 Feb 2017 12:03:59 -0800 Subject: [PATCH 7/9] :mode and :interpreter can now accept (rx ...) forms Fixes https://github.com/jwiegley/use-package/issues/204 --- lisp/use-package/use-package.el | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/lisp/use-package/use-package.el b/lisp/use-package/use-package.el index 733a6316647..c6387d7e1f1 100644 --- a/lisp/use-package/use-package.el +++ b/lisp/use-package/use-package.el @@ -427,6 +427,28 @@ This is in contrast to merely setting it to 0." ;;; Normalization functions ;; +(defun use-package-regex-p (re) + "Return t if RE is some regexp-like thing." + (cond + ((and (listp re) + (eq (car re) 'rx)) + t) + ((stringp re) + t) + (t + nil))) + +(defun use-package-normalize-regex (re) + "Given some regexp-like thing, resolve it down to a regular expression." + (cond + ((and (listp re) + (eq (car re) 'rx)) + (eval re)) + ((stringp re) + re) + (t + (error "Not recognized as regular expression: %s" re)))) + (defun use-package-normalize-plist (name input) "Given a pseudo-plist, normalize it to a regular plist." (unless (null input) @@ -877,7 +899,8 @@ deferred until the prefix key sequence is pressed." (defun use-package-normalize-mode (name keyword args) (use-package-as-one (symbol-name keyword) args (apply-partially #'use-package-normalize-pairs - #'stringp (lambda (m) (and (not (null m)) (symbolp m))) + #'use-package-regex-p + (lambda (m) (and (not (null m)) (symbolp m))) name))) (defalias 'use-package-normalize/:interpreter 'use-package-normalize-mode) @@ -886,6 +909,8 @@ deferred until the prefix key sequence is pressed." (let* (commands (form (mapcar #'(lambda (interpreter) (push (cdr interpreter) commands) + (setcar interpreter + (use-package-normalize-regex (car interpreter))) `(add-to-list 'interpreter-mode-alist ',interpreter)) arg))) (use-package-concat (use-package-process-keywords name @@ -905,6 +930,8 @@ deferred until the prefix key sequence is pressed." (let* (commands (form (mapcar #'(lambda (mode) (push (cdr mode) commands) + (setcar mode + (use-package-normalize-regex (car mode))) `(add-to-list 'auto-mode-alist ',mode)) arg))) (use-package-concat (use-package-process-keywords name From 0517689cf3bb55b034788d6427220bd42f8ca4b1 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Thu, 16 Feb 2017 13:48:05 -0800 Subject: [PATCH 8/9] Support multiple symbols passed to :after The following expressions are now permitted: foo ; load after foo is loaded foo bar ; load after both foo and bar are loaded :all foo bar ; same as previous :any foo bar ; load after either foo or bar is loaded :any (:all foo bar) baz ; more complex combinations... :any (:all foo bar) (:all baz wow) :all (:any foo bar) (:any baz wow) Fixes https://github.com/jwiegley/use-package/issues/283 --- lisp/use-package/use-package.el | 55 +++++++++++++++++++++++++++------ 1 file changed, 45 insertions(+), 10 deletions(-) diff --git a/lisp/use-package/use-package.el b/lisp/use-package/use-package.el index c6387d7e1f1..4b425242ed1 100644 --- a/lisp/use-package/use-package.el +++ b/lisp/use-package/use-package.el @@ -678,6 +678,22 @@ manually updated package." (use-package-as-one (symbol-name keyword) args #'use-package-normalize-symbols)) +(defun use-package-normalize-recursive-symbols (label arg) + "Normalize a list of symbols." + (cond + ((symbolp arg) + arg) + ((and (listp arg) (listp (cdr arg))) + (mapcar #'(lambda (x) (use-package-normalize-recursive-symbols label x)) + arg)) + (t + (use-package-error + (concat label " wants a symbol, or nested list of symbols"))))) + +(defun use-package-normalize-recursive-symlist (name keyword args) + (use-package-as-one (symbol-name keyword) args + #'use-package-normalize-recursive-symbols)) + (defalias 'use-package-normalize/:requires 'use-package-normalize-symlist) (defun use-package-handler/:requires (name keyword requires rest state) @@ -1023,25 +1039,44 @@ deferred until the prefix key sequence is pressed." ;;; :after ;; -(defalias 'use-package-normalize/:after 'use-package-normalize-symlist) +(defalias 'use-package-normalize/:after 'use-package-normalize-recursive-symlist) -(defun use-package-require-after-load (features name) +(defun use-package-require-after-load (features) "Return form for after any of FEATURES require NAME." - `(progn - ,@(mapcar - (lambda (feat) - `(eval-after-load - (quote ,feat) - (quote (require (quote ,name) nil t)))) - features))) + (pcase features + ((and (pred symbolp) feat) + `(lambda (body) + (list 'eval-after-load (list 'quote ',feat) + (list 'quote body)))) + (`(,(or :or :any) . ,rest) + `(lambda (body) + (append (list 'progn) + (mapcar (lambda (form) + (funcall form body)) + (list ,@(use-package-require-after-load rest)))))) + (`(,(or :and :all) . ,rest) + `(lambda (body) + (let ((result body)) + (dolist (form (list ,@(use-package-require-after-load rest))) + (setq result (funcall form result))) + result))) + (`(,feat . ,rest) + (if rest + (cons (use-package-require-after-load feat) + (use-package-require-after-load rest)) + (list (use-package-require-after-load feat)))))) (defun use-package-handler/:after (name keyword arg rest state) (let ((body (use-package-process-keywords name rest (plist-put state :deferred t))) (name-string (use-package-as-string name))) + (if (and (consp arg) + (not (memq (car arg) '(:or :any :and :all)))) + (setq arg (cons :all arg))) (use-package-concat (when arg - (list (use-package-require-after-load arg name))) + (list (funcall (use-package-require-after-load arg) + `(require (quote ,name) nil t)))) body))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; From 45442561d3ec095b7fa244d3b2c80b9847baee99 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sat, 18 Feb 2017 01:32:34 -0800 Subject: [PATCH 9/9] Revert "Return `t' after calling `eval-after-load'" This reverts commit 87a8ff6d693f3cc79ea423ca8c8e0a60b0bc596c. --- lisp/use-package/use-package.el | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lisp/use-package/use-package.el b/lisp/use-package/use-package.el index 4b425242ed1..99646e2690a 100644 --- a/lisp/use-package/use-package.el +++ b/lisp/use-package/use-package.el @@ -1132,10 +1132,8 @@ deferred until the prefix key sequence is pressed." (list t)))))) (if (plist-get state :deferred) (unless (or (null config-body) (equal config-body '(t))) - `((progn - (eval-after-load ,(if (symbolp name) `',name name) - ',(macroexp-progn config-body)) - t))) + `((eval-after-load ,(if (symbolp name) `',name name) + ',(macroexp-progn config-body)))) (use-package--with-elapsed-timer (format "Loading package %s" name) (if use-package-expand-minimally