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

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

Re: I'd like non-overwriteable global keybindings


From: Scott Frazer
Subject: Re: I'd like non-overwriteable global keybindings
Date: Wed, 02 Apr 2008 13:27:48 -0400
User-agent: Thunderbird 2.0.0.12 (Windows/20080213)

Benjamin Andresen wrote:
Hey there,

I'm trying to set certain keybindings to be global but I don't want
_any_ major or minor mode to be able to change them. One example:

M-o should always be 'other-window

I'd start with (global-set-key (kbd "M-o") 'other-window) and that
works, until there is a major mode that sets it locally.
Example: rcirc overwrites M-o.

I tried several things to get rid of them without specifically setting
rcirc-map locally to nil, because I have several and I just want a
general solution.

What I tried:

(add-hook 'after-change-major-mode-hook
          '(lambda () (define-key (current-local-map) (kbd "M-o")
          'nil)))

This doesn't work. M-o still does rcirc omit mode.
Apparently that's not the very latest hook that is run after a buffer
is initialized. Maybe there is a hook that gets called after every
(use-local-map) or so?

Another hack would be to get a list of all -maps at any given moment and
map through it and run a (define-key mapcmap ...)
Any idea if there is a variable that holds them all?

Two other ways that people on #emacs suggested are creating a minor mode
as some sort of overlay and/or somehow use overriding-local-map.

I haven't investigated the minor mode one, but the overriding-local-map
is neither a function nor a variable if you ask define-key... (both are
void, but documented)

Does anyone have an idea how to fix this or has any other pointers, I
would be very happy.


I use the minor-mode trick:

(defvar my-keys-minor-mode-map (make-keymap) "my-keys-minor-mode keymap.")
(define-key my-keys-minor-mode-map "\M-o" 'other-window)
(define-minor-mode my-keys-minor-mode
  "A minor mode so that my key settings override annoying major modes."
  t " my-keys" 'my-keys-minor-mode-map)
(my-keys-minor-mode)

Scott


reply via email to

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