help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Attach a map to another


From: Ergus
Subject: Attach a map to another
Date: Sat, 19 Feb 2022 14:07:37 +0100

Hi:

Recently I was making a minor-mode that apart from other stuff attach
some bindings to isearch-mode-map. I know that it is possible to add a
parent keymap and some inheritance.. and in the opposite direction I see
that it is possible to add bindings or prefix maps to another... But I
am not clear from the documentation if it is possible to add a keymap to
another without a prefix (with something like keymap-set or similar).

I think that having a keymap entry in another one makes the trick
according to the documentation:
(keymap
 (keymap
    (26 . extra-functions))
 (24 . normal-functions))

but I am wondering if there is an api to do that more conveniently?? At
we don't add bindings to keymaps with push so I don't expect to do so
with keymaps.

The idea is that in the mode it will be easier to do something like:

```
(defvar-keymap my-mode-isearch-map
    ...)

(define-minor-mode my-mode
   :keymap 'my-mode-keymap
   (if my-mode
       (keymap-set isearch-mode-map <something> my-mode-isearch-map)
     (keymap-unset isearch-mode-map <something>)))
```

Otherwise the isearch-mode-map keeps modified even after disabling the
mode.

I see that some packages around deal with this manually coping the
bindings, saving the previous map and replacing with an inherited one
iteratively and so on... but maybe there is something already there to
not reinvent the wheel?? And potentially more efficient??


reply via email to

[Prev in Thread] Current Thread [Next in Thread]