Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Showing all sequences bound to a prefix?

4 views
Skip to first unread message

Elena

unread,
Sep 2, 2009, 6:28:03 AM9/2/09
to
Hello,

how can you know all keybindings which start with a key? For instance,
"C-h c" asks me to enter a key. If I enter "C-w" it waits for more
input, which means that "C-w" is a prefix.

Thanks

Anselm Helbig

unread,
Sep 2, 2009, 6:36:13 AM9/2/09
to
At Wed, 2 Sep 2009 03:28:03 -0700 (PDT),

Use C-h, e.g. `C-x r C-h' will show you all key bindings starting with
`C-x r'.

HTH,

Anselm


--
Anselm Helbig
mailto:anselm.helb...@googlemail.com

Peter Dyballa

unread,
Sep 2, 2009, 9:01:33 AM9/2/09
to Elena, help-gn...@gnu.org

Am 02.09.2009 um 12:28 schrieb Elena:

> how can you know all keybindings which start with a key?


C-h b, copy the output to *scratch* buffer for example or make the
*Help* writable, sort the lines. Or apply a shell command with sort
on the *Help* buffer's contents. Then you could grep for what you are
interested...

--
Greetings

Pete

"A designer knows he has arrived at perfection not when there is no
longer anything to add, but when there is no longer anything to take
away."
– Antoine de Saint-Exupéry

Drew Adams

unread,
Sep 2, 2009, 11:04:28 AM9/2/09
to Anselm Helbig, help-gn...@gnu.org
> > how can you know all keybindings which start with a key?
> For instance,
> > "C-h c" asks me to enter a key. If I enter "C-w" it waits for more
> > input, which means that "C-w" is a prefix.
>
> Use C-h, e.g. `C-x r C-h' will show you all key bindings starting with
> `C-x r'.

That doesn't always work. Try C-s C-h, for instance.

Drew Adams

unread,
Sep 2, 2009, 11:04:33 AM9/2/09
to Elena, help-gn...@gnu.org
> how can you know all keybindings which start with a key? For instance,
> "C-h c" asks me to enter a key. If I enter "C-w" it waits for more
> input, which means that "C-w" is a prefix.

Icicles key completion.
http://www.emacswiki.org/emacs/Icicles_-_Key_Completion

(BTW, C-w is not normally a prefix key in Emacs. You or some library you load
has defined it as a prefix key.)

If C-w is a prefix key for you, then C-w S-TAB shows you all of the completions
for C-w: each suffix key with its associated command. Similarly, `C-x r S-TAB'
shows all of the completions of prefix key `C-x r':

..
+ = increment-register
b = bookmark-jump
c = clear-rectangle
C-@ = point-to-register
C-SPC = point-to-register
d = delete-rectangle
f = frame-configuration-to-register
g = insert-register
i = insert-register
j = jump-to-register
k = kill-rectangle
l = bookmark-bmenu-list
n = number-to-register
o = open-rectangle
r = copy-rectangle-to-register
s = copy-to-register
SPC = point-to-register
t = string-rectangle
w = window-configuration-to-register
x = copy-to-register
y = yank-rectangle

While completing, you can get the full help (in *Help*) for any key/command, by
cycling to it and hitting `C-M-RET'. For example, cycling to the third
completion, `c = clear-rectangle', and hitting `C-M-RET', shows this:

,----
| clear-rectangle is an interactive autoloaded Lisp function in `rect'.
|
| It is bound to C-x r c.
|
| (clear-rectangle START END &optional FILL)
|
| Blank out the region-rectangle.
| The text previously in the region is overwritten with blanks.
|
| When called from a program the rectangle's corners are START and END.
| With a prefix (or a FILL) argument, also fill with blanks the parts of the
| rectangle which were empty.
|
`----

You don't need to cycle - you can use completion instead. And you can filter
completion candidates by just typing some text. For example, type `rect' to
narrow the completions of `C-x r' to those keys that act on rectangles:

c = clear-rectangle
d = delete-rectangle
k = kill-rectangle
o = open-rectangle
r = copy-rectangle-to-register
t = string-rectangle
y = yank-rectangle

Once you've chosen a completion, hit RET to use it, or C-g to quit. IOW, you can
use this either to complete a key, performing its action, or just to get help on
keys.

Anselm Helbig

unread,
Sep 2, 2009, 11:35:31 AM9/2/09
to
At Wed, 2 Sep 2009 08:04:28 -0700,

