unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Ergus <spacibba@aol.com>
To: help-gnu-emacs@gnu.org
Subject: Attach a map to another
Date: Sat, 19 Feb 2022 14:07:37 +0100	[thread overview]
Message-ID: <20220219130737.esdd2kou35avl75e@Ergus> (raw)
In-Reply-To: 20220219130737.esdd2kou35avl75e.ref@Ergus

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	other threads:[~2022-02-19 13:07 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20220219130737.esdd2kou35avl75e.ref@Ergus>
2022-02-19 13:07 ` Ergus [this message]
2022-02-19 18:29   ` Attach a map to another Stefan Monnier via Users list for the GNU Emacs text editor
2022-02-19 19:24     ` Stefan Monnier via Users list for the GNU Emacs text editor
2022-02-20 11:10       ` Ergus via Users list for the GNU Emacs text editor
2022-02-20 14:54         ` Stefan Monnier
2022-02-20 11:07     ` Ergus
2022-02-20 14:52       ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220219130737.esdd2kou35avl75e@Ergus \
    --to=spacibba@aol.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).