From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Scott Frazer Newsgroups: gmane.emacs.help Subject: Re: I'd like non-overwriteable global keybindings Date: Wed, 02 Apr 2008 13:27:48 -0400 Organization: Ye 'Ol Disorganized NNTPCache groupie Message-ID: <1207157268.754863@sj-nntpcache-3.cisco.com> References: <87tziks3fp.fsf@gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1207198782 835 80.91.229.12 (3 Apr 2008 04:59:42 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 3 Apr 2008 04:59:42 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Apr 03 07:00:13 2008 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1JhHYZ-0008IQ-T3 for geh-help-gnu-emacs@m.gmane.org; Thu, 03 Apr 2008 07:00:12 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JhHXx-00023I-Gn for geh-help-gnu-emacs@m.gmane.org; Thu, 03 Apr 2008 00:59:33 -0400 Original-Path: shelby.stanford.edu!headwall.stanford.edu!newshub.sdsu.edu!bigfeed.bellsouth.net!bigfeed2.bellsouth.net!news.bellsouth.net!hwmnpeer01.phx!news.highwinds-media.com!hw-filter.phx!newsfe17.phx.POSTED!53ab2750!not-for-mail User-Agent: Thunderbird 2.0.0.12 (Windows/20080213) Original-Newsgroups: gnu.emacs.help In-Reply-To: <87tziks3fp.fsf@gmail.com> Cache-Post-Path: sj-nntpcache-3.cisco.com!unknown@scfrazer-wxp.cisco.com X-Cache: nntpcache 3.0.2 (see http://www.nntpcache.com/) Original-Lines: 52 Original-X-Complaints-To: newsadmin@cisco.com Original-NNTP-Posting-Date: Wed, 02 Apr 2008 10:27:48 MST Original-Xref: shelby.stanford.edu gnu.emacs.help:157615 X-Mailman-Approved-At: Thu, 03 Apr 2008 00:58:32 -0400 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:52999 Archived-At: Benjamin Andresen wrote: > Hey there, > > I'm trying to set certain keybindings to be global but I don't want > _any_ major or minor mode to be able to change them. One example: > > M-o should always be 'other-window > > I'd start with (global-set-key (kbd "M-o") 'other-window) and that > works, until there is a major mode that sets it locally. > Example: rcirc overwrites M-o. > > I tried several things to get rid of them without specifically setting > rcirc-map locally to nil, because I have several and I just want a > general solution. > > What I tried: > > (add-hook 'after-change-major-mode-hook > '(lambda () (define-key (current-local-map) (kbd "M-o") > 'nil))) > > This doesn't work. M-o still does rcirc omit mode. > Apparently that's not the very latest hook that is run after a buffer > is initialized. Maybe there is a hook that gets called after every > (use-local-map) or so? > > Another hack would be to get a list of all -maps at any given moment and > map through it and run a (define-key mapcmap ...) > Any idea if there is a variable that holds them all? > > Two other ways that people on #emacs suggested are creating a minor mode > as some sort of overlay and/or somehow use overriding-local-map. > > I haven't investigated the minor mode one, but the overriding-local-map > is neither a function nor a variable if you ask define-key... (both are > void, but documented) > > Does anyone have an idea how to fix this or has any other pointers, I > would be very happy. > I use the minor-mode trick: (defvar my-keys-minor-mode-map (make-keymap) "my-keys-minor-mode keymap.") (define-key my-keys-minor-mode-map "\M-o" 'other-window) (define-minor-mode my-keys-minor-mode "A minor mode so that my key settings override annoying major modes." t " my-keys" 'my-keys-minor-mode-map) (my-keys-minor-mode) Scott