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

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

Re: Stop modes from hijacking several global keys


From: Tassilo Horn
Subject: Re: Stop modes from hijacking several global keys
Date: Wed, 05 Nov 2014 08:12:08 +0100
User-agent: Gnus/5.130012 (Ma Gnus v0.12) Emacs/25.0.50 (gnu/linux)

Tassilo Horn <tsdh@gnu.org> writes:

> Ideally, that magic would stop the mode from hijacking M-<number>
> keys, and whatever it wants to bind to M-<number> would automagically
> be bound to `<escape> M-<number>' instead.
>
> I think at least for major-modes I can use
> `after-change-major-mode-hook' in combination with a function checking
> (key-binding (kbd "M-<number>")) and doing `local-set-key' if needed.

Oh, that was easier than I expected:

--8<---------------cut here---------------start------------->8---
(defun th/select-nth-window-ensure-keys ()
  "Ensures that M-<number> is bound to `th/select-nth-window'.
Binds whatever else is bound to M-<number> to <escape> M-<number>."
  (dotimes (i 9)
    (let* ((key (kbd (format "M-%s" (1+ i))))
           (cmd (key-binding key)))
      (unless (equal cmd #'th/select-nth-window)
        (local-set-key key 'th/select-nth-window)
        (local-set-key (kbd (format "<escape> M-%s" (1+ i))) cmd)))))

(add-hook 'after-change-major-mode-hook #'th/select-nth-window-ensure-keys)
--8<---------------cut here---------------end--------------->8---

> But is there a similar hook that runs after a minor mode has been
> activated?

This one is still open although I think I haven't encountered a
minor-mode that tried to redefine M-<number> yet, so it's less important
to me.

Bye,
Tassilo



reply via email to

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