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

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

Re: Scanning keymaps for keybindings


From: Tim X
Subject: Re: Scanning keymaps for keybindings
Date: Wed, 08 Dec 2010 15:35:16 -0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)

Elena <egarrulo@gmail.com> writes:

> On Nov 9, 10:47 pm, Tim X <t...@nospam.dev.null> wrote:
>> Depending on what you want to do, you may be able to use something like
>> after-change-major-mode hook or similar to update things after a new
>> mode is used. However, this assumes all modes have been written
>> following standard conventions, which cannot be guaranteed.
>
> The goal I'd like to accomplish is remapping a keybinding without
> having to dig through the documentation and Elisp files.  Yes, I know
> you can type "C-h c" to know what the name of the command which is
> bound to a specific key, then you can grep such name to know which
> keymap you'd have to change; but since I'm a keyboard layout
> thinkerer, I'd prefer to automate that.

Given your goal, possibly the only way to automate the process would be
to add a function to after-change-major-mode-hook that searches the
currently defined keymaps for an entry for the key you are interested in
re-mapping. Then, perhaps you could re-map this key. However, I see some
difficulties here 

1. Remember that key maps don't just have mappings to commands as in the
sense of an interactive function. You can also have
lists, vectors, macros and symbols. This may not be an issue
if all you want to know is if the key sequence is bound to something or
not - though I'm not sure what sort of complexities you may run into
changing the key bindings of keys involved in a macro. 

2. It could be difficult to automatically find a new place to re-bind
the command. If, for example, what you want to do is re-bind some keys
and have anything they were previously bound to moved to some other key
binding, then you could end up with quite a search. This could be a
bit slow. Worse still, you need to somehow notify the user of the new
binding and of course, what keys are available and the order they are
used may change depending on the order you load things. 

Possibly another solution would be to only partially automate the
process. It might be possible to add a hook function that looks for
potential key binding conflicts, alerts the user and asks them what they
want to do. Possibly it could then gather information from the user
which could be used to generate snippets of elisp code that would
redefine the binding. These snippets could then be added to the
appropriate mode hooks. This may then make it easier to develop
customizations that could then be further refined if necessary. At the
very least, you can fairly easily develop a hook function that will look
for something bound to a specific key sequence and what its keymap is -
maybe a little less work than C-h c and grep. See the kemap section from
the elisp manual for a pseudo algorithm for searching keymaps and key
lookup related functions. 

Tim


-- 
tcross (at) rapttech dot com dot au


reply via email to

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