all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Teemu Likonen <tlikonen@iki.fi>
To: emacs-devel@gnu.org
Subject: substitute-key-definition vs. define-key MAP [remap ...]
Date: Thu, 15 Jul 2010 11:25:05 +0300	[thread overview]
Message-ID: <871vb517a6.fsf@mithlond.arda> (raw)

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.



             reply	other threads:[~2010-07-15  8:25 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-15  8:25 Teemu Likonen [this message]
2010-07-22 22:36 ` substitute-key-definition vs. define-key MAP [remap ...] Stefan Monnier
2010-07-23  3:50   ` Stephen J. Turnbull
2010-07-23  9:26     ` Stefan Monnier
2010-07-23  9:32       ` Miles Bader
2010-07-24  7:08         ` Stephen J. Turnbull
2010-07-24  8:19           ` David Kastrup
2010-07-24  9:33           ` Miles Bader
2010-07-24 14:25             ` Stephen J. Turnbull
2010-07-25  3:21               ` Miles Bader
2010-07-25 10:19                 ` Stephen J. Turnbull
2010-07-25 13:43                   ` Miles Bader
2010-07-23 10:03       ` David Kastrup
2010-07-24  6:27         ` Stephen J. Turnbull

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=871vb517a6.fsf@mithlond.arda \
    --to=tlikonen@iki.fi \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.