C-s is not a key sequence, in that case you can always use C-h k. Do
you have a better example for when C-h breaks? I agree that it is not
guaranteed to work, but it's a well established convention not to bind
C-h in a key sequence to something else.

Anselm Helbig

unread,
Sep 2, 2009, 11:55:31 AM9/2/09
to
At Wed, 2 Sep 2009 08:04:33 -0700,

"Drew Adams" <drew....@oracle.com> wrote:
>
> > how can you know all keybindings which start with a key? For instance,
> > "C-h c" asks me to enter a key. If I enter "C-w" it waits for more
> > input, which means that "C-w" is a prefix.
>
> Icicles key completion.

But this only works with Iciclemacs, of course. 8;-)

Drew Adams

unread,
Sep 2, 2009, 12:40:41 PM9/2/09
to Anselm Helbig, help-gn...@gnu.org
> > > > how can you know all keybindings which start with a key?
> > > > For instance, "C-h c" asks me to enter a key. If I enter
> > > > "C-w" it waits for more input, which means that "C-w"
> > > > is a prefix.
> > >
> > > Use C-h, e.g. `C-x r C-h' will show you all key bindings
> > > starting with `C-x r'.
> >
> > That doesn't always work. Try C-s C-h, for instance.
>
> C-s is not a key sequence

Huh? The only reason `C-s C-h' does not work (show you the isearch bindings) is
because RMS did not want it to work. He prefers that `C-h' break out of isearch
(and so initiate global help).

(isearch+.el does let `C-s C-h' give you isearch help, including listing all of
the bindings - http://www.emacswiki.org/emacs/IsearchPlus)

> in that case you can always use C-h k.

How will C-h k help you discover the isearch keys? Sure, if you already know
that `C-s M-s w' is one of the isearch keys, then you can use `C-h k C-s M-s w'
to discover that its command is `isearch-toggle-word'. But you can't discover
the keys using `C-h k' (except by trying all keys).

`C-h f isearch-forward' gives you information about the isearch keys.

Another possibility for listing the keys in the `isearch-mode-map' is to use
library help-fns+.el, and use `C-h C-k isearch-mode-map'.
http://www.emacswiki.org/emacs/HelpPlus

> Do you have a better example for when C-h breaks?

Not offhand. I used to know some, but things change with every version of Emacs,
and I've fixed this long ago locally, so I don't keep track of which
combinations don't work in vanilla Emacs. Maybe `C-s C-h' is the only one
nowadays - dunno.

> I agree that it is not guaranteed to work, but it's a well
> established convention not to bind C-h in a key sequence to
> something else.

Agreed: (a) it might not work (my point), and (b) it's good to let it work, when
it does.

And it's good that you mentioned `C-h' as a means to discover the suffix keys
for a prefix key. I just wanted to point out that it might not work in some
cases.

Drew Adams

unread,
Sep 2, 2009, 12:47:13 PM9/2/09
to Anselm Helbig, help-gn...@gnu.org
> > > how can you know all keybindings which start with a key?
> > > For instance, "C-h c" asks me to enter a key. If I enter
> > > "C-w" it waits for more input, which means that "C-w" is a prefix.
> >
> > Icicles key completion.
>
> But this only works with Iciclemacs, of course. 8;-)

Of course. ;-)

To be clear, it works with GNU Emacs 22 and 23, in Icicle minor mode (after
loading the Icicles libraries). If you turn off Icicle mode, it stops working
until you turn it on again. ;-)


Kevin Rodgers

unread,
Sep 3, 2009, 12:19:11 AM9/3/09
to help-gn...@gnu.org
Drew Adams wrote:
>>>>> how can you know all keybindings which start with a key?
>>>>> For instance, "C-h c" asks me to enter a key. If I enter
>>>>> "C-w" it waits for more input, which means that "C-w"
>>>>> is a prefix.
>>>> Use C-h, e.g. `C-x r C-h' will show you all key bindings
>>>> starting with `C-x r'.
>>> That doesn't always work. Try C-s C-h, for instance.
>> C-s is not a key sequence

I think Anselm meant "C-s is not a prefix key".

> Huh? The only reason `C-s C-h' does not work (show you the isearch bindings) is
> because RMS did not want it to work. He prefers that `C-h' break out of isearch
> (and so initiate global help).

