all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* I'd like non-overwriteable global keybindings
@ 2008-04-02 15:04 Benjamin Andresen
  2008-04-02 17:27 ` Scott Frazer
  2008-04-03 14:07 ` Lennart Borgman (gmail)
  0 siblings, 2 replies; 5+ messages in thread
From: Benjamin Andresen @ 2008-04-02 15:04 UTC (permalink / raw)
  To: help-gnu-emacs


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.

A general solution is necessary because listing each mode where I want
to continue using my global bindings seems wasteful...

Thanks in advance,
benny







          
          



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

* Re: I'd like non-overwriteable global keybindings
  2008-04-02 15:04 I'd like non-overwriteable global keybindings Benjamin Andresen
@ 2008-04-02 17:27 ` Scott Frazer
  2008-04-04 15:12   ` Benjamin Andresen
  2008-04-03 14:07 ` Lennart Borgman (gmail)
  1 sibling, 1 reply; 5+ messages in thread
From: Scott Frazer @ 2008-04-02 17:27 UTC (permalink / raw)
  To: help-gnu-emacs

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


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

* Re: I'd like non-overwriteable global keybindings
  2008-04-02 15:04 I'd like non-overwriteable global keybindings Benjamin Andresen
  2008-04-02 17:27 ` Scott Frazer
@ 2008-04-03 14:07 ` Lennart Borgman (gmail)
  1 sibling, 0 replies; 5+ messages in thread
From: Lennart Borgman (gmail) @ 2008-04-03 14:07 UTC (permalink / raw)
  To: help-gnu-emacs

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:

See the manual

   (info "(elisp) Key Binding Conventions")




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

* Re: I'd like non-overwriteable global keybindings
@ 2008-04-03 17:30 martin rudalics
  0 siblings, 0 replies; 5+ messages in thread
From: martin rudalics @ 2008-04-03 17:30 UTC (permalink / raw)
  To: help-gnu-emacs

I'm using the following brute-force approach:

(defvar meta-map (make-sparse-keymap)
   "My keymap.")

(defvar meta-map-alist `((t . ,meta-map))
   "My keymap alist.")

(add-to-ordered-list 'emulation-mode-map-alists 'meta-map-alist 1000)

(define-key meta-map [(meta left)] 'bury-buffer)
(define-key meta-map [(meta right)] 'unbury-buffer)
[...]





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

* Re: I'd like non-overwriteable global keybindings
  2008-04-02 17:27 ` Scott Frazer
@ 2008-04-04 15:12   ` Benjamin Andresen
  0 siblings, 0 replies; 5+ messages in thread
From: Benjamin Andresen @ 2008-04-04 15:12 UTC (permalink / raw)
  To: help-gnu-emacs

Hey,

Scott Frazer <frazer.scott@gmail.com> writes:
> I use the minor-mode trick

Thanks for that! That works!

And also thanks for the priority trick, Martin!
I was scared that other minor modes will overwrite that, but the
documentation and echo-area in #emacs told me the way it's determined.

br,
benny


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

end of thread, other threads:[~2008-04-04 15:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-02 15:04 I'd like non-overwriteable global keybindings Benjamin Andresen
2008-04-02 17:27 ` Scott Frazer
2008-04-04 15:12   ` Benjamin Andresen
2008-04-03 14:07 ` Lennart Borgman (gmail)
  -- strict thread matches above, loose matches on Subject: below --
2008-04-03 17:30 martin rudalics

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.