mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-16 10:50:49 -08:00
Remove :bind-keymaps, and only apply :map bindings after load
This commit is contained in:
parent
856e8ee245
commit
828563a756
2 changed files with 43 additions and 88 deletions
|
|
@ -212,6 +212,7 @@ function symbol (unquoted)."
|
||||||
(prefix (plist-get args :prefix))
|
(prefix (plist-get args :prefix))
|
||||||
(filter (plist-get args :filter))
|
(filter (plist-get args :filter))
|
||||||
(menu-name (plist-get args :menu-name))
|
(menu-name (plist-get args :menu-name))
|
||||||
|
(pkg (plist-get args :package))
|
||||||
(key-bindings (progn
|
(key-bindings (progn
|
||||||
(while (keywordp (car args))
|
(while (keywordp (car args))
|
||||||
(pop args)
|
(pop args)
|
||||||
|
|
@ -233,30 +234,43 @@ function symbol (unquoted)."
|
||||||
(nconc first (list (car args)))
|
(nconc first (list (car args)))
|
||||||
(setq first (list (car args))))
|
(setq first (list (car args))))
|
||||||
(setq args (cdr args))))
|
(setq args (cdr args))))
|
||||||
(append
|
(cl-flet ((wrap (maps bindings)
|
||||||
(when prefix-map
|
(if (and maps pkg)
|
||||||
`((defvar ,prefix-map)
|
`((eval-after-load
|
||||||
,@(when doc `((put ',prefix-map 'variable-documentation ,doc)))
|
,(if (symbolp pkg) `',pkg pkg)
|
||||||
,@(if menu-name
|
'(progn ,@bindings)))
|
||||||
`((define-prefix-command ',prefix-map nil ,menu-name))
|
bindings)))
|
||||||
`((define-prefix-command ',prefix-map)))
|
(append
|
||||||
,@(if maps
|
(when prefix-map
|
||||||
(mapcar
|
`((defvar ,prefix-map)
|
||||||
#'(lambda (m)
|
,@(when doc `((put ',prefix-map 'variable-documentation ,doc)))
|
||||||
`(bind-key ,prefix ',prefix-map ,m ,filter)) maps)
|
,@(if menu-name
|
||||||
`((bind-key ,prefix ',prefix-map nil ,filter)))))
|
`((define-prefix-command ',prefix-map nil ,menu-name))
|
||||||
(cl-mapcan
|
`((define-prefix-command ',prefix-map)))
|
||||||
(lambda (form)
|
,@(if maps
|
||||||
(if prefix-map
|
(wrap maps
|
||||||
`((bind-key ,(car form) ',(cdr form) ,prefix-map ,filter))
|
(mapcar
|
||||||
(if maps
|
#'(lambda (m)
|
||||||
(mapcar
|
`(bind-key ,prefix ',prefix-map ,m ,filter))
|
||||||
#'(lambda (m)
|
maps))
|
||||||
`(bind-key ,(car form) ',(cdr form) ,m ,filter)) maps)
|
`((bind-key ,prefix ',prefix-map nil ,filter)))))
|
||||||
`((bind-key ,(car form) ',(cdr form) nil ,filter)))))
|
(wrap maps
|
||||||
first)
|
(cl-mapcan
|
||||||
(when next
|
(lambda (form)
|
||||||
(bind-keys-form next))))))
|
(if prefix-map
|
||||||
|
`((bind-key ,(car form) ',(cdr form) ,prefix-map ,filter))
|
||||||
|
(if maps
|
||||||
|
(mapcar
|
||||||
|
#'(lambda (m)
|
||||||
|
`(bind-key ,(car form) ',(cdr form) ,m ,filter))
|
||||||
|
maps)
|
||||||
|
`((bind-key ,(car form) ',(cdr form) nil ,filter)))))
|
||||||
|
first))
|
||||||
|
(when next
|
||||||
|
(bind-keys-form
|
||||||
|
(if pkg
|
||||||
|
(cons :package (cons pkg next))
|
||||||
|
next))))))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defmacro bind-keys (&rest args)
|
(defmacro bind-keys (&rest args)
|
||||||
|
|
|
||||||
|
|
@ -123,8 +123,6 @@ the user specified."
|
||||||
:no-require
|
:no-require
|
||||||
:bind
|
:bind
|
||||||
:bind*
|
:bind*
|
||||||
:bind-keymap
|
|
||||||
:bind-keymap*
|
|
||||||
:interpreter
|
:interpreter
|
||||||
:mode
|
:mode
|
||||||
:commands
|
:commands
|
||||||
|
|
@ -175,7 +173,9 @@ convert it to a string and return that."
|
||||||
(defun use-package-load-name (name &optional noerror)
|
(defun use-package-load-name (name &optional noerror)
|
||||||
"Return a form which will load or require NAME depending on
|
"Return a form which will load or require NAME depending on
|
||||||
whether it's a string or symbol."
|
whether it's a string or symbol."
|
||||||
(if (stringp name) `(load ,name 'noerror) `(require ',name nil 'noerror)))
|
(if (stringp name)
|
||||||
|
`(load ,name 'noerror)
|
||||||
|
`(require ',name nil 'noerror)))
|
||||||
|
|
||||||
(defun use-package-expand (name label form)
|
(defun use-package-expand (name label form)
|
||||||
"FORM is a list of forms, so `((foo))' if only `foo' is being called."
|
"FORM is a list of forms, so `((foo))' if only `foo' is being called."
|
||||||
|
|
@ -700,68 +700,12 @@ may also be a string, as accepted by `define-key'."
|
||||||
(use-package-plist-append state :commands commands))
|
(use-package-plist-append state :commands commands))
|
||||||
`((ignore
|
`((ignore
|
||||||
,(macroexpand
|
,(macroexpand
|
||||||
`(,(if bind-macro bind-macro 'bind-keys) ,@arg)))))))
|
`(,(if bind-macro bind-macro 'bind-keys)
|
||||||
|
:package ,name ,@arg)))))))
|
||||||
|
|
||||||
(defun use-package-handler/:bind* (name keyword arg rest state)
|
(defun use-package-handler/:bind* (name keyword arg rest state)
|
||||||
(use-package-handler/:bind name keyword arg rest state 'bind-keys*))
|
(use-package-handler/:bind name keyword arg rest state 'bind-keys*))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
||||||
;;
|
|
||||||
;; :bind-keymap, :bind-keymap*
|
|
||||||
;;
|
|
||||||
|
|
||||||
(defalias 'use-package-normalize/:bind-keymap 'use-package-normalize-binder)
|
|
||||||
(defalias 'use-package-normalize/:bind-keymap* 'use-package-normalize-binder)
|
|
||||||
|
|
||||||
(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 (not (require package nil t))
|
|
||||||
(use-package-error (format "Could not load package.el: %s" package))
|
|
||||||
(if (and (boundp keymap-symbol)
|
|
||||||
(keymapp (symbol-value keymap-symbol)))
|
|
||||||
(let* ((kv (this-command-keys-vector))
|
|
||||||
(key (key-description kv))
|
|
||||||
(keymap (symbol-value keymap-symbol)))
|
|
||||||
(if override
|
|
||||||
(bind-key* key keymap)
|
|
||||||
(bind-key key keymap))
|
|
||||||
(setq unread-command-events
|
|
||||||
(listify-key-sequence kv)))
|
|
||||||
(use-package-error
|
|
||||||
(format "use-package: package.el %s failed to define keymap %s"
|
|
||||||
package keymap-symbol)))))
|
|
||||||
|
|
||||||
(defun use-package-handler/:bind-keymap
|
|
||||||
(name keyword arg rest state &optional override)
|
|
||||||
(let ((form (mapcar
|
|
||||||
#'(lambda (binding)
|
|
||||||
`(,(if override
|
|
||||||
'bind-key*
|
|
||||||
'bind-key)
|
|
||||||
,(car binding)
|
|
||||||
#'(lambda ()
|
|
||||||
(interactive)
|
|
||||||
(use-package-autoload-keymap
|
|
||||||
',(cdr binding) ',(use-package-as-symbol name) ,override)))) arg)))
|
|
||||||
(use-package-concat
|
|
||||||
(use-package-process-keywords name
|
|
||||||
(use-package-sort-keywords
|
|
||||||
(use-package-plist-maybe-put rest :defer t))
|
|
||||||
state)
|
|
||||||
`((ignore ,@form)))))
|
|
||||||
|
|
||||||
(defun use-package-handler/:bind-keymap* (name keyword arg rest state)
|
|
||||||
(use-package-handler/:bind-keymap name keyword arg rest state t))
|
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;;
|
;;
|
||||||
;; :interpreter
|
;; :interpreter
|
||||||
|
|
@ -1066,9 +1010,6 @@ this file. Usage:
|
||||||
:bind Bind keys, and define autoloads for the bound commands.
|
:bind Bind keys, and define autoloads for the bound commands.
|
||||||
:bind* Bind keys, and define autoloads for the bound commands,
|
:bind* Bind keys, and define autoloads for the bound commands,
|
||||||
*overriding all minor mode bindings*.
|
*overriding all minor mode bindings*.
|
||||||
:bind-keymap Bind a key prefix to an auto-loaded keymap defined in the
|
|
||||||
package. This is like `:bind', but for keymaps.
|
|
||||||
:bind-keymap* Like `:bind-keymap', but overrides all minor mode bindings
|
|
||||||
|
|
||||||
:defer Defer loading of a package -- this is implied when using
|
:defer Defer loading of a package -- this is implied when using
|
||||||
`:commands', `:bind', `:bind*', `:mode' or `:interpreter'.
|
`:commands', `:bind', `:bind*', `:mode' or `:interpreter'.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue