From: Tassilo Horn <tsdh@gnu.org>
To: help-gnu-emacs <help-gnu-emacs@gnu.org>
Subject: Re: Stop modes from hijacking several global keys
Date: Wed, 05 Nov 2014 08:12:08 +0100 [thread overview]
Message-ID: <87sihy3yuv.fsf@thinkpad-t440p.tsdh.org> (raw)
In-Reply-To: <87wq7a3zb0.fsf@thinkpad-t440p.tsdh.org> (Tassilo Horn's message of "Wed, 05 Nov 2014 08:02:27 +0100")
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
next prev parent reply other threads:[~2014-11-05 7:12 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-05 7:02 Stop modes from hijacking several global keys Tassilo Horn
2014-11-05 7:12 ` Tassilo Horn [this message]
2014-11-05 9:41 ` Nicolas Richard
2014-11-05 11:38 ` Tassilo Horn
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87sihy3yuv.fsf@thinkpad-t440p.tsdh.org \
--to=tsdh@gnu.org \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.