diff options
author | John Wiegley <johnw@newartisans.com> | 2022-11-15 15:28:53 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-15 15:28:53 -0800 |
commit | 7087a97a24fe0d9fba756369bfb23b28093f6e67 (patch) | |
tree | 1f7f09a99f93707a7d9e2d1ad7955febe8f13c05 /lisp/use-package | |
parent | f4ee1c3839a7cc5818198cd1031aee2bef15a7d6 (diff) | |
parent | 3e81af80a2fdf200395aea6bdf15dd897303956f (diff) | |
download | emacs-7087a97a24fe0d9fba756369bfb23b28093f6e67.tar.gz emacs-7087a97a24fe0d9fba756369bfb23b28093f6e67.tar.bz2 emacs-7087a97a24fe0d9fba756369bfb23b28093f6e67.zip |
Merge pull request from jwiegley/revert-1019-johnw/multi-keymap
GitHub-reference: https://github.com/jwiegley/use-package/issues/1021
Diffstat (limited to 'lisp/use-package')
-rw-r--r-- | lisp/use-package/bind-chord.el | 3 | ||||
-rw-r--r-- | lisp/use-package/bind-key.el | 109 | ||||
-rw-r--r-- | lisp/use-package/use-package-bind-key.el | 13 |
3 files changed, 54 insertions, 71 deletions
diff --git a/lisp/use-package/bind-chord.el b/lisp/use-package/bind-chord.el index d592736e227..bf0f5866ac4 100644 --- a/lisp/use-package/bind-chord.el +++ b/lisp/use-package/bind-chord.el @@ -92,8 +92,7 @@ function symbol (unquoted)." "Bind multiple chords at once. Accepts keyword argument: -:map - a keymap or list of keymaps into which the keybindings should be - added +: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)." diff --git a/lisp/use-package/bind-key.el b/lisp/use-package/bind-key.el index b02b7a4ad9f..f0b9cdb588d 100644 --- a/lisp/use-package/bind-key.el +++ b/lisp/use-package/bind-key.el @@ -248,12 +248,12 @@ In contrast to `define-key', this function removes the binding from the keymap." "Similar to `bind-key', but overrides any mode-specific bindings." `(bind-key ,key-name ,command override-global-map ,predicate)) -(defun bind-keys-form (args &rest keymaps) +(defun bind-keys-form (args keymap) "Bind multiple keys at once. Accepts keyword arguments: :map MAP - a keymap into which the keybindings should be - added, or a list of such keymaps + added :prefix KEY - prefix key for these bindings :prefix-map MAP - name of the prefix map that should be created for these bindings @@ -276,7 +276,7 @@ Accepts keyword arguments: The rest of the arguments are conses of keybinding string and a function symbol (unquoted)." - (let (maps + (let (map prefix-doc prefix-map prefix @@ -293,17 +293,20 @@ function symbol (unquoted)." (while (and cont args) (if (cond ((and (eq :map (car args)) (not prefix-map)) - (let ((arg (cadr args))) - (setq maps (if (listp arg) arg (list arg))))) + (setq map (cadr args))) ((eq :prefix-docstring (car args)) (setq prefix-doc (cadr args))) - ((eq :prefix-map (car args)) + ((and (eq :prefix-map (car args)) + (not (memq map '(global-map + override-global-map)))) (setq prefix-map (cadr args))) ((eq :repeat-docstring (car args)) (setq repeat-doc (cadr args))) - ((eq :repeat-map (car args)) + ((and (eq :repeat-map (car args)) + (not (memq map '(global-map + override-global-map)))) (setq repeat-map (cadr args)) - (setq maps (list repeat-map))) + (setq map repeat-map)) ((eq :continue (car args)) (setq repeat-type :continue arg-change-func 'cdr)) @@ -332,8 +335,7 @@ function symbol (unquoted)." (when (and menu-name (not prefix)) (error "If :menu-name is supplied, :prefix must be too")) - (unless maps (setq maps keymaps)) - (unless maps (setq maps (list nil))) + (unless map (setq map keymap)) ;; Process key binding arguments (let (first next) @@ -347,67 +349,50 @@ function symbol (unquoted)." (setq first (list (car args)))) (setq args (cdr args)))) - (cl-labels - ((wrap (maps bindings) - (if (and pkg - (cl-every - (lambda (map) - (and map - (not (memq map '(global-map - override-global-map))))) - maps)) - `((if (mapcan 'boundp ',maps) + (cl-flet + ((wrap (map bindings) + (if (and map pkg (not (memq map '(global-map + override-global-map)))) + `((if (boundp ',map) ,(macroexp-progn bindings) (eval-after-load ,(if (symbolp pkg) `',pkg pkg) ',(macroexp-progn bindings)))) bindings))) + (append + (when prefix-map + `((defvar ,prefix-map) + ,@(when prefix-doc `((put ',prefix-map 'variable-documentation ,prefix-doc))) + ,@(if menu-name + `((define-prefix-command ',prefix-map nil ,menu-name)) + `((define-prefix-command ',prefix-map))) + ,@(if (and map (not (eq map 'global-map))) + (wrap map `((bind-key ,prefix ',prefix-map ,map ,filter))) + `((bind-key ,prefix ',prefix-map nil ,filter))))) (when repeat-map `((defvar ,repeat-map (make-sparse-keymap) ,@(when repeat-doc `(,repeat-doc))))) - (if prefix-map - `((defvar ,prefix-map) - ,@(when prefix-doc `((put ',prefix-map 'variable-documentation ,prefix-doc))) - ,@(if menu-name - `((define-prefix-command ',prefix-map nil ,menu-name)) - `((define-prefix-command ',prefix-map))) - ,@(cl-mapcan - (lambda (map) - (wrap (list map) - `((bind-key ,prefix ',prefix-map ,map ,filter)))) - maps) - ,@(wrap maps - (cl-mapcan - (lambda (form) - (let ((fun - (and (cdr form) (list 'function (cdr form))))) - `((bind-key ,(car form) ,fun ,prefix-map ,filter)))) - first))) - (cl-mapcan - (lambda (map) - (wrap (list map) - (cl-mapcan - (lambda (form) - (let ((fun (and (cdr form) (list 'function (cdr form))))) - (if (and map (not (eq map 'global-map))) - ;; Only needed in this branch, since when - ;; repeat-map is non-nil, map is always - ;; non-nil - `(,@(when (and repeat-map - (not (eq repeat-type :exit))) - `((put ,fun 'repeat-map ',repeat-map))) - (bind-key ,(car form) ,fun ,map ,filter)) - `((bind-key ,(car form) ,fun nil ,filter))))) - first))) - maps)) + (wrap map + (cl-mapcan + (lambda (form) + (let ((fun (and (cdr form) (list 'function (cdr form))))) + (if prefix-map + `((bind-key ,(car form) ,fun ,prefix-map ,filter)) + (if (and map (not (eq map 'global-map))) + ;; Only needed in this branch, since when + ;; repeat-map is non-nil, map is always + ;; non-nil + `(,@(when (and repeat-map (not (eq repeat-type :exit))) + `((put ,fun 'repeat-map ',repeat-map))) + (bind-key ,(car form) ,fun ,map ,filter)) + `((bind-key ,(car form) ,fun nil ,filter)))))) + first)) (when next - (apply 'bind-keys-form - `(,@(when repeat-map `(:repeat-map ,repeat-map)) - ,@(if pkg - (cons :package (cons pkg next)) - next)) - maps))))))) + (bind-keys-form `(,@(when repeat-map `(:repeat-map ,repeat-map)) + ,@(if pkg + (cons :package (cons pkg next)) + next)) map))))))) ;;;###autoload (defmacro bind-keys (&rest args) @@ -415,7 +400,7 @@ function symbol (unquoted)." Accepts keyword arguments: :map MAP - a keymap into which the keybindings should be - added, or a list of such keymaps + added :prefix KEY - prefix key for these bindings :prefix-map MAP - name of the prefix map that should be created for these bindings diff --git a/lisp/use-package/use-package-bind-key.el b/lisp/use-package/use-package-bind-key.el index 460d6255e93..5e6a10925ca 100644 --- a/lisp/use-package/use-package-bind-key.el +++ b/lisp/use-package/use-package-bind-key.el @@ -86,20 +86,19 @@ deferred until the prefix key sequence is pressed." ;; :prefix-docstring STRING ;; :prefix-map SYMBOL ;; :prefix STRING - ;; :repeat-docstring STRING + ;; :repeat-docstring STRING ;; :repeat-map SYMBOL ;; :filter SEXP ;; :menu-name STRING ;; :package SYMBOL - ;; :continue and :exit are used within :repeat-map - ((or (and (eq x :map) (or (symbolp (cadr arg)) - (listp (cadr arg)))) + ;; :continue and :exit are used within :repeat-map + ((or (and (eq x :map) (symbolp (cadr arg))) (and (eq x :prefix) (stringp (cadr arg))) (and (eq x :prefix-map) (symbolp (cadr arg))) (and (eq x :prefix-docstring) (stringp (cadr arg))) - (and (eq x :repeat-map) (symbolp (cadr arg))) - (eq x :continue) - (eq x :exit) + (and (eq x :repeat-map) (symbolp (cadr arg))) + (eq x :continue) + (eq x :exit) (and (eq x :repeat-docstring) (stringp (cadr arg))) (eq x :filter) (and (eq x :menu-name) (stringp (cadr arg))) |