[Top][All Lists]

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

Re: Enhancements to "minor-mode-map-alist" functionality.

From: Kim F. Storm
Subject: Re: Enhancements to "minor-mode-map-alist" functionality.
Date: 12 Apr 2002 15:20:17 +0200
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2.50

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
                                (or (eq cua-enable-cua-keys t)
                                    (not cua--explicit-region-start))
                                (not executing-kbd-macro)
                                (not cua--prefix-override-timer))
           (keymap :filter (and mark-active
                                (timerp cua--prefix-override-timer))
           (keymap :filter (or (eq cua-enable-cua-keys t)
           (keymap :filter (and cua--global-mark-active
                                (not (window-minibuffer-p)))
           (keymap :filter cua--rectangle ,cua--rectangle-keymap)
           (keymap :filter mark-active ,cua--region-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 <address@hidden> http://www.cua.dk

reply via email to

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