unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* substitute-key-definition vs. define-key MAP [remap ...]
@ 2010-07-15  8:25 Teemu Likonen
  2010-07-22 22:36 ` Stefan Monnier
  0 siblings, 1 reply; 14+ messages in thread
From: Teemu Likonen @ 2010-07-15  8:25 UTC (permalink / raw)
  To: emacs-devel

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.



^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2010-07-25 13:43 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-15  8:25 substitute-key-definition vs. define-key MAP [remap ...] Teemu Likonen
2010-07-22 22:36 ` 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

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).