From: Tassilo Horn <tsdh@gnu.org>
To: help-gnu-emacs <help-gnu-emacs@gnu.org>
Subject: Stop modes from hijacking several global keys
Date: Wed, 05 Nov 2014 08:02:27 +0100 [thread overview]
Message-ID: <87wq7a3zb0.fsf@thinkpad-t440p.tsdh.org> (raw)
Hi all,
I'm using this command for years for easily switching to windows with
M-<window-number>:
--8<---------------cut here---------------start------------->8---
(defun th/select-nth-window (n)
"Selects the N-th window.
When called interactively, the N is provided as the last part of
the keybinding. So you'd usually bind this function to
M-{1,..,9}, and then M-3 selects the third window."
(interactive
(list (let ((ev (event-basic-type last-command-event)))
(string-to-number (char-to-string ev)))))
(if (> n (length (window-list)))
(user-error "There's no window %s." n)
(select-window (window-at 0 0))
(other-window (1- n))))
(dotimes (i 9)
(global-set-key (kbd (format "M-%s" (1+ i))) 'th/select-nth-window))
--8<---------------cut here---------------end--------------->8---
But somewhat recently, many modes like magit and diff-mode (why does
that redefine M-<number> to `digit-argument' in its own mode map?) start
using M-<number> keys for other things. Or maybe I just started using
modes that use these keys for other things...
Anyway, window-switching is such a frequent task, and doing M-<number>
for that is hard-wired in my muscle memory, so the question is: Is there
some automatic way to prevent modes and minor-modes from redefining it?
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.
But is there a similar hook that runs after a minor mode has been
activated?
Bye,
Tassilo
next reply other threads:[~2014-11-05 7:02 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-05 7:02 Tassilo Horn [this message]
2014-11-05 7:12 ` Stop modes from hijacking several global keys Tassilo Horn
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=87wq7a3zb0.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.