diff options
author | Justin Talbott <justin@waymondo.com> | 2016-01-08 14:35:17 -0500 |
---|---|---|
committer | Justin Talbott <justin@waymondo.com> | 2016-01-08 14:35:17 -0500 |
commit | cd867dfe2f21aa1397016d7c441a3d6c90f36672 (patch) | |
tree | 9acc0a9fc22384acb6182d3856141828a52b0dc1 /lisp/use-package | |
parent | 95038f96f1e715022a5ca5ffbb12fc9a4fa8a252 (diff) | |
download | emacs-cd867dfe2f21aa1397016d7c441a3d6c90f36672.tar.gz emacs-cd867dfe2f21aa1397016d7c441a3d6c90f36672.tar.bz2 emacs-cd867dfe2f21aa1397016d7c441a3d6c90f36672.zip |
allow string values in cons for :bind keywords
It is possible with `bind-key` and `define-key` (and also `bind-chord`
and `key-chord-define`) to define a binding to a string's value, i.e:
``` elisp
(bind-key "C-;" "the ")
(bind-chord "^^" "λ")
```
This adds an option for `(use-package-normalize-pairs)` that allows
string values to be given with the `:bind` (and also `:chord`) keywords
to expand into these definitions.
Diffstat (limited to 'lisp/use-package')
-rw-r--r-- | lisp/use-package/use-package.el | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/lisp/use-package/use-package.el b/lisp/use-package/use-package.el index fecd37bc121..36a2540f7e0 100644 --- a/lisp/use-package/use-package.el +++ b/lisp/use-package/use-package.el @@ -644,8 +644,14 @@ manually updated package." (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)))) + (defun use-package-normalize-pairs - (name label arg &optional recursed allow-vector) + (name label arg &optional recursed allow-vector allow-string-cdrs) "Normalize a list of string/symbol pairs." (cond ((or (stringp arg) (and allow-vector (vectorp arg))) @@ -655,16 +661,18 @@ manually updated package." ((and (not recursed) (listp arg) (listp (cdr arg))) (mapcar #'(lambda (x) (let ((ret (use-package-normalize-pairs - name label x t allow-vector))) + name label x t allow-vector allow-string-cdrs))) (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)))) + (use-package-normalize-pairs name label arg nil t t)))) (defalias 'use-package-normalize/:bind 'use-package-normalize-binder) (defalias 'use-package-normalize/:bind* 'use-package-normalize-binder) @@ -850,12 +858,13 @@ deferred until the prefix key sequence is pressed." (apply #'nconc (mapcar #'(lambda (command) - (append - `((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)))))) + (when (not (stringp command)) + (append + `((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 (plist-get state :commands)))) body))) |