From 5d9c854a6cf12fff2326ee5653e87e2d3d550a8d Mon Sep 17 00:00:00 2001 From: Justin Talbott Date: Mon, 4 Dec 2017 10:57:23 -0500 Subject: [PATCH 01/17] Add `use-package-chords` and `use-package-ensure-system-package` Also update docs on usage connect to https://github.com/jwiegley/use-package/issues/516 --- lisp/use-package/bind-chord.el | 61 ++++++++++++++++ lisp/use-package/use-package-chords.el | 48 +++++++++++++ .../use-package-ensure-system-package.el | 70 +++++++++++++++++++ 3 files changed, 179 insertions(+) create mode 100644 lisp/use-package/bind-chord.el create mode 100644 lisp/use-package/use-package-chords.el create mode 100644 lisp/use-package/use-package-ensure-system-package.el diff --git a/lisp/use-package/bind-chord.el b/lisp/use-package/bind-chord.el new file mode 100644 index 00000000000..e0827a4230f --- /dev/null +++ b/lisp/use-package/bind-chord.el @@ -0,0 +1,61 @@ +;;; bind-chord.el --- key-chord binding helper for use-package-chords + +;; Copyright (C) 2015-2017 Justin Talbott + +;; Author: Justin Talbott +;; Keywords: convenience, tools, extensions +;; URL: https://github.com/waymondo/use-package-chords +;; Version: 0.2 +;; Package-Requires: ((bind-key "1.0") (key-chord "0.6")) +;; Filename: bind-chord.el +;; License: GNU General Public License version 3, or (at your option) any later version +;; + +;;; Commentary: +;; + +;;; Code: + +(require 'bind-key) +(require 'key-chord) + +;;;###autoload +(defmacro bind-chord (chord command &optional keymap) + "Bind CHORD to COMMAND in KEYMAP (`global-map' if not passed)." + (let ((key1 (logand 255 (aref chord 0))) + (key2 (logand 255 (aref chord 1)))) + (if (eq key1 key2) + `(bind-key (vector 'key-chord ,key1 ,key2) ,command ,keymap) + `(progn + (bind-key (vector 'key-chord ,key1 ,key2) ,command ,keymap) + (bind-key (vector 'key-chord ,key2 ,key1) ,command ,keymap))))) + +;;;###autoload +(defmacro bind-chords (&rest args) + "Bind multiple chords at once. + +Accepts keyword argument: +:map - a keymap into which the keybindings should be added + +The rest of the arguments are conses of keybinding string and a +function symbol (unquoted)." + (let* ((map (plist-get args :map)) + (maps (if (listp map) map (list map))) + (key-bindings (progn + (while (keywordp (car args)) + (pop args) + (pop args)) + args))) + (macroexp-progn + (apply + #'nconc + (mapcar (lambda (form) + (if maps + (mapcar + #'(lambda (m) + `(bind-chord ,(car form) ',(cdr form) ,m)) maps) + `((bind-chord ,(car form) ',(cdr form))))) + key-bindings))))) + +(provide 'bind-chord) +;;; bind-chord.el ends here diff --git a/lisp/use-package/use-package-chords.el b/lisp/use-package/use-package-chords.el new file mode 100644 index 00000000000..f3e85b4149a --- /dev/null +++ b/lisp/use-package/use-package-chords.el @@ -0,0 +1,48 @@ +;;; use-package-chords.el --- key-chord keyword for use-package + +;; Copyright (C) 2015-2017 Justin Talbott + +;; Author: Justin Talbott +;; Keywords: convenience, tools, extensions +;; URL: https://github.com/waymondo/use-package-chords +;; Version: 0.2 +;; Package-Requires: ((use-package "2.1") (bind-key "1.0") (bind-chord "0.2") (key-chord "0.6")) +;; Filename: use-package-chords.el +;; License: GNU General Public License version 3, or (at your option) any later version +;; + +;;; Commentary: +;; +;; The `:chords' keyword allows you to define `key-chord' bindings for +;; `use-package' declarations in the same manner as the `:bind' +;; keyword. +;; + +;;; Code: + +(require 'use-package) +(require 'bind-chord) + +(add-to-list 'use-package-keywords :chords t) + +(defalias 'use-package-normalize/:chords 'use-package-normalize-binder) + +(defun use-package-handler/:chords (name keyword arg rest state) + "Handler for `:chords' keyword in `use-package'." + (let* ((commands (remq nil (mapcar #'(lambda (arg) + (if (listp arg) + (cdr arg) + nil)) arg))) + (chord-binder + (use-package-concat + (use-package-process-keywords name + (use-package-sort-keywords + (use-package-plist-maybe-put rest :defer t)) + (use-package-plist-append state :commands commands)) + `((ignore + ,(macroexpand + `(bind-chords :package ,name ,@arg))))))) + (use-package-handler/:preface name keyword chord-binder rest state))) + +(provide 'use-package-chords) +;;; use-package-chords.el ends here diff --git a/lisp/use-package/use-package-ensure-system-package.el b/lisp/use-package/use-package-ensure-system-package.el new file mode 100644 index 00000000000..e34bb16d738 --- /dev/null +++ b/lisp/use-package/use-package-ensure-system-package.el @@ -0,0 +1,70 @@ +;;; use-package-ensure-system-package.el --- auto install system packages + +;; Copyright (C) 2017 Justin Talbott + +;; Author: Justin Talbott +;; Keywords: convenience, tools, extensions +;; URL: https://github.com/waymondo/use-package-ensure-system-package +;; Version: 0.1 +;; Package-Requires: ((use-package "2.1") (system-packages "0.1")) +;; Filename: use-package-ensure-system-package.el +;; License: GNU General Public License version 3, or (at your option) any later version +;; + +;;; Commentary: +;; +;; The `:ensure-system-package` keyword allows you to ensure system +;; binaries exist alongside your `use-package` declarations. +;; + +;;; Code: + +(require 'use-package) +(require 'system-packages) + +(add-to-list 'use-package-keywords :ensure-system-package t) + +(defun use-package-ensure-system-package-install-command (pack) + "Return the default install command for `pack'." + (let ((command + (cdr (assoc 'install (cdr (assoc system-packages-packagemanager + system-packages-supported-package-managers)))))) + (unless command + (error (format "%S not supported in %S" 'install system-packages-packagemanager))) + (unless (listp command) + (setq command (list command))) + (when system-packages-usesudo + (setq command (mapcar (lambda (part) (concat "sudo " part)) command))) + (setq command (mapconcat 'identity command " && ")) + (mapconcat 'identity (list command pack) " "))) + +(defun use-package-ensure-system-package-consify (arg) + "Turn `arg' into a cons of (`package-name' . `install-command')." + (cond + ((stringp arg) + (cons arg (use-package-ensure-system-package-install-command arg))) + ((symbolp arg) + (cons arg (use-package-ensure-system-package-install-command (symbol-name arg)))) + ((consp arg) arg))) + +(defun use-package-normalize/:ensure-system-package (name-symbol keyword args) + "Turn `arg' into a list of cons-es of (`package-name' . `install-command')." + (use-package-only-one (symbol-name keyword) args + (lambda (label arg) + (cond + ((and (listp arg) (listp (cdr arg))) + (mapcar #'use-package-ensure-system-package-consify arg)) + (t + (list (use-package-ensure-system-package-consify arg))))))) + +(defun use-package-handler/:ensure-system-package (name keyword arg rest state) + "Execute the handler for `:ensure-system-package' keyword in `use-package'." + (let ((body (use-package-process-keywords name rest state))) + (use-package-concat + (mapcar #'(lambda (cons) + `(unless (executable-find (symbol-name ',(car cons))) + (async-shell-command ,(cdr cons)))) arg) + body))) + +(provide 'use-package-ensure-system-package) +;;; use-package-ensure-system-package.el ends here From 0239ee227a5d40a13430843f61eea4f57afc2c7e Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Mon, 4 Dec 2017 09:03:13 -0800 Subject: [PATCH 02/17] Move :init back to happening after all autoloads have occurred Fixes https://github.com/jwiegley/use-package/issues/535 --- up-core.el | 2 +- up-tests.el | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/up-core.el b/up-core.el index d809970cdb7..b78c619c003 100644 --- a/up-core.el +++ b/up-core.el @@ -66,7 +66,6 @@ :after :custom :custom-face - :init :bind :bind* :bind-keymap @@ -79,6 +78,7 @@ ;; Any other keyword that also declares commands to be autoloaded (such as ;; :bind) must appear before this keyword. :commands + :init :defer :demand :load diff --git a/up-tests.el b/up-tests.el index 8de058c4512..33b43654313 100644 --- a/up-tests.el +++ b/up-tests.el @@ -662,6 +662,15 @@ (eval-when-compile (declare-function quux "foo")))))) +(ert-deftest use-package-test/:commands-4 () + (match-expansion + (use-package foo :commands bar :init (bar)) + `(progn + (unless + (fboundp 'bar) + (autoload #'bar "foo" nil t)) + (bar)))) + (ert-deftest use-package-test/:defines-1 () (match-expansion (use-package foo :defines bar) From ac906479a782c5eedd2662fe4f65aa3ac6d3489c Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Mon, 4 Dec 2017 09:31:13 -0800 Subject: [PATCH 03/17] Normalize some whitespace and ordering in new code --- lisp/use-package/bind-chord.el | 1 + lisp/use-package/use-package-chords.el | 5 +++-- lisp/use-package/use-package-ensure-system-package.el | 5 +++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lisp/use-package/bind-chord.el b/lisp/use-package/bind-chord.el index e0827a4230f..35634b174a3 100644 --- a/lisp/use-package/bind-chord.el +++ b/lisp/use-package/bind-chord.el @@ -58,4 +58,5 @@ function symbol (unquoted)." key-bindings))))) (provide 'bind-chord) + ;;; bind-chord.el ends here diff --git a/lisp/use-package/use-package-chords.el b/lisp/use-package/use-package-chords.el index f3e85b4149a..023a9c6b2ad 100644 --- a/lisp/use-package/use-package-chords.el +++ b/lisp/use-package/use-package-chords.el @@ -23,8 +23,6 @@ (require 'use-package) (require 'bind-chord) -(add-to-list 'use-package-keywords :chords t) - (defalias 'use-package-normalize/:chords 'use-package-normalize-binder) (defun use-package-handler/:chords (name keyword arg rest state) @@ -44,5 +42,8 @@ `(bind-chords :package ,name ,@arg))))))) (use-package-handler/:preface name keyword chord-binder rest state))) +(add-to-list 'use-package-keywords :chords t) + (provide 'use-package-chords) + ;;; use-package-chords.el ends here diff --git a/lisp/use-package/use-package-ensure-system-package.el b/lisp/use-package/use-package-ensure-system-package.el index e34bb16d738..b8fd19d830b 100644 --- a/lisp/use-package/use-package-ensure-system-package.el +++ b/lisp/use-package/use-package-ensure-system-package.el @@ -22,8 +22,6 @@ (require 'use-package) (require 'system-packages) -(add-to-list 'use-package-keywords :ensure-system-package t) - (defun use-package-ensure-system-package-install-command (pack) "Return the default install command for `pack'." (let ((command @@ -66,5 +64,8 @@ (async-shell-command ,(cdr cons)))) arg) body))) +(add-to-list 'use-package-keywords :ensure-system-package t) + (provide 'use-package-ensure-system-package) + ;;; use-package-ensure-system-package.el ends here From 1e560c514004747062276ca59ddf425a3edc44cd Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Mon, 4 Dec 2017 09:33:10 -0800 Subject: [PATCH 04/17] Reduce some code duplication --- up-core.el | 26 +++++++++++++------------- up-ensure.el | 35 +++++++++++++---------------------- 2 files changed, 26 insertions(+), 35 deletions(-) diff --git a/up-core.el b/up-core.el index b78c619c003..73884196e7f 100644 --- a/up-core.el +++ b/up-core.el @@ -273,6 +273,16 @@ Must be set before loading use-package." "Report MSG as an error, so the user knows it came from this package." (error "use-package: %s" msg)) +(defun use-package-hush (f body) + (condition-case-unless-debug err + (macroexp-progn body) + (error + (if (stringp f) + (ignore (display-warning 'use-package + (format f (error-message-string err)) + :error)) + (funcall f err))))) + (defsubst use-package-concat (&rest elems) "Delete all empty lists from ELEMS (nil or (list nil)), and append them." (apply #'append (delete nil (delete (list nil) elems)))) @@ -1297,11 +1307,6 @@ no keyword implies `:all'." ;;; The main macro ;; -(defsubst use-package-hush (context body) - `((condition-case-unless-debug err - ,(macroexp-progn body) - (error (funcall ,context err))))) - (defun use-package-core (name args) (let* ((context (gensym "use-package--warning")) (args* (use-package-normalize-keywords name args)) @@ -1404,14 +1409,9 @@ this file. Usage: (macroexp-progn (if (eq use-package-verbose 'errors) (use-package-core name args) - (condition-case-unless-debug err - (use-package-core name args) - (error - (ignore - (display-warning - 'use-package - (format "Failed to parse package %s: %s" - name (error-message-string err)) :error)))))))) + (use-package-hush + (format "Failed to parse package %s: %%s" name) + '((use-package-core name args))))))) (put 'use-package 'lisp-indent-function 'defun) diff --git a/up-ensure.el b/up-ensure.el index fa19e1d5a8e..cd6a8533992 100644 --- a/up-ensure.el +++ b/up-ensure.el @@ -143,31 +143,22 @@ manually updated package." "(an unquoted symbol name)"))))))) (defun use-package-ensure-elpa (name ensure state &optional no-refresh) - (let ((package - (or (and (eq ensure t) (use-package-as-symbol name)) - ensure))) + (let ((package (or (and (eq ensure t) (use-package-as-symbol name)) + ensure))) (when package (require 'package) (unless (package-installed-p package) - (condition-case-unless-debug err - (progn - (when (assoc package (bound-and-true-p - package-pinned-packages)) - (package-read-all-archive-contents)) - (if (assoc package package-archive-contents) - (package-install package) - (package-refresh-contents) - (when (assoc package (bound-and-true-p - package-pinned-packages)) - (package-read-all-archive-contents)) - (package-install package)) - t) - (error - (ignore - (display-warning 'use-package - (format "Failed to install %s: %s" - name (error-message-string err)) - :error)))))))) + (use-package-hush + (format "Failed to install %s: %%s" name) + '((when (assoc package (bound-and-true-p package-pinned-packages)) + (package-read-all-archive-contents)) + (if (assoc package package-archive-contents) + (package-install package) + (package-refresh-contents) + (when (assoc package (bound-and-true-p package-pinned-packages)) + (package-read-all-archive-contents)) + (package-install package)) + t)))))) (defun use-package-handler/:ensure (name keyword ensure rest state) (let* ((body (use-package-process-keywords name rest state))) From 4efd35510871047b438241788be77c089ac78945 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Mon, 4 Dec 2017 09:33:18 -0800 Subject: [PATCH 05/17] Add two new tests --- up-tests.el | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/up-tests.el b/up-tests.el index 33b43654313..063db98bbea 100644 --- a/up-tests.el +++ b/up-tests.el @@ -1219,6 +1219,38 @@ (if (fboundp 'delight) (delight '((foo "bar" foo))))))) +(ert-deftest use-package-test/538 () + (match-expansion + (use-package mu4e + :commands (mu4e) + :bind (("" . mu4e)) + :init + :config + (config)) + `(progn + (unless + (fboundp 'mu4e) + (autoload #'mu4e "mu4e" nil t)) + (eval-after-load 'mu4e + '(progn + (config) + t)) + (ignore + (bind-keys :package mu4e + ("" . mu4e)))))) + +(ert-deftest use-package-test/539 () + (match-expansion + (use-package foo + :requires bar + :after quux + :ensure bow) + `(progn + (use-package-ensure-elpa 'foo 'bow 'nil) + (when (featurep 'bar) + (eval-after-load 'quux + '(require 'foo nil nil)))))) + ;; Local Variables: ;; indent-tabs-mode: nil ;; no-byte-compile: t From fb9d1596326cf2d1c4472eabb36f50d40ca37cfb Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Mon, 4 Dec 2017 09:39:54 -0800 Subject: [PATCH 06/17] Move :preface handling within the code --- up-core.el | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/up-core.el b/up-core.el index 73884196e7f..6994c632ec0 100644 --- a/up-core.el +++ b/up-core.el @@ -939,17 +939,6 @@ deferred until the prefix key sequence is pressed." (defun use-package-handler/:no-require (name keyword arg rest state) (use-package-process-keywords name rest state)) -;;;; :preface - -(defalias 'use-package-normalize/:preface 'use-package-normalize-forms) - -(defun use-package-handler/:preface (name keyword arg rest state) - (let ((body (use-package-process-keywords name rest state))) - (use-package-concat - (when arg - `((eval-and-compile ,@arg))) - body))) - ;;;; :defines (defalias 'use-package-normalize/:defines 'use-package-normalize-symlist) @@ -964,6 +953,17 @@ deferred until the prefix key sequence is pressed." (defun use-package-handler/:functions (name keyword arg rest state) (use-package-process-keywords name rest state)) +;;;; :preface + +(defalias 'use-package-normalize/:preface 'use-package-normalize-forms) + +(defun use-package-handler/:preface (name keyword arg rest state) + (let ((body (use-package-process-keywords name rest state))) + (use-package-concat + (when arg + `((eval-and-compile ,@arg))) + body))) + ;;;; :bind, :bind* (defalias 'use-package-normalize/:bind 'use-package-normalize-binder) From 026433a8a03133b76f1d9db9d9a7b250a5d28a13 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Mon, 4 Dec 2017 10:29:27 -0800 Subject: [PATCH 07/17] Revert "Reduce some code duplication" This reverts commit 1e560c514004747062276ca59ddf425a3edc44cd. --- up-core.el | 26 +++++++++++++------------- up-ensure.el | 35 ++++++++++++++++++++++------------- 2 files changed, 35 insertions(+), 26 deletions(-) diff --git a/up-core.el b/up-core.el index 6994c632ec0..6fc8ae5a7ef 100644 --- a/up-core.el +++ b/up-core.el @@ -273,16 +273,6 @@ Must be set before loading use-package." "Report MSG as an error, so the user knows it came from this package." (error "use-package: %s" msg)) -(defun use-package-hush (f body) - (condition-case-unless-debug err - (macroexp-progn body) - (error - (if (stringp f) - (ignore (display-warning 'use-package - (format f (error-message-string err)) - :error)) - (funcall f err))))) - (defsubst use-package-concat (&rest elems) "Delete all empty lists from ELEMS (nil or (list nil)), and append them." (apply #'append (delete nil (delete (list nil) elems)))) @@ -1307,6 +1297,11 @@ no keyword implies `:all'." ;;; The main macro ;; +(defsubst use-package-hush (context body) + `((condition-case-unless-debug err + ,(macroexp-progn body) + (error (funcall ,context err))))) + (defun use-package-core (name args) (let* ((context (gensym "use-package--warning")) (args* (use-package-normalize-keywords name args)) @@ -1409,9 +1404,14 @@ this file. Usage: (macroexp-progn (if (eq use-package-verbose 'errors) (use-package-core name args) - (use-package-hush - (format "Failed to parse package %s: %%s" name) - '((use-package-core name args))))))) + (condition-case-unless-debug err + (use-package-core name args) + (error + (ignore + (display-warning + 'use-package + (format "Failed to parse package %s: %s" + name (error-message-string err)) :error)))))))) (put 'use-package 'lisp-indent-function 'defun) diff --git a/up-ensure.el b/up-ensure.el index cd6a8533992..fa19e1d5a8e 100644 --- a/up-ensure.el +++ b/up-ensure.el @@ -143,22 +143,31 @@ manually updated package." "(an unquoted symbol name)"))))))) (defun use-package-ensure-elpa (name ensure state &optional no-refresh) - (let ((package (or (and (eq ensure t) (use-package-as-symbol name)) - ensure))) + (let ((package + (or (and (eq ensure t) (use-package-as-symbol name)) + ensure))) (when package (require 'package) (unless (package-installed-p package) - (use-package-hush - (format "Failed to install %s: %%s" name) - '((when (assoc package (bound-and-true-p package-pinned-packages)) - (package-read-all-archive-contents)) - (if (assoc package package-archive-contents) - (package-install package) - (package-refresh-contents) - (when (assoc package (bound-and-true-p package-pinned-packages)) - (package-read-all-archive-contents)) - (package-install package)) - t)))))) + (condition-case-unless-debug err + (progn + (when (assoc package (bound-and-true-p + package-pinned-packages)) + (package-read-all-archive-contents)) + (if (assoc package package-archive-contents) + (package-install package) + (package-refresh-contents) + (when (assoc package (bound-and-true-p + package-pinned-packages)) + (package-read-all-archive-contents)) + (package-install package)) + t) + (error + (ignore + (display-warning 'use-package + (format "Failed to install %s: %s" + name (error-message-string err)) + :error)))))))) (defun use-package-handler/:ensure (name keyword ensure rest state) (let* ((body (use-package-process-keywords name rest state))) From 4042b87c720f68d213eb4933c010820de99834d2 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Mon, 4 Dec 2017 10:30:49 -0800 Subject: [PATCH 08/17] Add expand-maximally macro to up-tests.el --- up-tests.el | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/up-tests.el b/up-tests.el index 063db98bbea..2635c7df757 100644 --- a/up-tests.el +++ b/up-tests.el @@ -61,6 +61,11 @@ (use-package-expand-minimally t)) (macroexpand-1 ',form))) +(defmacro expand-maximally (form) + `(let ((use-package-verbose 'debug) + (use-package-expand-minimally nil)) + (macroexpand-1 ',form))) + (defmacro match-expansion (form &rest value) `(should (pcase (expand-minimally ,form) ,@(mapcar #'(lambda (x) (list x t)) value)))) From 8489206db4abe4edd2de6b54b09961d99111dba6 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Mon, 4 Dec 2017 10:41:17 -0800 Subject: [PATCH 09/17] Fix duplication in an error message --- up-core.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/up-core.el b/up-core.el index 6fc8ae5a7ef..aa677e1ad80 100644 --- a/up-core.el +++ b/up-core.el @@ -851,7 +851,7 @@ deferred until the prefix key sequence is pressed." (setq unread-command-events (listify-key-sequence kv))) (use-package-error - (format "use-package: package.el %s failed to define keymap %s" + (format "package.el %s failed to define keymap %s" package keymap-symbol))))) (defun use-package-normalize-mode (name keyword args) From fe85f246b0cd22ec3d8915d47ec6798958cbeefd Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Mon, 4 Dec 2017 11:00:05 -0800 Subject: [PATCH 10/17] Add a new :catch keyword, and move :preface before such handling Fixes https://github.com/jwiegley/use-package/issues/534 --- etc/USE-PACKAGE-NEWS | 6 +++ up-core.el | 121 +++++++++++++++++++++++++------------------ up-tests.el | 29 +++++++++++ 3 files changed, 107 insertions(+), 49 deletions(-) diff --git a/etc/USE-PACKAGE-NEWS b/etc/USE-PACKAGE-NEWS index de9de0e977d..b5b5adc0be0 100644 --- a/etc/USE-PACKAGE-NEWS +++ b/etc/USE-PACKAGE-NEWS @@ -52,6 +52,12 @@ - New `:hook` keyword. +- New `:catch` keyword. If `t` or `nil`, it enables (the default, see + `use-package-defaults`) or disables catching errors at load time in + use-package expansions. It can also be a function taking two arguments: the + keyword being processed at the time the error was encountered, and the error + object (as generated by `condition-case`). + - New keywords `:custom (foo1 bar1) (foo2 bar2)` etc., and `:custom-face`. - New `:magic` and `:magic-fallback` keywords. diff --git a/up-core.el b/up-core.el index aa677e1ad80..deaead24e85 100644 --- a/up-core.el +++ b/up-core.el @@ -63,6 +63,7 @@ :defines :functions :preface + :catch :after :custom :custom-face @@ -148,6 +149,8 @@ See also `use-package-defaults', which uses this value." '(;; this '(t) has special meaning; see `use-package-handler/:config' (:config '(t) t) (:init nil t) + (:catch t (lambda (args) + (not use-package-expand-minimally))) (:defer use-package-always-defer (lambda (args) (and use-package-always-defer @@ -262,8 +265,6 @@ Must be set before loading use-package." (font-lock-add-keywords 'emacs-lisp-mode use-package-font-lock-keywords) -(defvar use-package--hush-function) - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;;; Utility functions @@ -954,6 +955,56 @@ deferred until the prefix key sequence is pressed." `((eval-and-compile ,@arg))) body))) +;;;; :catch + +(defvar use-package--form) +(defvar use-package--hush-function #'(lambda (keyword body) body)) + +(defsubst use-package-hush (context keyword body) + `((condition-case-unless-debug err + ,(macroexp-progn body) + (error (funcall ,context ,keyword err))))) + +(defun use-package-normalize/:catch (name keyword args) + (if (null args) + t + (use-package-only-one (symbol-name keyword) args + use-package--hush-function))) + +(defun use-package-handler/:catch (name keyword arg rest state) + (let* ((context (gensym "use-package--warning"))) + (cond + ((not arg) + (use-package-process-keywords name rest state)) + ((eq arg t) + `((let ((,context + #'(lambda (keyword err) + (let ((msg (format "%s/%s: %s" ',name keyword + (error-message-string err)))) + ,(when (eq use-package-verbose 'debug) + `(progn + (with-current-buffer + (get-buffer-create "*use-package*") + (goto-char (point-max)) + (insert "-----\n" msg ,use-package--form) + (emacs-lisp-mode)) + (setq msg + (concat msg + " (see the *use-package* buffer)")))) + (ignore (display-warning 'use-package msg :error)))))) + ,@(let ((use-package--hush-function + (apply-partially #'use-package-hush context))) + (funcall use-package--hush-function keyword + (use-package-process-keywords name rest state)))))) + ((functionp arg) + `((let ((,context ,arg)) + ,@(let ((use-package--hush-function + (apply-partially #'use-package-hush context))) + (funcall use-package--hush-function keyword + (use-package-process-keywords name rest state)))))) + (t + (use-package-error "The :catch keyword expects 't' or a function"))))) + ;;;; :bind, :bind* (defalias 'use-package-normalize/:bind 'use-package-normalize-binder) @@ -1253,7 +1304,7 @@ no keyword implies `:all'." (use-package-hook-injector (use-package-as-string name) :init arg))) (when init-body - (funcall use-package--hush-function + (funcall use-package--hush-function :init (if use-package-check-before-init `((when (locate-library ,(use-package-as-string name)) ,@init-body)) @@ -1285,7 +1336,7 @@ no keyword implies `:all'." body (use-package-with-elapsed-timer (format "Configuring package %s" name-symbol) - (funcall use-package--hush-function + (funcall use-package--hush-function :config (use-package-concat (use-package-hook-injector (symbol-name name-symbol) :config arg) @@ -1297,52 +1348,24 @@ no keyword implies `:all'." ;;; The main macro ;; -(defsubst use-package-hush (context body) - `((condition-case-unless-debug err - ,(macroexp-progn body) - (error (funcall ,context err))))) - (defun use-package-core (name args) - (let* ((context (gensym "use-package--warning")) - (args* (use-package-normalize-keywords name args)) - (use-package--hush-function #'identity)) - (if use-package-expand-minimally - (use-package-process-keywords name args* - (and (plist-get args* :demand) - (list :demand t))) - `((let - ((,context - #'(lambda (err) - (let ((msg (format "%s: %s" ',name (error-message-string err)))) - ,(when (eq use-package-verbose 'debug) - `(progn - (with-current-buffer (get-buffer-create "*use-package*") - (goto-char (point-max)) - (insert - "-----\n" msg - ,(concat - "\n\n" - (pp-to-string `(use-package ,name ,@args)) - "\n -->\n\n" - (pp-to-string `(use-package ,name ,@args*)) - "\n ==>\n\n" - (pp-to-string - (macroexp-progn - (let ((use-package-verbose 'errors) - (use-package-expand-minimally t)) - (use-package-process-keywords name args* - (and (plist-get args* :demand) - (list :demand t)))))))) - (emacs-lisp-mode)) - (setq msg (concat msg " (see the *use-package* buffer)")))) - (ignore (display-warning 'use-package msg :error)))))) - ,(let ((use-package--hush-function - (apply-partially #'use-package-hush context))) - (macroexp-progn - (funcall use-package--hush-function - (use-package-process-keywords name args* - (and (plist-get args* :demand) - (list :demand t))))))))))) + (let* ((args* (use-package-normalize-keywords name args)) + (use-package--form + (concat "\n\n" + (pp-to-string `(use-package ,name ,@args)) + "\n -->\n\n" + (pp-to-string `(use-package ,name ,@args*)) + "\n ==>\n\n" + (pp-to-string + (macroexp-progn + (let ((use-package-verbose 'errors) + (use-package-expand-minimally t)) + (use-package-process-keywords name args* + (and (plist-get args* :demand) + (list :demand t))))))))) + (use-package-process-keywords name args* + (and (plist-get args* :demand) + (list :demand t))))) ;;;###autoload (defmacro use-package (name &rest args) diff --git a/up-tests.el b/up-tests.el index 2635c7df757..c23d706c32c 100644 --- a/up-tests.el +++ b/up-tests.el @@ -866,6 +866,35 @@ (init) (require 'foo nil nil))))) +(ert-deftest use-package-test/:catch-1 () + (match-expansion + (use-package foo :catch t) + `(let + ((,_ #'(lambda (keyword err) + (let ((msg (format "%s/%s: %s" 'foo keyword + (error-message-string err)))) + nil + (ignore (display-warning 'use-package msg :error)))))) + (condition-case-unless-debug err + (require 'foo nil nil) + (error + (funcall ,_ :catch err)))))) + +(ert-deftest use-package-test/:catch-2 () + (match-expansion + (use-package foo :catch nil) + `(require 'foo nil nil))) + +(ert-deftest use-package-test/:catch-3 () + (match-expansion + (use-package foo :catch (lambda (keyword error))) + `(let + ((,_ (lambda (keyword error)))) + (condition-case-unless-debug err + (require 'foo nil nil) + (error + (funcall ,_ :catch err)))))) + (ert-deftest use-package-test/:after-1 () (match-expansion (use-package foo :after bar) From 101dc9793bfd7ac0d9f2ec1f857bf1cef54ca679 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Mon, 4 Dec 2017 11:05:11 -0800 Subject: [PATCH 11/17] Ensure that :commands always declare-function at compile time --- up-core.el | 26 +++++++++++++------------- up-tests.el | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 13 deletions(-) diff --git a/up-core.el b/up-core.el index deaead24e85..d1732c3b2a2 100644 --- a/up-core.el +++ b/up-core.el @@ -1147,20 +1147,20 @@ deferred until the prefix key sequence is pressed." (defun use-package-handler/:commands (name keyword arg rest state) (use-package-concat - (unless (plist-get state :demand) - ;; Since we deferring load, establish any necessary autoloads, and also - ;; keep the byte-compiler happy. - (let ((name-string (use-package-as-string name))) - (cl-mapcan - #'(lambda (command) - (when (symbolp command) - (append + ;; Since we deferring load, establish any necessary autoloads, and also + ;; keep the byte-compiler happy. + (let ((name-string (use-package-as-string name))) + (cl-mapcan + #'(lambda (command) + (when (symbolp command) + (append + (unless (plist-get state :demand) `((unless (fboundp ',command) - (autoload #',command ,name-string nil t))) - (when (bound-and-true-p byte-compile-current-file) - `((eval-when-compile - (declare-function ,command ,name-string))))))) - (delete-dups arg)))) + (autoload #',command ,name-string nil t)))) + (when (bound-and-true-p byte-compile-current-file) + `((eval-when-compile + (declare-function ,command ,name-string))))))) + (delete-dups arg))) (use-package-process-keywords name rest state))) ;;;; :defer diff --git a/up-tests.el b/up-tests.el index c23d706c32c..3bcc340eaca 100644 --- a/up-tests.el +++ b/up-tests.el @@ -676,6 +676,52 @@ (autoload #'bar "foo" nil t)) (bar)))) +(ert-deftest use-package-test/:commands-5 () + (match-expansion + (use-package gnus-harvest + :load-path "lisp/gnus-harvest" + :commands gnus-harvest-install + :demand t + :config + (if (featurep 'message-x) + (gnus-harvest-install 'message-x) + (gnus-harvest-install))) + `(progn + (eval-and-compile + (add-to-list 'load-path "/Users/johnw/.emacs.d/lisp/gnus-harvest")) + (require 'gnus-harvest nil nil) + (if (featurep 'message-x) + (gnus-harvest-install 'message-x) + (gnus-harvest-install)) + t))) + +(ert-deftest use-package-test/:commands-6 () + (let ((byte-compile-current-file t)) + (match-expansion + (use-package gnus-harvest + :load-path "lisp/gnus-harvest" + :commands gnus-harvest-install + :demand t + :config + (if (featurep 'message-x) + (gnus-harvest-install 'message-x) + (gnus-harvest-install))) + `(progn + (eval-and-compile + (add-to-list 'load-path "/Users/johnw/.emacs.d/lisp/gnus-harvest")) + (eval-and-compile + (eval-when-compile + (with-demoted-errors "Cannot load gnus-harvest: %S" nil + (load "gnus-harvest" nil t)))) + (eval-when-compile + (declare-function gnus-harvest-install "gnus-harvest")) + (require 'gnus-harvest nil nil) + (if + (featurep 'message-x) + (gnus-harvest-install 'message-x) + (gnus-harvest-install)) + t)))) + (ert-deftest use-package-test/:defines-1 () (match-expansion (use-package foo :defines bar) From 01c3d756061b5f558895d674acc6d9a199707b43 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Mon, 4 Dec 2017 11:26:19 -0800 Subject: [PATCH 12/17] :ensure can be a list; correct handling of multiple :ensure keywords Fixes https://github.com/jwiegley/use-package/issues/539 --- up-ensure.el | 66 ++++++++++++++++++++++++++++------------------------ up-tests.el | 58 +++++++++++++++++++++++++++------------------ 2 files changed, 71 insertions(+), 53 deletions(-) diff --git a/up-ensure.el b/up-ensure.el index fa19e1d5a8e..30f2190e922 100644 --- a/up-ensure.el +++ b/up-ensure.el @@ -33,6 +33,7 @@ ;;; Code: +(require 'cl-lib) (require 'up-core) (defgroup use-package-ensure nil @@ -58,9 +59,9 @@ See also `use-package-defaults', which uses this value." (defcustom use-package-ensure-function 'use-package-ensure-elpa "Function that ensures a package is installed. This function is called with three arguments: the name of the -package declared in the `use-package' form; the argument passed -to `:ensure'; and the current `state' plist created by previous -handlers. +package declared in the `use-package' form; the arguments passed +to all `:ensure' keywords (always a list, even if only one); and +the current `state' plist created by previous handlers. Note that this function is called whenever `:ensure' is provided, even if it is nil. It is up to the function to decide on the @@ -136,38 +137,43 @@ manually updated package." t (use-package-only-one (symbol-name keyword) args #'(lambda (label arg) - (if (symbolp arg) - arg + (cond + ((symbolp arg) + (list arg)) + ((and (listp arg) (cl-every #'symbolp arg)) + arg) + (t (use-package-error (concat ":ensure wants an optional package name " - "(an unquoted symbol name)"))))))) + "(an unquoted symbol name)")))))))) -(defun use-package-ensure-elpa (name ensure state &optional no-refresh) - (let ((package - (or (and (eq ensure t) (use-package-as-symbol name)) - ensure))) - (when package - (require 'package) - (unless (package-installed-p package) - (condition-case-unless-debug err - (progn - (when (assoc package (bound-and-true-p - package-pinned-packages)) - (package-read-all-archive-contents)) - (if (assoc package package-archive-contents) - (package-install package) - (package-refresh-contents) +(defun use-package-ensure-elpa (name args state &optional no-refresh) + (dolist (ensure args) + (let ((package + (or (and (eq ensure t) (use-package-as-symbol name)) + ensure))) + (when package + (require 'package) + (unless (package-installed-p package) + (condition-case-unless-debug err + (progn (when (assoc package (bound-and-true-p package-pinned-packages)) (package-read-all-archive-contents)) - (package-install package)) - t) - (error - (ignore - (display-warning 'use-package - (format "Failed to install %s: %s" - name (error-message-string err)) - :error)))))))) + (if (assoc package package-archive-contents) + (package-install package) + (package-refresh-contents) + (when (assoc package (bound-and-true-p + package-pinned-packages)) + (package-read-all-archive-contents)) + (package-install package)) + t) + (error + (ignore + (display-warning 'use-package + (format "Failed to install %s: %s" + name (error-message-string err)) + :error))))))))) (defun use-package-handler/:ensure (name keyword ensure rest state) (let* ((body (use-package-process-keywords name rest state))) @@ -184,7 +190,7 @@ manually updated package." body)) (add-to-list 'use-package-defaults - '(:ensure use-package-always-ensure + '(:ensure (list use-package-always-ensure) (lambda (args) (and use-package-always-ensure (not (plist-member args :load-path))))) t) diff --git a/up-tests.el b/up-tests.el index 3bcc340eaca..efefd07612c 100644 --- a/up-tests.el +++ b/up-tests.el @@ -219,9 +219,9 @@ (flet ((norm (&rest args) (apply #'use-package-normalize/:ensure 'foopkg :ensure args))) - (should (equal (norm '(t)) t)) - (should (equal (norm '(nil)) nil)) - (should (equal (norm '(sym)) 'sym)) + (should (equal (norm '(t)) '(t))) + (should (equal (norm '(nil)) '(nil))) + (should (equal (norm '(sym)) '(sym))) (should-error (norm '(1))) (should-error (norm '("Hello"))))) @@ -230,7 +230,7 @@ (match-expansion (use-package foo :ensure t) `(progn - (use-package-ensure-elpa 'foo 't 'nil) + (use-package-ensure-elpa 'foo '(t) 'nil) (require 'foo nil nil))))) (ert-deftest use-package-test/:ensure-2 () @@ -238,7 +238,7 @@ (match-expansion (use-package foo :ensure t) `(progn - (use-package-ensure-elpa 'foo 't 'nil) + (use-package-ensure-elpa 'foo '(t) 'nil) (require 'foo nil nil))))) (ert-deftest use-package-test/:ensure-3 () @@ -246,7 +246,7 @@ (match-expansion (use-package foo :ensure nil) `(progn - (use-package-ensure-elpa 'foo 'nil 'nil) + (use-package-ensure-elpa 'foo '(nil) 'nil) (require 'foo nil nil))))) (ert-deftest use-package-test/:ensure-4 () @@ -254,7 +254,7 @@ (match-expansion (use-package foo :ensure nil) `(progn - (use-package-ensure-elpa 'foo 'nil 'nil) + (use-package-ensure-elpa 'foo '(nil) 'nil) (require 'foo nil nil))))) (ert-deftest use-package-test/:ensure-5 () @@ -280,7 +280,7 @@ (match-expansion (use-package foo :ensure nil :load-path "foo") `(progn - (use-package-ensure-elpa 'foo 'nil 'nil) + (use-package-ensure-elpa 'foo '(nil) 'nil) (eval-and-compile (add-to-list 'load-path ,(pred stringp))) (require 'foo nil nil))))) @@ -290,7 +290,7 @@ (match-expansion (use-package foo :ensure nil :load-path "foo") `(progn - (use-package-ensure-elpa 'foo 'nil 'nil) + (use-package-ensure-elpa 'foo '(nil) 'nil) (eval-and-compile (add-to-list 'load-path ,(pred stringp))) (require 'foo nil nil))))) @@ -300,7 +300,7 @@ (match-expansion (use-package foo :ensure t :load-path "foo") `(progn - (use-package-ensure-elpa 'foo 't 'nil) + (use-package-ensure-elpa 'foo '(t) 'nil) (eval-and-compile (add-to-list 'load-path ,(pred stringp))) (require 'foo nil nil))))) @@ -310,7 +310,7 @@ (match-expansion (use-package foo :ensure t :load-path "foo") `(progn - (use-package-ensure-elpa 'foo 't 'nil) + (use-package-ensure-elpa 'foo '(t) 'nil) (eval-and-compile (add-to-list 'load-path ,(pred stringp))) (require 'foo nil nil))))) @@ -325,6 +325,30 @@ (use-package foo :ensure t) (should (eq tried-to-install 'foo))))) +(ert-deftest use-package-test/:ensure-12 () + (let ((use-package-always-ensure t)) + (match-expansion + (use-package foo :ensure bar) + `(progn + (use-package-ensure-elpa 'foo '(bar) 'nil) + (require 'foo nil nil))))) + +(ert-deftest use-package-test/:ensure-13 () + (let ((use-package-always-ensure t)) + (match-expansion + (use-package foo :ensure bar :ensure quux) + `(progn + (use-package-ensure-elpa 'foo '(bar quux) 'nil) + (require 'foo nil nil))))) + +(ert-deftest use-package-test/:ensure-14 () + (let ((use-package-always-ensure t)) + (match-expansion + (use-package foo :ensure bar :ensure (quux bow)) + `(progn + (use-package-ensure-elpa 'foo '(bar quux bow) 'nil) + (require 'foo nil nil))))) + (ert-deftest use-package-test/:if-1 () (match-expansion (use-package foo :if t) @@ -1319,18 +1343,6 @@ (bind-keys :package mu4e ("" . mu4e)))))) -(ert-deftest use-package-test/539 () - (match-expansion - (use-package foo - :requires bar - :after quux - :ensure bow) - `(progn - (use-package-ensure-elpa 'foo 'bow 'nil) - (when (featurep 'bar) - (eval-after-load 'quux - '(require 'foo nil nil)))))) - ;; Local Variables: ;; indent-tabs-mode: nil ;; no-byte-compile: t From e36d208c694153bfb195a2750405483ebe306d8a Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Mon, 4 Dec 2017 11:32:27 -0800 Subject: [PATCH 13/17] Expand use-package-core as a macro, to avoid load time dependency --- up-core.el | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/up-core.el b/up-core.el index d1732c3b2a2..b4d86971b9b 100644 --- a/up-core.el +++ b/up-core.el @@ -1348,24 +1348,24 @@ no keyword implies `:all'." ;;; The main macro ;; -(defun use-package-core (name args) - (let* ((args* (use-package-normalize-keywords name args)) - (use-package--form - (concat "\n\n" - (pp-to-string `(use-package ,name ,@args)) - "\n -->\n\n" - (pp-to-string `(use-package ,name ,@args*)) - "\n ==>\n\n" - (pp-to-string - (macroexp-progn - (let ((use-package-verbose 'errors) - (use-package-expand-minimally t)) - (use-package-process-keywords name args* - (and (plist-get args* :demand) - (list :demand t))))))))) - (use-package-process-keywords name args* - (and (plist-get args* :demand) - (list :demand t))))) +(defmacro use-package-core (name args) + `(let* ((args* (use-package-normalize-keywords ,name ,args)) + (use-package--form + (concat "\n\n" + (pp-to-string `(use-package ,name ,@,args)) + "\n -->\n\n" + (pp-to-string `(use-package ,name ,@args*)) + "\n ==>\n\n" + (pp-to-string + (macroexp-progn + (let ((use-package-verbose 'errors) + (use-package-expand-minimally t)) + (use-package-process-keywords name args* + (and (plist-get args* :demand) + (list :demand t))))))))) + (use-package-process-keywords name args* + (and (plist-get args* :demand) + (list :demand t))))) ;;;###autoload (defmacro use-package (name &rest args) From 9245d08ebc9d123693437d00707d56e45fc5b9ec Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Mon, 4 Dec 2017 11:53:18 -0800 Subject: [PATCH 14/17] Require cl for the use-package tests --- up-tests.el | 1 + 1 file changed, 1 insertion(+) diff --git a/up-tests.el b/up-tests.el index efefd07612c..c1daf0499b9 100644 --- a/up-tests.el +++ b/up-tests.el @@ -22,6 +22,7 @@ ;;; Code: +(require 'cl) (require 'ert) (require 'use-package) From d771e8d71931d2b9d8bf3d19b1e2a98d9b02c218 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Mon, 4 Dec 2017 11:53:35 -0800 Subject: [PATCH 15/17] Please the byte-compiler --- lisp/use-package/bind-chord.el | 2 +- lisp/use-package/use-package-ensure-system-package.el | 7 ++++++- lisp/use-package/use-package.el | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lisp/use-package/bind-chord.el b/lisp/use-package/bind-chord.el index 35634b174a3..e5184bff60e 100644 --- a/lisp/use-package/bind-chord.el +++ b/lisp/use-package/bind-chord.el @@ -17,7 +17,7 @@ ;;; Code: (require 'bind-key) -(require 'key-chord) +(require 'key-chord nil t) ;;;###autoload (defmacro bind-chord (chord command &optional keymap) diff --git a/lisp/use-package/use-package-ensure-system-package.el b/lisp/use-package/use-package-ensure-system-package.el index b8fd19d830b..36a614d47c3 100644 --- a/lisp/use-package/use-package-ensure-system-package.el +++ b/lisp/use-package/use-package-ensure-system-package.el @@ -20,7 +20,12 @@ ;;; Code: (require 'use-package) -(require 'system-packages) +(require 'system-packages nil t) + +(eval-when-compile + (defvar system-packages-packagemanager) + (defvar system-packages-supported-package-managers) + (defvar system-packages-usesudo)) (defun use-package-ensure-system-package-install-command (pack) "Return the default install command for `pack'." diff --git a/lisp/use-package/use-package.el b/lisp/use-package/use-package.el index ec459ab1662..c6ab7d742c6 100644 --- a/lisp/use-package/use-package.el +++ b/lisp/use-package/use-package.el @@ -45,6 +45,7 @@ (require 'up-diminish) (require 'up-delight) +(declare-function use-package-jump-to-package-form "up-jump") (autoload #'use-package-jump-to-package-form "up-jump" nil t) (provide 'use-package) From 057814ae241e44f7550e5d485decb6f40e312d3c Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Mon, 4 Dec 2017 12:04:20 -0800 Subject: [PATCH 16/17] Add new customization variables `use-package-hook-name-suffix' Fixes https://github.com/jwiegley/use-package/issues/530 --- etc/USE-PACKAGE-NEWS | 2 ++ up-core.el | 14 ++++++++++++-- up-tests.el | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/etc/USE-PACKAGE-NEWS b/etc/USE-PACKAGE-NEWS index b5b5adc0be0..3bdd623adeb 100644 --- a/etc/USE-PACKAGE-NEWS +++ b/etc/USE-PACKAGE-NEWS @@ -66,6 +66,8 @@ - New customization variable `use-package-enable-imenu-support`. +- New customization variable `use-package-hook-name-suffix`. + - Allow `:diminish` to take no arguments. - Support multiple symbols passed to `:after`, and a mini-DSL using `:all` and diff --git a/up-core.el b/up-core.el index b4d86971b9b..fbaa862b066 100644 --- a/up-core.el +++ b/up-core.el @@ -180,6 +180,13 @@ be attempted." (choice :tag "Enable if non-nil" sexp function))) :group 'use-package) +(defcustom use-package-hook-name-suffix "-hook" + "Text append to the name of hooks mentioned by :hook. +Set to `nil' if you don't want this to happen; it's only a +convenience." + :type '(choice string (const :tag "No suffix" nil)) + :group 'use-package) + (defcustom use-package-minimum-reported-time 0.1 "Minimal load time that will be reported. Note that `use-package-verbose' has to be set to a non-nil value @@ -1136,8 +1143,11 @@ deferred until the prefix key sequence is pressed." (when fun (mapcar #'(lambda (sym) - `(add-hook (quote ,(intern (format "%s-hook" sym))) - (function ,fun))) + `(add-hook + (quote ,(intern + (concat (symbol-name sym) + use-package-hook-name-suffix))) + (function ,fun))) (if (use-package-non-nil-symbolp syms) (list syms) syms))))) nargs)))))) diff --git a/up-tests.el b/up-tests.el index c1daf0499b9..dcd3c8d308e 100644 --- a/up-tests.el +++ b/up-tests.el @@ -891,6 +891,38 @@ (ignore (bind-keys :package foo ("C-a" . key)))))))) +(ert-deftest use-package-test/:hook-2 () + (match-expansion + (use-package foo + :hook (hook . fun)) + `(progn + (unless (fboundp 'fun) + (autoload #'fun "foo" nil t)) + (ignore + (add-hook 'hook-hook #'fun))))) + +(ert-deftest use-package-test/:hook-3 () + (let ((use-package-hook-name-suffix nil)) + (match-expansion + (use-package foo + :hook (hook . fun)) + `(progn + (unless (fboundp 'fun) + (autoload #'fun "foo" nil t)) + (ignore + (add-hook 'hook #'fun)))))) + +(ert-deftest use-package-test/:hook-4 () + (let ((use-package-hook-name-suffix "-special")) + (match-expansion + (use-package foo + :hook (hook . fun)) + `(progn + (unless (fboundp 'fun) + (autoload #'fun "foo" nil t)) + (ignore + (add-hook 'hook-special #'fun)))))) + (ert-deftest use-package-test-normalize/:custom () (flet ((norm (&rest args) (apply #'use-package-normalize/:custom From 5382941ac3e57f6b930a0181be68d2a11a21eb9a Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Mon, 4 Dec 2017 12:09:52 -0800 Subject: [PATCH 17/17] Add a test-in-progress for issue 506 --- up-tests.el | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/up-tests.el b/up-tests.el index dcd3c8d308e..bb22b344479 100644 --- a/up-tests.el +++ b/up-tests.el @@ -1356,6 +1356,18 @@ (if (fboundp 'delight) (delight '((foo "bar" foo))))))) +(ert-deftest use-package-test/506 () + (match-expansion + (use-package ess-site + :ensure ess + :pin melpa-stable) + `(progn + (use-package-pin-package 'ess-site "melpa-stable") + (use-package-ensure-elpa 'ess-site + '(ess) + 'nil) + (require 'ess-site nil nil)))) + (ert-deftest use-package-test/538 () (match-expansion (use-package mu4e