From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Teemu Likonen Newsgroups: gmane.emacs.devel Subject: substitute-key-definition vs. define-key MAP [remap ...] Date: Thu, 15 Jul 2010 11:25:05 +0300 Message-ID: <871vb517a6.fsf@mithlond.arda> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1279182330 17813 80.91.229.12 (15 Jul 2010 08:25:30 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 15 Jul 2010 08:25:30 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Jul 15 10:25:29 2010 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1OZJl1-0004qM-MJ for ged-emacs-devel@m.gmane.org; Thu, 15 Jul 2010 10:25:28 +0200 Original-Received: from localhost ([127.0.0.1]:46118 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OZJkp-0004j5-G5 for ged-emacs-devel@m.gmane.org; Thu, 15 Jul 2010 04:25:15 -0400 Original-Received: from [140.186.70.92] (port=44560 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OZJkj-0004iF-CY for emacs-devel@gnu.org; Thu, 15 Jul 2010 04:25:10 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OZJkh-0000FM-Ux for emacs-devel@gnu.org; Thu, 15 Jul 2010 04:25:09 -0400 Original-Received: from mta-out.inet.fi ([195.156.147.13]:51255 helo=jenni2.inet.fi) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OZJkh-0000F2-Jf for emacs-devel@gnu.org; Thu, 15 Jul 2010 04:25:07 -0400 Original-Received: from mithlond.arda (84.251.132.215) by jenni2.inet.fi (8.5.122) id 4C3330770037EC36 for emacs-devel@gnu.org; Thu, 15 Jul 2010 11:25:05 +0300 Original-Received: from dtw by mithlond.arda with local (Exim 4.69) (envelope-from ) id 1OZJkf-00016s-D1 for emacs-devel@gnu.org; Thu, 15 Jul 2010 11:25:05 +0300 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) 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:127329 Archived-At: Some Emacs modes use substitute-key-definition function to redirect some global key-commands to mode-specific commands. My view is that using define-key and its [remap ...] functionality would be better. The problem I'm seeing is that global keys defined in a global minor mode don't work with substitute-key-definition. Here's an example, first a working one: cc-mode has this (in cc-mode.el): (substitute-key-definition 'indent-new-comment-line 'c-indent-new-comment-line c-mode-base-map global-map) In default global-map M-j runs indent-new-comment-line. Now, let's say that I have this in my .emacs file: (global-set-key [f7] 'indent-new-comment-line) This works nicely with cc-mode: f7 will run c-indent-new-comment-line instead of indent-new-comment-line. But if I don't redefine f7 key in the global map but use a global minor mode instead to shadow some of the global map (like the command indent-new-comment-line) then that binding won't be substituted in cc-mode. In other words, when my global minor mode is activated, the key for indent-new-comment-line will just run that and not c-indent-new-comment-line in cc-mode. If you want to test that here's a small minor mode for you: (defvar my-global-minor-mode-map (let ((map (make-sparse-keymap))) (define-key map [f7] 'indent-new-comment-line) map)) (define-minor-mode my-global-minor-mode "\\{my-global-minor-mode-map}" :global t :lighter " my-mode" :keymap my-global-minor-mode-map) All this would work nicely if cc-mode used [remap ...]: (define-key c-mode-base-map [remap indent-new-comment-line] 'c-indent-new-comment-line) So, am I right in saying that using substitute-key-definition on global map directly is a bad practice? I guess the question is whether you/we want to let user create custom global bindings through a global minor mode. It would be nice and convenient because global minor modes can be turned on and off. User may want to have different minor modes for redefining the basic global keys for different editing tasks.