unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* key binding only when in a given minor mode and a given major mode?
@ 2006-08-13 21:16 Drew Adams
  0 siblings, 0 replies; 4+ messages in thread
From: Drew Adams @ 2006-08-13 21:16 UTC (permalink / raw)


I have a minor mode that binds some keys in its minor-mode map. In some
cases, these shadow global bindings. When the mode is turned off, the
minor-mode bindings are no longer in effect.

That works fine, but what happens when the binding I want to shadow is not a
global binding but a major-mode binding? What's a good way to create a
binding that will only be effective when in both a particular major mode and
a particular minor mode? When not in that minor mode, but still in the major
mode, I want the major-mode binding to be in effect, and when not in that
major mode, I want the global binding to be in effect.

For example, suppose I want to bind `g' in Info (major) mode to command
`foo-cmd' if and only if minor mode `foo' is turned on. I don't want to
affect global bindings or bindings in other modes. Turning `foo' off while
in Info should remove the binding of `g' to command `foo-cmd'. Turning `foo'
on or off while not in Info should have no effect on the binding of `g'.

All I can think of are these possibilities:

1. Bind the key in the minor-mode map to another command, `maybe-foo-cmd',
which tests the major mode and either calls `foo-cmd' or uses the global
binding of the key.

2. Bind the key in the major-mode map to another command, `maybe-foo-cmd',
which tests the minor mode and either calls `foo-cmd' or uses the major-mode
binding of the key.

#2 seems preferable, but I wonder if there isn't a better way to accomplish
this, without the intermediary of another command like `maybe-foo-cmd'. I
looked through the Elisp manual, but I didn't notice anything that might be
pertinent here. It looks like `minor-mode-overriding-map-alist' would be
almost what I need, but it does the opposite: it lets a major mode override
minor-mode maps.

Suggestions appreciated.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2006-08-13 22:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.5150.1155503814.9609.help-gnu-emacs@gnu.org>
2006-08-13 21:35 ` key binding only when in a given minor mode and a given major mode? David Kastrup
2006-08-13 21:54   ` key binding only when in a given minor mode and a given majormode? Drew Adams
2006-08-13 22:43 ` key binding only when in a given minor mode and a given major mode? David Kastrup
2006-08-13 21:16 Drew Adams

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).