`C-s C-h' does not work the way e.g. `C-x r C-h' works because `C-s' is not a
prefix key. `C-s C-h' does not work the way you and I want it to work because
`C-s' invokes a transient mode (incremental search) with its own keymap, which
implies that `C-h' must be bound to mode-specific command in that keymap, and
RMS prefers a different binding than we do.

> (isearch+.el does let `C-s C-h' give you isearch help, including listing all of
> the bindings - http://www.emacswiki.org/emacs/IsearchPlus)

Or just put this in your ~/.emacs:

(define-key isearch-mode-map "\C-h" 'isearch-mode-help)

--
Kevin Rodgers
Denver, Colorado, USA

Drew Adams

unread,
Sep 3, 2009, 1:32:35 AM9/3/09
to Kevin Rodgers, help-gn...@gnu.org
> > The only reason `C-s C-h' does not work (show you the
> > isearch bindings) is because RMS did not want it to work.
> > He prefers that `C-h' break out of isearch
> > (and so initiate global help).
>
> `C-s C-h' does not work the way e.g. `C-x r C-h' works
> because `C-s' is not a prefix key.

The discussion wasn't only about working "the way C-x r C-h works" - the goal
was to see the isearch key bindings. Which is why I explicitly said "does not
work (show you the isearch bindings)".

The "does not work" in this general sense of showing you the isearch bindings is
not "because C-s is not a prefix key". That explains why `C-s' doesn't work the
same as `C-x r', but it doesn't explain why `C-s C-h' doesn't show you isearch
help (bindings).

There is nothing about not being a prefix key that prevents having C-s C-h show
the isearch bindings. As has been said, it can easily be made to work (show the
bindings), by just binding C-h to isearch-mode-help in isearch-mode-map. It's
not a technical problem.

The *reason* that that binding has not been made in Emacs (it has been proposed
several times), and thus the reason that C-s C-h does not work (does not show
you the isearch bindings), is because Richard does not want C-h during isearch
to offer isearch help. He wants it to exit isearch and offer global, top-level
help. It is not a technical reason, but a UI choice.

> `C-s C-h' does not work the way you and I want it to work because
> `C-s' invokes a transient mode (incremental search) with its
> own keymap, which implies that `C-h' must be bound to
> mode-specific command in that keymap,

Yes.

> and RMS prefers a different binding than we do.

Yes.

But there is no relation between the last clause and the first part of the
sentence. The first part explains why C-s C-h doesn't _automatically_ work (the
way C-x r C-h does). But all that matters for the desired result is the second
part: it wasn't implemented because of a UI design choice - the implementation
is then irrelevant.

Anselm Helbig

unread,
Sep 3, 2009, 2:38:19 AM9/3/09
to
At Wed, 2 Sep 2009 22:32:35 -0700,

"Drew Adams" <drew....@oracle.com> wrote:
>
> > > The only reason `C-s C-h' does not work (show you the
> > > isearch bindings) is because RMS did not want it to work.
> > > He prefers that `C-h' break out of isearch
> > > (and so initiate global help).
> >
> > `C-s C-h' does not work the way e.g. `C-x r C-h' works
> > because `C-s' is not a prefix key.
>
> The discussion wasn't only about working "the way C-x r C-h works" - the goal
> was to see the isearch key bindings. Which is why I explicitly said "does not
> work (show you the isearch bindings)".

Well, you want to discuss it, Drew. 8;-) The OP wanted to find out
about key sequences with a common prefix.

Drew Adams

unread,
Sep 3, 2009, 3:42:54 AM9/3/09
to Anselm Helbig, help-gn...@gnu.org
> > The discussion wasn't only about working "the way C-x r C-h
> > works" - the goal was to see the isearch key bindings.
> > Which is why I explicitly said "does not
> > work (show you the isearch bindings)".
>
> Well, you want to discuss it, Drew. 8;-) The OP wanted to find out
> about key sequences with a common prefix.

Oops; you're right, and I'm wrong.

I lost sight of the original question, and somehow thought it was about C-s C-h.
Your explanation and Kevin's were 100% apropos the question.

Sorry about that.

Bernardo

unread,
Sep 3, 2009, 6:26:12 AM9/3/09
to help-gn...@gnu.org

>
> Huh? The only reason `C-s C-h' does not work (show you the isearch bindings) is

somewhat off topic, but still interesting - C-s C-h b will do the trick

,----[ (info "(emacs) Special Isearch") ]
| ...
| When incremental search is active, you can type `C-h C-h' to access
| interactive help options, including a list of special keybindings.
| These keybindings are part of the keymap `isearch-mode-map' (*note
| Keymaps::).
`----


Message has been deleted
0 new messages