From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Drew Adams" Newsgroups: gmane.emacs.devel Subject: Question on remapping keys Date: Thu, 19 Jan 2006 13:30:00 -0800 Message-ID: References: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1137711694 7837 80.91.229.2 (19 Jan 2006 23:01:34 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 19 Jan 2006 23:01:34 +0000 (UTC) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Jan 20 00:01:31 2006 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1Ezim3-0005d1-QN for ged-emacs-devel@m.gmane.org; Fri, 20 Jan 2006 00:01:00 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1EzioV-0000W9-Ev for ged-emacs-devel@m.gmane.org; Thu, 19 Jan 2006 18:03:31 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1EzhRA-0005Bx-RF for emacs-devel@gnu.org; Thu, 19 Jan 2006 16:35:21 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1EzhOj-00045J-SP for emacs-devel@gnu.org; Thu, 19 Jan 2006 16:32:50 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1EzhOX-0003wb-GV for emacs-devel@gnu.org; Thu, 19 Jan 2006 16:32:37 -0500 Original-Received: from [141.146.126.228] (helo=agminet01.oracle.com) by monty-python.gnu.org with esmtp (TLS-1.0:DHE_RSA_3DES_EDE_CBC_SHA:24) (Exim 4.34) id 1EzhSd-0001vd-F9 for emacs-devel@gnu.org; Thu, 19 Jan 2006 16:36:51 -0500 Original-Received: from rgmsgw300.us.oracle.com (rgmsgw300.us.oracle.com [138.1.186.49]) by agminet01.oracle.com (Switch-3.1.7/Switch-3.1.7) with ESMTP id k0JLU1PI001265 for ; Thu, 19 Jan 2006 15:30:02 -0600 Original-Received: from rgmsgw300.us.oracle.com (localhost [127.0.0.1]) by rgmsgw300.us.oracle.com (Switch-3.1.7/Switch-3.1.7) with ESMTP id k0JLU1v2012805 for ; Thu, 19 Jan 2006 14:30:01 -0700 Original-Received: from dradamslap (dradams-lap.us.oracle.com [130.35.177.126]) by rgmsgw300.us.oracle.com (Switch-3.1.7/Switch-3.1.7) with SMTP id k0JLU0kk012791 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NO) for ; Thu, 19 Jan 2006 14:30:01 -0700 Original-To: "Emacs-Devel" X-Priority: 1 (Highest) X-MSMail-Priority: High X-Mailer: Microsoft Outlook IMO, Build 9.0.6604 (9.0.2911.0) In-Reply-To: Importance: High X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506 X-Brightmail-Tracker: AAAAAQAAAAI= X-Whitelist: TRUE X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:49277 Archived-At: I sent this to help-gnu-emacs, but I haven't yet found a solution to the problem. I wonder too if there might be a bug here. 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 only 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 (Kim?) suggested that I could use `define-key' with [remap...] instead of `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). The result of remapping is this for minibuffer-local-completion-map: (keymap ... (remap keymap (scroll-left . my-scroll-left) (scroll-right . my-scroll-right) (scroll-down . my-scroll-down) (scroll-up . my-scroll-up) (next-line . my-next-line) (previous-line . my-previous-line) (help-command . my-help) (self-insert-command . my-self-insert)) ...) This looks promising, but it seems to work only partially. For instance, (where-is-internal 'my-scroll-up (list minibuffer-local-completion-map)) returns ([remap scroll-up]), which looks good. `M-x' followed by `C-v' does invoke `my-scroll-up', but `M-x' followed by [next] (also bound to `scroll-up' in `global-map') does not invoke `my-scroll-up' - it invokes `next-history-element', just as in vanilla Emacs. IOW, apparently not all bindings of `scroll-up' got remapped. I don't know if this is a bug or by design. I'm looking for behavior similar to that of `substitute-key-definition': remap/substitute _all_ bindings. This is especially important since I apparently have no control over which single binding gets remapped - that is, only one binding of the command seems to be remapped, and I don't know how to pick which one. Similarly, (where-is-internal 'my-help (list minibuffer-local-completion-map)) returns ([remap help-command]). That suggests that `help-command' was remapped, but using `C-h' in the minibuffer does not invoke `my-help'. (Why?) If I use `substitute-key-definition', providing `global-map' as the OLDMAP arg, it works perfectly, but the performance is unacceptable in Emacs 22. There must be some way to do something equivalent using command remapping(?). Anyone have a suggestion on how to proceed?