From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tassilo Horn Newsgroups: gmane.emacs.help Subject: Stop modes from hijacking several global keys Date: Wed, 05 Nov 2014 08:02:27 +0100 Message-ID: <87wq7a3zb0.fsf@thinkpad-t440p.tsdh.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1415170985 6124 80.91.229.3 (5 Nov 2014 07:03:05 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 5 Nov 2014 07:03:05 +0000 (UTC) To: help-gnu-emacs Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Nov 05 08:02:59 2014 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1XlucM-0002q5-Gq for geh-help-gnu-emacs@m.gmane.org; Wed, 05 Nov 2014 08:02:58 +0100 Original-Received: from localhost ([::1]:44603 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XlucL-00069F-Tx for geh-help-gnu-emacs@m.gmane.org; Wed, 05 Nov 2014 02:02:57 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51645) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xluc5-000675-8W for help-gnu-emacs@gnu.org; Wed, 05 Nov 2014 02:02:47 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xluby-0005ZU-C8 for help-gnu-emacs@gnu.org; Wed, 05 Nov 2014 02:02:41 -0500 Original-Received: from out2-smtp.messagingengine.com ([66.111.4.26]:50595) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xluby-0005ZP-91 for help-gnu-emacs@gnu.org; Wed, 05 Nov 2014 02:02:34 -0500 Original-Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id A072220941 for ; Wed, 5 Nov 2014 02:02:33 -0500 (EST) Original-Received: from frontend2 ([10.202.2.161]) by compute5.internal (MEProxy); Wed, 05 Nov 2014 02:02:33 -0500 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=x-sasl-enc:from:to:subject:date :message-id:mime-version:content-type; s=smtpout; bh=jwlfk9DhxzT rzeCNDD53zGGLGGA=; b=YdYDZCITHbCWwanM6u3E8MUbTwQ544I0Dcp5jFlwX0P aXxekzx7pIqO7KQCTFkmISkXbeEplHMSPuc1Vg8+SDShy1DgpSrEx3EiqNEGcPW4 qwlOMN7rEE9ktMtVV8z45zS03TgpLzNZ7aHWZ2KEFpk2R86S0MAcV2ucaPgLhu0w = X-Sasl-enc: NztTDigLxfyb5BvR/ifjrtnwOScdb4V2jYWEdkPFkE3b 1415170953 Original-Received: from thinkpad-t440p.tsdh.org (unknown [2.162.240.213]) by mail.messagingengine.com (Postfix) with ESMTPA id E0069680101 for ; Wed, 5 Nov 2014 02:02:32 -0500 (EST) User-Agent: Gnus/5.130012 (Ma Gnus v0.12) Emacs/25.0.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 66.111.4.26 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:100756 Archived-At: Hi all, I'm using this command for years for easily switching to windows with M-: --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- to `digit-argument' in its own mode map?) start using M- 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- 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- keys, and whatever it wants to bind to M- would automagically be bound to ` M-' 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-")) and doing `local-set-key' if needed. But is there a similar hook that runs after a minor mode has been activated? Bye, Tassilo