all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Stop modes from hijacking several global keys
@ 2014-11-05  7:02 Tassilo Horn
  2014-11-05  7:12 ` Tassilo Horn
  0 siblings, 1 reply; 4+ messages in thread
From: Tassilo Horn @ 2014-11-05  7:02 UTC (permalink / raw)
  To: help-gnu-emacs

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



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

end of thread, other threads:[~2014-11-05 11:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-05  7:02 Stop modes from hijacking several global keys Tassilo Horn
2014-11-05  7:12 ` Tassilo Horn
2014-11-05  9:41   ` Nicolas Richard
2014-11-05 11:38     ` Tassilo Horn

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.