1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-11-24 07:20:37 +00:00

Merge remote-tracking branch 'origin/master' into defer-install

Resolve merge conflicts.
This commit is contained in:
Radon Rosborough 2017-03-18 20:43:40 -07:00
commit 249de4b44d
2 changed files with 164 additions and 44 deletions

View File

@ -470,6 +470,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)
@ -804,6 +826,22 @@ If the package is installed, its entry is removed from
(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)
@ -898,47 +936,44 @@ If the package is installed, its entry is removed from
;;; :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))))
(unless (consp arg)
(use-package-error
(concat label " a (<string or vector> . <symbol or string>)"
" 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))))
(defalias 'use-package-normalize/:bind 'use-package-normalize-binder)
(defalias 'use-package-normalize/:bind* 'use-package-normalize-binder)
@ -970,6 +1005,7 @@ may also be a string, as accepted by `define-key'."
(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
@ -1026,7 +1062,10 @@ 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
#'use-package-regex-p
(lambda (m) (and (not (null m)) (symbolp m)))
name)))
(defalias 'use-package-normalize/:interpreter 'use-package-normalize-mode)
@ -1034,6 +1073,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
@ -1053,6 +1094,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
@ -1182,34 +1225,52 @@ 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 &optional deferred-install)
(features)
"Return form for after any of FEATURES require NAME."
`(progn
,@(mapcar
(lambda (feat)
`(eval-after-load
(quote ,feat)
,(macroexp-progn
`(,@(when deferred-install
`((use-package-install-deferred-package
',name :after)))
'(require ',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
;; Here we are checking the marker value for deferred
;; installation set in `use-package-handler/:ensure'.
;; See also `use-package-handler/:defer-install'.
arg name (eq (plist-get state :defer-install) :ensure))))
(list (funcall (use-package-require-after-load arg)
(macroexp-progn
;; Here we are checking the marker value for deferred
;; installation set in `use-package-handler/:ensure'.
;; See also `use-package-handler/:defer-install'.
`(,@(when (eq (plist-get state :defer-install) :ensure)
`((use-package-install-deferred-package
'name :after)))
'(require (quote ,name) nil t))))))
body)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -1271,7 +1332,7 @@ deferred until the prefix key sequence is pressed."
;; installation set in `use-package-handler/:ensure'. See also
;; `use-package-handler/:defer-install'.
(when (eq (plist-get state :defer-install) :ensure)
(use-package-install-deferred-package name 'no-prompt :config))
(use-package-install-deferred-package name :config))
(use-package--with-elapsed-timer
(format "Loading package %s" name)
(if use-package-expand-minimally

View File

@ -0,0 +1,59 @@
;;; use-package-tests.el --- Tests for use-package.el
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 2, or (at
;; your option) any later version.
;; This program is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Commentary:
;;
;;; Code:
(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")))
(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" . foopkg))))
(should (equal (use-package-normalize-mode 'foopkg :mode '((".foo" . foo) (".bar" . bar)))
'((".foo" . foo) (".bar" . bar)))))
;; Local Variables:
;; indent-tabs-mode: nil
;; no-byte-compile: t
;; no-update-autoloads: t
;; End:
;;; use-package-tests.el ends here