From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Drew Adams" Newsgroups: gmane.emacs.help Subject: Question on remapping keys Date: Sun, 15 Jan 2006 17:19:51 -0800 Message-ID: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1137374433 11199 80.91.229.2 (16 Jan 2006 01:20:33 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 16 Jan 2006 01:20:33 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Jan 16 02:20:28 2006 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1EyJ2k-0004Hb-Lb for geh-help-gnu-emacs@m.gmane.org; Mon, 16 Jan 2006 02:20:25 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1EyJ50-0000LG-OY for geh-help-gnu-emacs@m.gmane.org; Sun, 15 Jan 2006 20:22:42 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1EyJ4r-0000KE-8t for help-gnu-emacs@gnu.org; Sun, 15 Jan 2006 20:22:33 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1EyJ4n-0000IF-HX for help-gnu-emacs@gnu.org; Sun, 15 Jan 2006 20:22:32 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1EyJ4n-0000I3-Dg for help-gnu-emacs@gnu.org; Sun, 15 Jan 2006 20:22:29 -0500 Original-Received: from [148.87.122.30] (helo=rgminet01.oracle.com) by monty-python.gnu.org with esmtp (TLS-1.0:DHE_RSA_3DES_EDE_CBC_SHA:24) (Exim 4.34) id 1EyJ8D-0008W4-IT for help-gnu-emacs@gnu.org; Sun, 15 Jan 2006 20:26:01 -0500 Original-Received: from rgmsgw301.us.oracle.com (rgmsgw301.us.oracle.com [138.1.186.50]) by rgminet01.oracle.com (Switch-3.1.6/Switch-3.1.6) with ESMTP id k0G1K5G6006089 for ; Sun, 15 Jan 2006 18:20:06 -0700 Original-Received: from rgmsgw301.us.oracle.com (localhost [127.0.0.1]) by rgmsgw301.us.oracle.com (Switch-3.1.7/Switch-3.1.7) with ESMTP id k0G1K5MW000419 for ; Sun, 15 Jan 2006 18:20:05 -0700 Original-Received: from dradamslap (dhcp-amer-rmdc-csvpn-gw5-141-144-105-79.vpn.oracle.com [141.144.105.79]) by rgmsgw301.us.oracle.com (Switch-3.1.7/Switch-3.1.7) with SMTP id k0G1K42q000411 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NO) for ; Sun, 15 Jan 2006 18:20:05 -0700 Original-To: "Help-Gnu-Emacs" X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.6604 (9.0.2911.0) Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506 X-Brightmail-Tracker: AAAAAQAAAAI= X-Whitelist: TRUE 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:32672 Archived-At: I have a minor mode that redefines some of the minibuffer keymaps (e.g. minibuffer-local-completion-map). I want turning on the mode to implement the new minibuffer bindings, and turning it off to restore the minibuffer bindings of vanilla Emacs. In some cases, I reuse key sequences that are bound in the global map, binding them to other commands in minibuffer maps. Those are the bindings that I have a question about. In Emacs 20, I simply do this: (substitute-key-definition from to minibuffer-local-completion-map global-map) For example, to bind `C-h' in the minibuffer to command `my-help': (substitute-key-definition 'help-command 'my-help minibuffer-local-completion-map global-map) I do the same for `self-insert-command', replacing it with `my-self-insert' for minibuffer maps. This is very fast in Emacs 20, but in Emacs 22 it is unbearably slow. It takes about 5 seconds for 10 such key-definition substitutions! I think that the slowness might be due, in particular, to dealing with the case of `self-insert-command'. Someone suggested that I could use `define-key' with [remap...] instead of `substitute-key-definition'. I'm not sure how to do that, since I use the OLDMAP arg to `substitute-key-definition'. I tried using the following when my minor mode is turned on: (defun my-remap (from to map) "Remap command FROM to command TO in keymap MAP." (if (boundp 'this-original-command) (define-key map [remap `,from] to) ; Emacs 22 (substitute-key-definition from to map global-map))) ; Emacs 20 And similarly when it is turned off, using nil for TO, to remove the binding from MAP (a minibuffer map). However, as you can guess, that doesn't work. I haven't expressed that I want to pick up the `global-map' binding (equivalent of OLDMAP arg to `substitute-key-definition'). Anyone have a suggestion on how to proceed? What I'm looking for is a fast way to do more or less what (substitute-key-definition from to map global-map) does. The performance penalty for using `substitute-key-definition' is just too big - I need to find something faster. Any advice would be appreciated.