[Top][All Lists]

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

Question on accessible-keymaps

From: Drew Adams
Subject: Question on accessible-keymaps
Date: Sun, 17 Sep 2006 17:21:32 -0700

I have a question about using `accessible-keymaps'. I've implemented a kind
of key-sequence completion, but I'm having trouble picking up all of the
global prefix maps. I do something like this:

(dolist (key+map (accessible-keymaps (current-global-map)))
  (when (keymapp (cdr key+map))
    (map-keymap (lambda (event binding)
                  (when (keymapp binding)
                    (let ((key (vconcat (car key+map)
                                        (vector event)
                      (unless (lookup-key my-map key)
                        (define-key my-map key foo)))))
                (cdr key+map))))

My hope was to run through all keymaps accessible from the current global
map, and bind, in `my-map', to command `foo', any prefix keys followed by
[S-tab]. (Similarly to, say, `C-x C-h', `C-x S-tab' gives access to the
possible `C-x' bindings, but in this case as completion candidates.)

This works fine for prefix keys such as `C-x' and `C-x 4', but it doesn't
work for some other prefix keys, such as `C-x v', `C-h', and `C-x 8'. I've
hacked some of those separately as individual one-offs, but I imagine there
must be a way to pick them up generally with `accessible-keymaps'.

Any suggestions would be appreciated. Is this a reasonable approach, or can
you suggest an easier/better/smarter way to do what I want? You can reply
off-list if you don't think others would be interested. I looked at the
existing Emacs sources for inspiration, but the only use I found of
`accessible-keymaps' was a comment in emerge.el, and it didn't help.

Note that this will only work anyway for globally defined prefixes, not for,
e.g., `%' in Dired mode. That's OK. I'd like to do the same for mode maps
(e.g. Dired), but that seems like it would be a bit complicated (`my-map' is
a minor-mode map; I don't want to modify any global or modal bindings).

reply via email to

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