all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* How do I "duplicate" a keybinding?
@ 2007-08-17  9:35 Alan Mackenzie
  0 siblings, 0 replies; 3+ messages in thread
From: Alan Mackenzie @ 2007-08-17  9:35 UTC (permalink / raw)
  To: help-gnu-emacs

I would like to "duplicate" a key-binding.  By this I mean I want to make
a new binding do the same thing as an existing one.

In particular, I find the commands in hideshow minor mode, such as

    C-c @ C-c (hs-toggle-hiding)

too cumbersome to type; each keystroke requires a modifier different
from the previous one - <ctrl>, <shift>, <ctrl>.

So I want to use an unused binding C-S-' in place of C-c @, so that I
could do the above command with the more convenient

    C-S-' C-c

.  I know that I could bind C-S-' to hs-minor-mode-map, but this wouldn't
be right, since C-S-' would continue to point to this keymap even when
hideshow mode was disabled.

I could write a command starting like this:

    (defun C-c@ ()
      (interactive)
      (let ((kmap (key-binding "\C-c@")))
        (if key-binding
	    ....

where I then proceed to read further keystrokes until I get a complete
key sequence.  But do I really have to go through all this?

I've tried to find something useful in the chapter "Keymaps" in the Elisp
manual, but didn't find anything.  Am I missing something obvious here?

-- 
Alan Mackenzie (Ittersbach, Germany).

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

* Re: How do I "duplicate" a keybinding?
       [not found] <mailman.4899.1187343204.32220.help-gnu-emacs@gnu.org>
@ 2007-08-17 10:37 ` Johan Bockgård
  2007-08-18 13:59   ` Alan Mackenzie
  0 siblings, 1 reply; 3+ messages in thread
From: Johan Bockgård @ 2007-08-17 10:37 UTC (permalink / raw)
  To: help-gnu-emacs

Alan Mackenzie <acm@muc.de> writes:

> So I want to use an unused binding C-S-' in place of C-c @, so that I
> could do the above command with the more convenient
>
>     C-S-' C-c
>
> .  I know that I could bind C-S-' to hs-minor-mode-map, but this wouldn't
> be right, since C-S-' would continue to point to this keymap even when
> hideshow mode was disabled.
[...]
> Am I missing something obvious here?

Yes. The way to make a binding not have an effect when a mode is
disabled is to bind it in the mode's map! (And you don't want to bind
C-S-' to hs-minor-mode-map but to the submap that C-c @ is bound to.)

    ;; C-S-' is C-" (on my keyboard).
    (define-key hs-minor-mode-map
      [?\C-\"]
      (lookup-key hs-minor-mode-map [?\C-c ?@]))

-- 
Johan Bockgård

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

* Re: How do I "duplicate" a keybinding?
  2007-08-17 10:37 ` How do I "duplicate" a keybinding? Johan Bockgård
@ 2007-08-18 13:59   ` Alan Mackenzie
  0 siblings, 0 replies; 3+ messages in thread
From: Alan Mackenzie @ 2007-08-18 13:59 UTC (permalink / raw)
  To: Johan Bockgård; +Cc: help-gnu-emacs

Hi, Johan!

On Fri, Aug 17, 2007 at 12:37:18PM +0200, Johan Bockgård wrote:
> Alan Mackenzie <acm@muc.de> writes:

> > So I want to use an unused binding C-S-' in place of C-c @, so that I
> > could do the above command with the more convenient

> >     C-S-' C-c

> > .  I know that I could bind C-S-' to hs-minor-mode-map, but this wouldn't
> > be right, since C-S-' would continue to point to this keymap even when
> > hideshow mode was disabled.
> [...]
> > Am I missing something obvious here?

> Yes. The way to make a binding not have an effect when a mode is
> disabled is to bind it in the mode's map! (And you don't want to bind
> C-S-' to hs-minor-mode-map but to the submap that C-c @ is bound to.)

>     ;; C-S-' is C-" (on my keyboard).
>     (define-key hs-minor-mode-map
>       [?\C-\"]
>       (lookup-key hs-minor-mode-map [?\C-c ?@]))

Thank you indeed!  I put this define-key in the mode's hook, and now
everything works as wanted.

What got me confused is that I (subconsciously) thought that typing C-c
@ brought you to hs-minor-mode-map. 

> -- 
> Johan Bockgård

-- 
Alan Mackenzie (Ittersbach, Germany).

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

end of thread, other threads:[~2007-08-18 13:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.4899.1187343204.32220.help-gnu-emacs@gnu.org>
2007-08-17 10:37 ` How do I "duplicate" a keybinding? Johan Bockgård
2007-08-18 13:59   ` Alan Mackenzie
2007-08-17  9:35 Alan Mackenzie

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.