From 471869269a2ab0a847c3d3ae34e8c7327a5919d8 Mon Sep 17 00:00:00 2001 From: Bernard Hurley Date: Fri, 20 Jun 2014 05:45:51 +0100 Subject: [PATCH 01/14] bind-keys macro changed to allow prefix map to have a menu string --- lisp/use-package/bind-key.el | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lisp/use-package/bind-key.el b/lisp/use-package/bind-key.el index e52ec07ed87..e5f990ef0f2 100644 --- a/lisp/use-package/bind-key.el +++ b/lisp/use-package/bind-key.el @@ -178,6 +178,7 @@ Accepts keyword arguments: these bindings :prefix - prefix key for these bindings :prefix-docstring - docstring for the prefix-map variable +:menu-name - optional menu string for prefix map The rest of the arguments are conses of keybinding string and a function symbol (unquoted)." @@ -185,6 +186,7 @@ function symbol (unquoted)." (doc (plist-get args :prefix-docstring)) (prefix-map (plist-get args :prefix-map)) (prefix (plist-get args :prefix)) + (menu-name (plist-get args :menu-name)) (key-bindings (progn (while (keywordp (car args)) (pop args) @@ -195,11 +197,15 @@ function symbol (unquoted)." (and prefix (not prefix-map))) (error "Both :prefix-map and :prefix must be supplied")) + (when (and menu-name (not prefix)) + (error "If :menu-name is supplied, :prefix must be too")) `(progn ,@(when prefix-map `((defvar ,prefix-map) ,@(when doc `((put ',prefix-map 'variable-documentation ,doc))) - (define-prefix-command ',prefix-map) + ,@(if menu-name + `((define-prefix-command ',prefix-map nil ,menu-name)) + `((define-prefix-command ',prefix-map))) (bind-key ,prefix ',prefix-map ,map))) ,@(mapcar (lambda (form) `(bind-key ,(car form) ',(cdr form) @@ -281,7 +287,7 @@ function symbol (unquoted)." (sort personal-keybindings #'(lambda (l r) (car (compare-keybindings l r)))))) - + (if (not (eq (cdar last-binding) (cdar binding))) (princ (format "\n\n%s\n%s\n\n" (cdar binding) @@ -289,7 +295,7 @@ function symbol (unquoted)." (if (and last-binding (cdr (compare-keybindings last-binding binding))) (princ "\n"))) - + (let* ((key-name (caar binding)) (at-present (lookup-key (or (symbol-value (cdar binding)) (current-global-map)) @@ -314,7 +320,7 @@ function symbol (unquoted)." (princ (if (string-match "[ \t]+\n" line) (replace-match "\n" t t line) line)))) - + (setq last-binding binding))))) (provide 'bind-key) From 31bb0cde56785731398b59af5cb0b48b016fcd36 Mon Sep 17 00:00:00 2001 From: Jonas Bernoulli Date: Sun, 7 Sep 2014 14:43:56 +0200 Subject: [PATCH 02/14] assume the declare-function macro exists Since `declare-function' was added in Emacs 23.1 (five years ago), we don't need to assert that it is defined. If the assertion was without any problems there would be no harm in keeping it, but unfortunately it causes a compile warning. Because `declare-function' is a macro with always expands to `nil' the value of (fboundp 'declare-function) ends up being unused. --- lisp/use-package/use-package.el | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lisp/use-package/use-package.el b/lisp/use-package/use-package.el index 7b370380d4b..7e4738fc9fe 100644 --- a/lisp/use-package/use-package.el +++ b/lisp/use-package/use-package.el @@ -41,8 +41,7 @@ (require 'bytecomp) (require 'diminish nil t) -(when (fboundp 'declare-function) - (declare-function package-installed-p 'package)) +(declare-function package-installed-p 'package) (defgroup use-package nil "A use-package declaration for simplifying your `.emacs'." From 351c10201092a6fb534728c3c19df1e87aa8fc1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Fr=C3=B6ssman?= Date: Sun, 14 Sep 2014 12:57:44 +0200 Subject: [PATCH 03/14] Display which package that has compile errors --- lisp/use-package/use-package.el | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lisp/use-package/use-package.el b/lisp/use-package/use-package.el index 7e4738fc9fe..34ea1ca30e5 100644 --- a/lisp/use-package/use-package.el +++ b/lisp/use-package/use-package.el @@ -401,10 +401,11 @@ For full documentation. please see commentary. (eval-when-compile (when (bound-and-true-p byte-compile-current-file) ,@defines-eval - (with-demoted-errors - ,(if (stringp name) - `(load ,name t) - `(require ',name nil t))))) + (condition-case err + ,(if (stringp name) + `(load ,name t) + `(require ',name nil t)) + (error (message "Error compiling %s: %s" ',name err) nil)))) ,(if (and (or commands (use-package-plist-get args :defer)) (not (use-package-plist-get args :demand))) From f07ecde5a1ba7d07405b4fd228b99529b37613a3 Mon Sep 17 00:00:00 2001 From: Philippe Vaucher Date: Tue, 16 Sep 2014 18:34:42 +0200 Subject: [PATCH 04/14] Fix "compiling" typo --- lisp/use-package/use-package.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lisp/use-package/use-package.el b/lisp/use-package/use-package.el index 34ea1ca30e5..fa8edb2f946 100644 --- a/lisp/use-package/use-package.el +++ b/lisp/use-package/use-package.el @@ -405,7 +405,7 @@ For full documentation. please see commentary. ,(if (stringp name) `(load ,name t) `(require ',name nil t)) - (error (message "Error compiling %s: %s" ',name err) nil)))) + (error (message "Error requiring %s: %s" ',name err) nil)))) ,(if (and (or commands (use-package-plist-get args :defer)) (not (use-package-plist-get args :demand))) From e8ce1b20ca3a99a5763e2d5404941d9697252a01 Mon Sep 17 00:00:00 2001 From: Justin Talbott Date: Tue, 16 Sep 2014 16:38:58 -0400 Subject: [PATCH 05/14] add :bind* keyword for `bind-key*` --- lisp/use-package/use-package.el | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lisp/use-package/use-package.el b/lisp/use-package/use-package.el index 34ea1ca30e5..68aa3c9d0b6 100644 --- a/lisp/use-package/use-package.el +++ b/lisp/use-package/use-package.el @@ -146,6 +146,7 @@ Return nil when the queue is empty." (defvar use-package-keywords '( :bind + :bind* :commands :config :defer @@ -247,6 +248,8 @@ For full documentation. please see commentary. :init Code to run when `use-package' form evals. :bind Perform key bindings, and define autoload for bound commands. +:bind* Perform key bindings, and define autoload for bound + commands, overriding all minor mode bindings. :commands Define autoloads for given commands. :pre-load Code to run when `use-package' form evals and before anything else. Unlike :init this form runs before the @@ -254,7 +257,7 @@ For full documentation. please see commentary. :mode Form to be added to `auto-mode-alist'. :interpreter Form to be added to `interpreter-mode-alist'. :defer Defer loading of package -- automatic - if :commands, :bind, :mode or :interpreter are used. + if :commands, :bind, :bind*, :mode or :interpreter are used. :demand Prevent deferred loading in all cases. :config Runs if and when package loads. :if Conditional loading. @@ -279,6 +282,7 @@ For full documentation. please see commentary. (idle-body (use-package-plist-get args :idle)) (idle-priority (use-package-plist-get args :idle-priority)) (keybindings-alist (use-package-plist-get args :bind t t)) + (overriding-keybindings-alist (use-package-plist-get args :bind* t t)) (mode (use-package-plist-get args :mode t t)) (mode-alist (if (stringp mode) (cons mode name) mode)) @@ -371,6 +375,12 @@ For full documentation. please see commentary. (quote ,(cdr binding)))) keybindings-alist) + (funcall init-for-commands + #'(lambda (binding) + `(bind-key* ,(car binding) + (quote ,(cdr binding)))) + overriding-keybindings-alist) + (funcall init-for-commands #'(lambda (mode) `(add-to-list 'auto-mode-alist From fe7fe61528008cf9bcfb5633c845d06da9c582bc Mon Sep 17 00:00:00 2001 From: Peter Hoeg Date: Thu, 11 Dec 2014 14:44:27 +0800 Subject: [PATCH 06/14] support for pinning package to archive --- lisp/use-package/use-package.el | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lisp/use-package/use-package.el b/lisp/use-package/use-package.el index bc2dec27380..570044970ea 100644 --- a/lisp/use-package/use-package.el +++ b/lisp/use-package/use-package.el @@ -139,6 +139,13 @@ Return nil when the queue is empty." (cancel-timer use-package-idle-timer) (setq use-package-idle-timer nil)))) +(defun use-package-pin-package (package archive) + "Pin PACKAGE to ARCHIVE." + (unless (boundp 'package-pinned-packages) + (setq package-pinned-packages '())) + (add-to-list 'package-pinned-packages (cons package archive)) + (package-initialize t)) + (defun use-package-ensure-elpa (package) (when (not (package-installed-p package)) (package-install package))) @@ -162,6 +169,7 @@ Return nil when the queue is empty." :interpreter :load-path :mode + :pin :pre-init :pre-load :requires @@ -270,7 +278,8 @@ For full documentation. please see commentary. priority (lower priorities run first). Default priority is 5; forms with the same priority are run in the order in which they are evaluated. -:ensure loads package using package.el if necessary." +:ensure loads package using package.el if necessary. +:pin pin package to archive." (use-package-validate-keywords args) ; error if any bad keyword, ignore result (let* ((commands (use-package-plist-get args :commands t t)) (pre-init-body (use-package-plist-get args :pre-init)) @@ -291,6 +300,7 @@ For full documentation. please see commentary. (if (stringp interpreter) (cons interpreter name) interpreter)) (predicate (use-package-plist-get args :if)) (pkg-load-path (use-package-plist-get args :load-path t t)) + (archive-name (use-package-plist-get args :pin)) (defines-eval (if (null defines) nil (if (listp defines) @@ -309,6 +319,9 @@ For full documentation. please see commentary. ;; force this immediately -- one off cost (unless (use-package-plist-get args :disabled) + (when archive-name + (use-package-pin-package name archive-name)) + (let* ((ensure (use-package-plist-get args :ensure)) (package-name (or (and (eq ensure t) From 435d4b407859f4f82b19662f57ceb7f72b567437 Mon Sep 17 00:00:00 2001 From: Peter Hoeg Date: Wed, 17 Dec 2014 05:45:53 +0800 Subject: [PATCH 07/14] pure cleanup --- lisp/use-package/use-package.el | 64 ++++++++++++++++----------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/lisp/use-package/use-package.el b/lisp/use-package/use-package.el index 570044970ea..83b5bd3f08d 100644 --- a/lisp/use-package/use-package.el +++ b/lisp/use-package/use-package.el @@ -113,10 +113,10 @@ Return nil when the queue is empty." (forms (gethash priority use-package-idle-forms)) (first-form (car forms)) (forms-remaining (cdr forms))) - (if forms-remaining - (puthash priority forms-remaining use-package-idle-forms) - (remhash priority use-package-idle-forms)) - first-form)) + (if forms-remaining + (puthash priority forms-remaining use-package-idle-forms) + (remhash priority use-package-idle-forms)) + first-form)) (defun use-package-idle-eval() "Start to eval idle-commands from the idle queue." @@ -152,28 +152,28 @@ Return nil when the queue is empty." (defvar use-package-keywords '( - :bind - :bind* - :commands - :config - :defer - :defines - :demand - :diminish - :disabled - :ensure - :idle - :idle-priority - :if - :init - :interpreter - :load-path - :mode - :pin - :pre-init - :pre-load - :requires - ) + :bind + :bind* + :commands + :config + :defer + :defines + :demand + :diminish + :disabled + :ensure + :idle + :idle-priority + :if + :init + :interpreter + :load-path + :mode + :pin + :pre-init + :pre-load + :requires + ) "Keywords recognized by `use-package'.") (defun use-package-mplist-get (plist prop) @@ -239,11 +239,11 @@ are all non-keywords elements that follow it." "Error if any keyword given in ARGS is not recognized. Return the list of recognized keywords." (mapc - (function - (lambda (keyword) - (unless (memq keyword use-package-keywords) - (error "Unrecognized keyword: %s" keyword)))) - (use-package-mplist-keys args))) + (function + (lambda (keyword) + (unless (memq keyword use-package-keywords) + (error "Unrecognized keyword: %s" keyword)))) + (use-package-mplist-keys args))) (defmacro use-package (name &rest args) "Use a package with configuration options. @@ -391,7 +391,7 @@ For full documentation. please see commentary. (funcall init-for-commands #'(lambda (binding) `(bind-key* ,(car binding) - (quote ,(cdr binding)))) + (quote ,(cdr binding)))) overriding-keybindings-alist) (funcall init-for-commands From a2b23f8326d06690c8092ecc5e83ba2e4dd3c336 Mon Sep 17 00:00:00 2001 From: Nicolas Richard Date: Thu, 11 Dec 2014 08:42:53 +0100 Subject: [PATCH 08/14] Don't add autoload for existing commands --- 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 570044970ea..654ed8d02b0 100644 --- a/lisp/use-package/use-package.el +++ b/lisp/use-package/use-package.el @@ -434,8 +434,10 @@ For full documentation. please see commentary. (not (use-package-plist-get args :demand))) (let (form) (mapc #'(lambda (command) - (push `(autoload (function ,command) - ,name-string nil t) form)) + (push `(unless (fboundp (quote ,command)) + (autoload (function ,command) + ,name-string nil t)) + form)) commands) `(when ,(or predicate t) From b3bf1b2587dee759e46cdb5941bf0689d54530f2 Mon Sep 17 00:00:00 2001 From: Peter Hoeg Date: Thu, 18 Dec 2014 04:34:49 +0800 Subject: [PATCH 09/14] Check if package-archives are valid when pinning --- lisp/use-package/use-package.el | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/lisp/use-package/use-package.el b/lisp/use-package/use-package.el index 83b5bd3f08d..950d0bf0ec2 100644 --- a/lisp/use-package/use-package.el +++ b/lisp/use-package/use-package.el @@ -142,9 +142,25 @@ Return nil when the queue is empty." (defun use-package-pin-package (package archive) "Pin PACKAGE to ARCHIVE." (unless (boundp 'package-pinned-packages) - (setq package-pinned-packages '())) - (add-to-list 'package-pinned-packages (cons package archive)) - (package-initialize t)) + (setq package-pinned-packages ())) + (let ((archive-symbol (if (symbolp archive) archive (intern archive))) + (archive-name (if (stringp archive) archive (symbol-name archive)))) + (if (use-package--archive-exists-p archive-symbol) + (add-to-list 'package-pinned-packages (cons package archive-name)) + (error (message "Archive '%s' requested for package '%s' is not available." archive-name package))) + (package-initialize t))) + +(defun use-package--archive-exists-p (archive) + "Check if a given ARCHIVE is enabled. + +ARCHIVE can be a string or a symbol or 'manual to indicate a manually updated package." + (if (member archive '(manual "manual")) + 't + (let ((valid nil)) + (dolist (pa package-archives) + (when (member archive (list (car pa) (intern (car pa)))) + (setq valid 't))) + valid))) (defun use-package-ensure-elpa (package) (when (not (package-installed-p package)) From 5a5aeca79736410462743f28d84dccde789efae3 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Fri, 19 Dec 2014 23:12:47 -0500 Subject: [PATCH 10/14] Do not quote lambda expressions http://emacs.stackexchange.com/a/3596 Quoting lambda expressions is at best redundant and at worst detrimental; this commit removes all use of the sharp-quote to reduce confusion. --- lisp/use-package/bind-key.el | 4 +-- lisp/use-package/use-package.el | 50 ++++++++++++++++----------------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/lisp/use-package/bind-key.el b/lisp/use-package/bind-key.el index e5f990ef0f2..2ac32365ecf 100644 --- a/lisp/use-package/bind-key.el +++ b/lisp/use-package/bind-key.el @@ -285,8 +285,8 @@ function symbol (unquoted)." (dolist (binding (setq personal-keybindings (sort personal-keybindings - #'(lambda (l r) - (car (compare-keybindings l r)))))) + (lambda (l r) + (car (compare-keybindings l r)))))) (if (not (eq (cdar last-binding) (cdar binding))) (princ (format "\n\n%s\n%s\n\n" diff --git a/lisp/use-package/use-package.el b/lisp/use-package/use-package.el index 57a80824fcc..3c0a7033af0 100644 --- a/lisp/use-package/use-package.el +++ b/lisp/use-package/use-package.el @@ -393,43 +393,43 @@ For full documentation. please see commentary. (setq init-body `(progn ,init-body - ,@(mapcar #'(lambda (elem) - (push (cdr elem) commands) - (funcall func elem)) + ,@(mapcar (lambda (elem) + (push (cdr elem) commands) + (funcall func elem)) cons-list)))))))) (funcall init-for-commands - #'(lambda (binding) - `(bind-key ,(car binding) - (quote ,(cdr binding)))) + (lambda (binding) + `(bind-key ,(car binding) + (quote ,(cdr binding)))) keybindings-alist) (funcall init-for-commands - #'(lambda (binding) - `(bind-key* ,(car binding) - (quote ,(cdr binding)))) + (lambda (binding) + `(bind-key* ,(car binding) + (quote ,(cdr binding)))) overriding-keybindings-alist) (funcall init-for-commands - #'(lambda (mode) - `(add-to-list 'auto-mode-alist - (quote ,mode))) + (lambda (mode) + `(add-to-list 'auto-mode-alist + (quote ,mode))) mode-alist) (funcall init-for-commands - #'(lambda (interpreter) - `(add-to-list 'interpreter-mode-alist - (quote ,interpreter))) + (lambda (interpreter) + `(add-to-list 'interpreter-mode-alist + (quote ,interpreter))) interpreter-alist)) `(progn ,pre-load-body ,@(mapcar - #'(lambda (path) - `(add-to-list 'load-path - ,(if (file-name-absolute-p path) - path - (expand-file-name path user-emacs-directory)))) + (lambda (path) + `(add-to-list 'load-path + ,(if (file-name-absolute-p path) + path + (expand-file-name path user-emacs-directory)))) (cond ((stringp pkg-load-path) (list pkg-load-path)) ((functionp pkg-load-path) @@ -449,11 +449,11 @@ For full documentation. please see commentary. ,(if (and (or commands (use-package-plist-get args :defer)) (not (use-package-plist-get args :demand))) (let (form) - (mapc #'(lambda (command) - (push `(unless (fboundp (quote ,command)) - (autoload (function ,command) - ,name-string nil t)) - form)) + (mapc (lambda (command) + (push `(unless (fboundp (quote ,command)) + (autoload (function ,command) + ,name-string nil t)) + form)) commands) `(when ,(or predicate t) From 1ae22368542380e51fa97066f454e72f0bdaa1fd Mon Sep 17 00:00:00 2001 From: Russell Black Date: Wed, 31 Dec 2014 17:02:25 -0700 Subject: [PATCH 11/14] :bind-keymap - bind a key prefix to an autoloaded package keymap --- lisp/use-package/use-package.el | 73 +++++++++++++++++++++++++++++---- 1 file changed, 64 insertions(+), 9 deletions(-) diff --git a/lisp/use-package/use-package.el b/lisp/use-package/use-package.el index 3c0a7033af0..ee7a5c41228 100644 --- a/lisp/use-package/use-package.el +++ b/lisp/use-package/use-package.el @@ -189,6 +189,8 @@ ARCHIVE can be a string or a symbol or 'manual to indicate a manually updated pa :pre-init :pre-load :requires + :bind-keymap + :bind-keymap* ) "Keywords recognized by `use-package'.") @@ -274,6 +276,10 @@ For full documentation. please see commentary. commands. :bind* Perform key bindings, and define autoload for bound commands, overriding all minor mode bindings. +:bind-keymap Bind key prefix to an auto-loaded keymap that + is defined in the package. Like bind but for keymaps + instead of commands. +:bind-keymap* like bind-keymap, but overrides all minor mode bindings :commands Define autoloads for given commands. :pre-load Code to run when `use-package' form evals and before anything else. Unlike :init this form runs before the @@ -308,6 +314,8 @@ For full documentation. please see commentary. (idle-priority (use-package-plist-get args :idle-priority)) (keybindings-alist (use-package-plist-get args :bind t t)) (overriding-keybindings-alist (use-package-plist-get args :bind* t t)) + (keymap-alist (use-package-plist-get args :bind-keymap t t)) + (overriding-keymap-alist (use-package-plist-get args :bind-keymap* t t)) (mode (use-package-plist-get args :mode t t)) (mode-alist (if (stringp mode) (cons mode name) mode)) @@ -382,9 +390,8 @@ For full documentation. please see commentary. (use-package-init-on-idle (lambda () ,idle-body) ,idle-priority) ,init-body))) - - (let ((init-for-commands - (lambda (func sym-or-list) + (let ((init-for-commands-or-keymaps + (lambda (func sym-or-list &optional keymap) (let ((cons-list (if (and (consp sym-or-list) (stringp (car sym-or-list))) (list sym-or-list) @@ -394,29 +401,50 @@ For full documentation. please see commentary. `(progn ,init-body ,@(mapcar (lambda (elem) - (push (cdr elem) commands) + (when (not keymap) + (push (cdr elem) commands)) (funcall func elem)) cons-list)))))))) - (funcall init-for-commands + (funcall init-for-commands-or-keymaps + (lambda (binding) + `(bind-key ,(car binding) + (lambda () (interactive) + (use-package-autoload-keymap + (quote ,(cdr binding)) + ,(if (stringp name) name `',name) + nil)))) + keymap-alist) + + (funcall init-for-commands-or-keymaps + (lambda (binding) + `(bind-key ,(car binding) + (lambda () (interactive) + (use-package-autoload-keymap + (quote ,(cdr binding)) + ,(if (stringp name) name `',name) + t)))) + overriding-keymap-alist) + + (funcall init-for-commands-or-keymaps (lambda (binding) `(bind-key ,(car binding) (quote ,(cdr binding)))) keybindings-alist) - (funcall init-for-commands + (funcall init-for-commands-or-keymaps (lambda (binding) `(bind-key* ,(car binding) (quote ,(cdr binding)))) overriding-keybindings-alist) - (funcall init-for-commands + (funcall init-for-commands-or-keymaps (lambda (mode) `(add-to-list 'auto-mode-alist (quote ,mode))) mode-alist) - (funcall init-for-commands + (funcall init-for-commands-or-keymaps (lambda (interpreter) `(add-to-list 'interpreter-mode-alist (quote ,interpreter))) @@ -446,7 +474,9 @@ For full documentation. please see commentary. `(require ',name nil t)) (error (message "Error requiring %s: %s" ',name err) nil)))) - ,(if (and (or commands (use-package-plist-get args :defer)) + ,(if (and (or commands (use-package-plist-get args :defer) + (use-package-plist-get args :bind-keymap) + (use-package-plist-get args :bind-keymap*)) (not (use-package-plist-get args :demand))) (let (form) (mapc (lambda (command) @@ -481,6 +511,31 @@ For full documentation. please see commentary. ,config-body t)))))))) +(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 same key sequence a again, so +that the next key pressed is routed to the newly loaded keymap. + +This function supports use-package's :bind-keymap keyword. It works +by binding the given key sequence to an invocation of this function for a +particular keymap. The keymap is expected to be defined by the package. In +this way, loading the package is deferred until the prefix key sequence is +pressed." + (if (if (stringp package) (load package t) (require package nil t)) + (if (and (boundp keymap-symbol) (keymapp (symbol-value keymap-symbol))) + (let ((key (key-description (this-command-keys-vector))) + (keymap (symbol-value keymap-symbol))) + (progn + (if override + `(eval `(bind-key* ,key ,keymap)) ; eval form is necessary to avoid compiler error + (bind-key key keymap)) + (setq unread-command-events + (listify-key-sequence (this-command-keys-vector))))) + (error + "use-package: package %s failed to define keymap %s" + package keymap-symbol)) + (error "Could not load package %s" package))) + (put 'use-package 'lisp-indent-function 'defun) (defconst use-package-font-lock-keywords From 7db9b920dfb8571b6a8a942dad6f70f471a7580b Mon Sep 17 00:00:00 2001 From: Thiago Barroso Perrotta Date: Fri, 2 Jan 2015 13:58:49 -0200 Subject: [PATCH 12/14] fix small typo (key > keymap) --- lisp/use-package/bind-key.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lisp/use-package/bind-key.el b/lisp/use-package/bind-key.el index 2ac32365ecf..fd143888d5d 100644 --- a/lisp/use-package/bind-key.el +++ b/lisp/use-package/bind-key.el @@ -41,7 +41,7 @@ ;; ;; (bind-key* "" 'other-window) ;; -;; If you want to rebind a key only in a particular key, use: +;; If you want to rebind a key only in a particular keymap, use: ;; ;; (bind-key "C-c x" 'my-ctrl-c-x-command some-other-mode-map) ;; From b8f0799ce8f404f1bd9182174970d43dd53b0db3 Mon Sep 17 00:00:00 2001 From: Russell Black Date: Sat, 3 Jan 2015 13:53:38 -0700 Subject: [PATCH 13/14] Passing t into keymap function --- 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 ee7a5c41228..7802e5a9549 100644 --- a/lisp/use-package/use-package.el +++ b/lisp/use-package/use-package.el @@ -414,7 +414,8 @@ For full documentation. please see commentary. (quote ,(cdr binding)) ,(if (stringp name) name `',name) nil)))) - keymap-alist) + keymap-alist + t) (funcall init-for-commands-or-keymaps (lambda (binding) @@ -424,7 +425,8 @@ For full documentation. please see commentary. (quote ,(cdr binding)) ,(if (stringp name) name `',name) t)))) - overriding-keymap-alist) + overriding-keymap-alist + t) (funcall init-for-commands-or-keymaps (lambda (binding) From 719115cf4778482f70c2b18613c0bc4e84d5259d Mon Sep 17 00:00:00 2001 From: Jonas Bernoulli Date: Sun, 18 Jan 2015 11:41:13 +0100 Subject: [PATCH 14/14] Allow using expanded macro without loading feature In the macro `use-package-with-elapased-timer' use `bound-and-true-p' go get the values of the customizable options `use-package-verbose' and `use-package-minimum-reported-time'. This way the library only has to be required at compile time, provided these options are not actually customized. If the user has changed the values, then she also has to load the library at runtime or the macros fall back to the default of doing their job silently. See https://github.com/jwiegley/use-package/issues/149. --- lisp/use-package/use-package.el | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/lisp/use-package/use-package.el b/lisp/use-package/use-package.el index 7802e5a9549..28d8587de00 100644 --- a/lisp/use-package/use-package.el +++ b/lisp/use-package/use-package.el @@ -48,12 +48,27 @@ :group 'startup) (defcustom use-package-verbose nil - "Whether to report about loading and configuration details." + "Whether to report about loading and configuration details. + +If you customize this, then you should require the `use-package' +feature in files that use one of the macros `use-package' or +`use-package-with-elapsed-timer', even if these files only +contain compiled expansions of the macros. If you don't do so, +then the expanded macros do their job silently." :type 'boolean :group 'use-package) (defcustom use-package-minimum-reported-time 0.01 - "Minimal load time that will be reported" + "Minimal load time that will be reported. + +Note that `use-package-verbose' has to be set to t, for anything +to be reported at all. + +If you customize this, then you should require the `use-package' +feature in files that use one of the macros `use-package' or +`use-package-with-elapsed-timer', even if these files only +contain compiled expansions of the macros. If you don't do so, +then the expanded macros do their job silently." :type 'number :group 'use-package) @@ -65,13 +80,15 @@ (defmacro use-package-with-elapsed-timer (text &rest body) (declare (indent 1)) (let ((nowvar (make-symbol "now"))) - `(if use-package-verbose + `(if (bound-and-true-p use-package-verbose) (let ((,nowvar (current-time))) (message "%s..." ,text) (prog1 (progn ,@body) (let ((elapsed (float-time (time-subtract (current-time) ,nowvar)))) - (if (> elapsed ,use-package-minimum-reported-time) + (if (> elapsed + (or (bound-and-true-p use-package-minimum-reported-time) + "0.01")) (message "%s...done (%.3fs)" ,text elapsed) (message "%s...done" ,text))))) ,@body)))