diff options
| author | Hugo Heagren | 2022-01-17 15:41:35 +0000 |
|---|---|---|
| committer | Hugo Heagren | 2022-01-28 22:37:37 +0000 |
| commit | 5ef327ce9fc1397cdbbde8936eca37ae6383d787 (patch) | |
| tree | da97916967981cb594990ec69ad0d8f7ccc7ba81 | |
| parent | 2203246454fddd41e0a62e78b17befce561998b9 (diff) | |
| download | emacs-5ef327ce9fc1397cdbbde8936eca37ae6383d787.tar.gz emacs-5ef327ce9fc1397cdbbde8936eca37ae6383d787.zip | |
bind-key-form: allow :exit keyword inside repeat map
Keys bound inside the scope of :exit are bound inside the repeat map,
but do not have their repeat-map property set (so they run a function,
but 'exit' the map).
| -rw-r--r-- | lisp/use-package/bind-key.el | 18 | ||||
| -rw-r--r-- | lisp/use-package/use-package-bind-key.el | 2 |
2 files changed, 17 insertions, 3 deletions
diff --git a/lisp/use-package/bind-key.el b/lisp/use-package/bind-key.el index bb09a6935a8..a899aca0ffc 100644 --- a/lisp/use-package/bind-key.el +++ b/lisp/use-package/bind-key.el | |||
| @@ -263,6 +263,9 @@ Accepts keyword arguments: | |||
| 263 | 'repeat-map property of each command bound | 263 | 'repeat-map property of each command bound |
| 264 | (within the scope of the :repeat-map keyword) | 264 | (within the scope of the :repeat-map keyword) |
| 265 | is set to this map. | 265 | is set to this map. |
| 266 | :exit BINDINGS - Within the scope of :repeat-map will bind the | ||
| 267 | key in the repeat map, but will not set the | ||
| 268 | 'repeat-map property of the bound command. | ||
| 266 | :filter FORM - optional form to determine when bindings apply | 269 | :filter FORM - optional form to determine when bindings apply |
| 267 | 270 | ||
| 268 | The rest of the arguments are conses of keybinding string and a | 271 | The rest of the arguments are conses of keybinding string and a |
| @@ -273,12 +276,14 @@ function symbol (unquoted)." | |||
| 273 | prefix | 276 | prefix |
| 274 | repeat-map | 277 | repeat-map |
| 275 | repeat-doc | 278 | repeat-doc |
| 279 | repeat-type ;; Only used internally | ||
| 276 | filter | 280 | filter |
| 277 | menu-name | 281 | menu-name |
| 278 | pkg) | 282 | pkg) |
| 279 | 283 | ||
| 280 | ;; Process any initial keyword arguments | 284 | ;; Process any initial keyword arguments |
| 281 | (let ((cont t)) | 285 | (let ((cont t) |
| 286 | (arg-change-func 'cddr)) | ||
| 282 | (while (and cont args) | 287 | (while (and cont args) |
| 283 | (if (cond ((and (eq :map (car args)) | 288 | (if (cond ((and (eq :map (car args)) |
| 284 | (not prefix-map)) | 289 | (not prefix-map)) |
| @@ -296,6 +301,9 @@ function symbol (unquoted)." | |||
| 296 | override-global-map)))) | 301 | override-global-map)))) |
| 297 | (setq repeat-map (cadr args)) | 302 | (setq repeat-map (cadr args)) |
| 298 | (setq map repeat-map)) | 303 | (setq map repeat-map)) |
| 304 | ((eq :exit (car args)) | ||
| 305 | (setq repeat-type :exit | ||
| 306 | arg-change-func 'cdr)) | ||
| 299 | ((eq :prefix (car args)) | 307 | ((eq :prefix (car args)) |
| 300 | (setq prefix (cadr args))) | 308 | (setq prefix (cadr args))) |
| 301 | ((eq :filter (car args)) | 309 | ((eq :filter (car args)) |
| @@ -304,7 +312,7 @@ function symbol (unquoted)." | |||
| 304 | (setq menu-name (cadr args))) | 312 | (setq menu-name (cadr args))) |
| 305 | ((eq :package (car args)) | 313 | ((eq :package (car args)) |
| 306 | (setq pkg (cadr args)))) | 314 | (setq pkg (cadr args)))) |
| 307 | (setq args (cddr args)) | 315 | (setq args (funcall arg-change-func args)) |
| 308 | (setq cont nil)))) | 316 | (setq cont nil)))) |
| 309 | 317 | ||
| 310 | (when (or (and prefix-map (not prefix)) | 318 | (when (or (and prefix-map (not prefix)) |
| @@ -362,7 +370,8 @@ function symbol (unquoted)." | |||
| 362 | ;; Only needed in this branch, since when | 370 | ;; Only needed in this branch, since when |
| 363 | ;; repeat-map is non-nil, map is always | 371 | ;; repeat-map is non-nil, map is always |
| 364 | ;; non-nil | 372 | ;; non-nil |
| 365 | `(,@(when repeat-map `((put ,fun 'repeat-map ',repeat-map))) | 373 | `(,@(when (and repeat-map (not (eq repeat-type :exit))) |
| 374 | `((put ,fun 'repeat-map ',repeat-map))) | ||
| 366 | (bind-key ,(car form) ,fun ,map ,filter)) | 375 | (bind-key ,(car form) ,fun ,map ,filter)) |
| 367 | `((bind-key ,(car form) ,fun nil ,filter)))))) | 376 | `((bind-key ,(car form) ,fun nil ,filter)))))) |
| 368 | first)) | 377 | first)) |
| @@ -389,6 +398,9 @@ Accepts keyword arguments: | |||
| 389 | 'repeat-map property of each command bound | 398 | 'repeat-map property of each command bound |
| 390 | (within the scope of the :repeat-map keyword) | 399 | (within the scope of the :repeat-map keyword) |
| 391 | is set to this map. | 400 | is set to this map. |
| 401 | :exit BINDINGS - Within the scope of :repeat-map will bind the | ||
| 402 | key in the repeat map, but will not set the | ||
| 403 | 'repeat-map property of the bound command. | ||
| 392 | :filter FORM - optional form to determine when bindings apply | 404 | :filter FORM - optional form to determine when bindings apply |
| 393 | 405 | ||
| 394 | The rest of the arguments are conses of keybinding string and a | 406 | The rest of the arguments are conses of keybinding string and a |
diff --git a/lisp/use-package/use-package-bind-key.el b/lisp/use-package/use-package-bind-key.el index d056d4266cc..73ea8ca83e0 100644 --- a/lisp/use-package/use-package-bind-key.el +++ b/lisp/use-package/use-package-bind-key.el | |||
| @@ -91,11 +91,13 @@ deferred until the prefix key sequence is pressed." | |||
| 91 | ;; :filter SEXP | 91 | ;; :filter SEXP |
| 92 | ;; :menu-name STRING | 92 | ;; :menu-name STRING |
| 93 | ;; :package SYMBOL | 93 | ;; :package SYMBOL |
| 94 | ;; :exit used within :repeat-map | ||
| 94 | ((or (and (eq x :map) (symbolp (cadr arg))) | 95 | ((or (and (eq x :map) (symbolp (cadr arg))) |
| 95 | (and (eq x :prefix) (stringp (cadr arg))) | 96 | (and (eq x :prefix) (stringp (cadr arg))) |
| 96 | (and (eq x :prefix-map) (symbolp (cadr arg))) | 97 | (and (eq x :prefix-map) (symbolp (cadr arg))) |
| 97 | (and (eq x :prefix-docstring) (stringp (cadr arg))) | 98 | (and (eq x :prefix-docstring) (stringp (cadr arg))) |
| 98 | (and (eq x :repeat-map) (symbolp (cadr arg))) | 99 | (and (eq x :repeat-map) (symbolp (cadr arg))) |
| 100 | (eq x :exit) | ||
| 99 | (and (eq x :repeat-docstring) (stringp (cadr arg))) | 101 | (and (eq x :repeat-docstring) (stringp (cadr arg))) |
| 100 | (eq x :filter) | 102 | (eq x :filter) |
| 101 | (and (eq x :menu-name) (stringp (cadr arg))) | 103 | (and (eq x :menu-name) (stringp (cadr arg))) |