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: key binding only when in a given minor mode and a given major mode? Date: Sun, 13 Aug 2006 14:16:27 -0700 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 1155503833 27945 80.91.229.2 (13 Aug 2006 21:17:13 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 13 Aug 2006 21:17:13 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Aug 13 23:17:12 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 1GCNKT-00034k-JM for geh-help-gnu-emacs@m.gmane.org; Sun, 13 Aug 2006 23:17:05 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GCNKT-0002bd-00 for geh-help-gnu-emacs@m.gmane.org; Sun, 13 Aug 2006 17:17:05 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1GCNKH-0002bG-0G for help-gnu-emacs@gnu.org; Sun, 13 Aug 2006 17:16:53 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1GCNKE-0002b1-J8 for help-gnu-emacs@gnu.org; Sun, 13 Aug 2006 17:16:51 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GCNKE-0002ay-Ei for help-gnu-emacs@gnu.org; Sun, 13 Aug 2006 17:16:50 -0400 Original-Received: from [148.87.113.118] (helo=rgminet01.oracle.com) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_3DES_EDE_CBC_SHA:24) (Exim 4.52) id 1GCNPt-0007LY-M1 for help-gnu-emacs@gnu.org; Sun, 13 Aug 2006 17:22:41 -0400 Original-Received: from rgmgw3.us.oracle.com (rgmgw3.us.oracle.com [138.1.186.112]) by rgminet01.oracle.com (Switch-3.1.6/Switch-3.1.6) with ESMTP id k7DLGmFs031770 for ; Sun, 13 Aug 2006 15:16:48 -0600 Original-Received: from dradamslap (dhcp-amer-csvpn-gw1-141-144-64-220.vpn.oracle.com [141.144.64.220]) by rgmgw3.us.oracle.com (Switch-3.1.7/Switch-3.1.7) with SMTP id k7DLGlWI011567 for ; Sun, 13 Aug 2006 15:16:47 -0600 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) X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1807 Importance: Normal X-Brightmail-Tracker: AAAAAQAAAAI= X-Brightmail-Tracker: AAAAAQAAAAI= X-Whitelist: TRUE 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:36671 Archived-At: I have a minor mode that binds some keys in its minor-mode map. In some cases, these shadow global bindings. When the mode is turned off, the minor-mode bindings are no longer in effect. That works fine, but what happens when the binding I want to shadow is not a global binding but a major-mode binding? What's a good way to create a binding that will only be effective when in both a particular major mode and a particular minor mode? When not in that minor mode, but still in the major mode, I want the major-mode binding to be in effect, and when not in that major mode, I want the global binding to be in effect. For example, suppose I want to bind `g' in Info (major) mode to command `foo-cmd' if and only if minor mode `foo' is turned on. I don't want to affect global bindings or bindings in other modes. Turning `foo' off while in Info should remove the binding of `g' to command `foo-cmd'. Turning `foo' on or off while not in Info should have no effect on the binding of `g'. All I can think of are these possibilities: 1. Bind the key in the minor-mode map to another command, `maybe-foo-cmd', which tests the major mode and either calls `foo-cmd' or uses the global binding of the key. 2. Bind the key in the major-mode map to another command, `maybe-foo-cmd', which tests the minor mode and either calls `foo-cmd' or uses the major-mode binding of the key. #2 seems preferable, but I wonder if there isn't a better way to accomplish this, without the intermediary of another command like `maybe-foo-cmd'. I looked through the Elisp manual, but I didn't notice anything that might be pertinent here. It looks like `minor-mode-overriding-map-alist' would be almost what I need, but it does the opposite: it lets a major mode override minor-mode maps. Suggestions appreciated.