From: storm@cua.dk (Kim F. Storm)
Cc: emacs-devel@gnu.org
Subject: Re: Enhancements to "minor-mode-map-alist" functionality.
Date: 12 Apr 2002 15:20:17 +0200 [thread overview]
Message-ID: <5x4rih12b2.fsf@kfs2.cua.dk> (raw)
In-Reply-To: <5xd6x5i7ps.fsf@kfs2.cua.dk>
I have been thinking more about this and I've now got a more generic
solution (I think) which has a lot of potential:
Nested, Conditioned Keymaps.
The idea is as follows:
1) A keymap may be conditioned with
(keymap :filter FORM ...)
We already discussed that, and although some precautions are needed
to handle this, it should be fairly trivial to implement.
2) A keymap may be nested with
(keymap ... (keymap ...) ... (keymap ...) ...)
The idea is that when we scan through a keymap (searching for a binding),
if we encounter a nested keymap, we will [recursively] scan that
keymap before continuing through the original keymap.
Now, if we combine those two ideas, I can write a "single" cua-mode
master keymap which contains all of the conditioned sub-keymaps I need,
i.e. something like this [I know this isn't the proper way to create
a keymap, but it illustrates the point I'm making]:
(setq cua-mode-map
(keymap :filter cua-mode
(keymap :filter (and mark-active
cua-enable-cua-keys
(or (eq cua-enable-cua-keys t)
(not cua--explicit-region-start))
(not executing-kbd-macro)
(not cua--prefix-override-timer))
,cua--prefix-override-keymap)
(keymap :filter (and mark-active
(timerp cua--prefix-override-timer))
,cua--prefix-repeat-keymap)
(keymap :filter (or (eq cua-enable-cua-keys t)
cua--last-region-shifted)
,cua--cua-keys-keymap)
(keymap :filter (and cua--global-mark-active
(not (window-minibuffer-p)))
,cua--global-mark-keymap)
(keymap :filter cua--rectangle ,cua--rectangle-keymap)
(keymap :filter mark-active ,cua--region-keymap)
,cua-global-keymap))
(add-to-list 'minor-mode-map-alist `(cua-mode . ,cua-mode-map))
So doing this would remove the need for the emulation-mode-map-alists
(which you dislike :-) as well
I can easily ensure that cua-mode-map stays at the beginning of
minor-mode-map-alist [will be simple in a post-command hook, or maybe
by adding it to minor-mode-overriding-map-alist :-) ]
Some functions may be needed to manage this, e.g.
(add-keymap keymap nested &optional after)
-> inserts NESTED at the beginning of KEYMAP,
or after optional AFTER keymap (or last if AFTER is t)
Returns NESTED.
(remove-keymap keymap nested)
-> removes NESTED from the KEYMAP.
(set-keymap-filter keymap filter &optional new)
-> sets the :filter property on KEYMAP to FILTER,
removes the :filter property if FILTER is nil.
If NEW is non-nil, create a new keymap and use KEYMAP as a nested
of that keymap, and apply the FILTER on the new keymap.
This means that we can apply a filter to an existing keymap without
adding a filter to that keymap.
-> returns KEYMAP if NEW is nil,
or the new keymap if NEW is non-nil.
(get-keymap-filter keymap)
-> returns the :filter property on KEYMAP
This can also be used instead of minor-mode-overriding-map-alist:
>From diff-mode.el:
;; Neat trick from Dave Love to add more bindings in read-only mode:
(add-to-list (make-local-variable 'minor-mode-overriding-map-alist)
(cons 'buffer-read-only diff-mode-shared-map))
could be replaced by:
;; Neat trick from Kim Storm to add more bindings in read-only mode:
(add-keymap 'diff-mode-map (set-keymap-filter diff-mode-shared-map 'buffer-read-only t))
--
Kim F. Storm <storm@cua.dk> http://www.cua.dk
next prev parent reply other threads:[~2002-04-12 13:20 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-04-11 22:56 Enhancements to "minor-mode-map-alist" functionality Kim F. Storm
2002-04-11 22:43 ` Stefan Monnier
2002-04-12 9:31 ` Kim F. Storm
2002-04-12 13:20 ` Kim F. Storm [this message]
2002-04-12 18:46 ` Stefan Monnier
[not found] ` <5xofgoobzr.fsf@kfs2.cua.dk>
[not found] ` <200204122021.g3CKLh217680@rum.cs.yale.edu>
2002-04-14 22:32 ` Kim F. Storm
2002-04-16 20:18 ` Richard Stallman
2002-04-16 22:34 ` Kim F. Storm
2002-04-18 18:46 ` Richard Stallman
2002-04-18 23:07 ` Kim F. Storm
2002-04-19 13:43 ` Stefan Monnier
2002-04-19 15:36 ` Kim F. Storm
2002-04-19 14:46 ` Stefan Monnier
2002-04-21 17:46 ` Kim F. Storm
2002-04-22 9:28 ` Stefan Monnier
2002-04-22 15:15 ` Kim F. Storm
2002-04-19 18:42 ` Richard Stallman
2002-04-19 22:05 ` Kim F. Storm
2002-04-20 17:27 ` Richard Stallman
2002-04-21 11:08 ` Kim F. Storm
2002-04-22 7:47 ` Richard Stallman
2002-04-22 13:53 ` Kim F. Storm
2002-04-22 22:36 ` Richard Stallman
2002-04-23 10:58 ` Kim F. Storm
2002-04-22 22:36 ` Richard Stallman
2002-04-23 11:02 ` Kim F. Storm
2002-04-24 17:55 ` Richard Stallman
2002-04-26 13:44 ` Kim F. Storm
2002-04-27 22:41 ` Richard Stallman
2002-04-29 9:17 ` Kai Großjohann
2002-04-30 5:18 ` Richard Stallman
2002-04-30 21:25 ` Kim F. Storm
2002-05-01 7:14 ` Richard Stallman
2002-05-01 17:37 ` Kim F. Storm
2002-04-14 23:11 ` Kim F. Storm
2002-04-12 18:20 ` Stefan Monnier
2002-04-12 21:05 ` Kim F. Storm
2002-04-12 20:30 ` Stefan Monnier
2002-04-12 22:08 ` Kim F. Storm
2002-04-13 19:05 ` Richard Stallman
2002-04-13 19:05 ` Richard Stallman
2002-04-13 23:30 ` Kim F. Storm
2002-04-15 12:34 ` Stefan Monnier
2002-04-17 16:03 ` Richard Stallman
2002-04-15 21:54 ` Richard Stallman
2002-04-15 23:55 ` Kim F. Storm
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=5x4rih12b2.fsf@kfs2.cua.dk \
--to=storm@cua.dk \
--cc=emacs-devel@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.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
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).