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

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

RE: How to get current keymap


From: Drew Adams
Subject: RE: How to get current keymap
Date: Sat, 6 Dec 2008 22:35:18 -0800

> I want to get current mode's keymap, some modes do not have 
> keymap, but current keymap always exists. I need define a
> key for my function in it and my function
> can be always active for that mode.

If you want to define a key for only a specific (major or minor) mode, then use
that mode's keymap.

If that mode doesn't have a keymap, then it is less straightforward to define a
key for only that mode. You can define a key in some map that is accessible from
that keymap, so the key will be active in that mode, but then that key binding
will also hold outside that mode - unless you take pains to bind and unbind the
key when, say, the mode is entered and exited.

To see all maps accessible currently, you can use functions
`current-active-maps' and `accessible-keymaps'. See the Elisp manual, nodes
Active Keymaps and Scanning Keymaps.

Remember that there are several levels of priority for keymaps: minor mode maps
(in order), then (major mode) local map, then global map (and there are some
more levels). If you define a key in a local map, it's possible it gets shadowed
by a minor-mode binding. 

To make sense of what's happening, before you try to bind a key examine the
existing bindings in the current minor modes and major mode, as well as the
global bindings. Command `describe-keymap' (bound to `C-h M-k') in library
help-fns+.el shows you the bindings for a given map.
http://www.emacswiki.org/emacs/HelpPlus





reply via email to

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