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

Binding C-i without losing <tab> functionality

113 views
Skip to first unread message

Joseph Peterson

unread,
Oct 23, 2008, 8:56:03 PM10/23/08
to help-gn...@gnu.org
Hello all,

I'm trying to bind C-i to isearch-forward, but I'm having some problems.

It doesn't change anything when I do this or variations of this:
(global-set-key [?\C-i] 'isearch-forward)

Sometimes it seems like it will work, but it rebinds the tab key, too
(I may be remembering when I bound TAB, though...)

If I bind both <tab> and C-i, then it seems that I can rebind C-i to be
different than <tab>. Like this:
(global-set-key [tab] 'c-indent-command)
(global-set-key [?\C-i] 'isearch-forward)

Then it seems to work, but then I lose all the mode-specific bindings.
(Most annoying is the loss of mini-buffer completion). How do I bind
C-i without affecting the Tab key?

Thanks all,
-JEEP
Joe Peterson



Paul R

unread,
Oct 24, 2008, 4:35:12 AM10/24/08
to jeepe...@yahoo.com, help-gn...@gnu.org
On Thu, 23 Oct 2008 17:56:03 -0700 (PDT), Joseph Peterson <jeepe...@yahoo.com> said:

Joseph> Hello all, I'm trying to bind C-i to isearch-forward, but I'm
Joseph> having some problems.

Some devices are known to treat C-i and TAB as the same signal, as
well as C-m and RET. I think this is why it is not so easy to
dissociate them in emacs, even when your device allows it.

--
Paul


Xah

unread,
Oct 24, 2008, 4:44:27 AM10/24/08
to

not sure if you can. Because i think internally Ctrl+i and Tab are
both rerpresented by ascii 9. (ascii 9 is named Horizontal Tab with
standard notation ^I)

similar other pairs i noticed are Return and Ctrl+m (which is ascii
13; ^M).

i might be wrong though.

Reference:
http://xahlee.org/elisp/Character-Type.html

quote: «
Control characters may be represented using yet another read syntax.
This consists of a question mark followed by a backslash, caret, and
the corresponding non-control character, in either upper or lower
case. For example, both `?\^I' and `?\^i' are valid read syntax for
the character C-i, the character whose value is 9.

Instead of the `^', you can use “C-”; thus, `?\C-i' is equivalent to `?
\^I' and to `?\^i':

?\^I ⇒ 9 ?\C-I ⇒ 9
»

Xah
http://xahlee.org/


Andreas Politz

unread,
Oct 24, 2008, 5:30:17 AM10/24/08
to

This looks like the answer :


,----[ (info "(elisp)Function Keys") ]
| In ASCII, `C-i' and <TAB> are the same character. If the terminal
| can distinguish between them, Emacs conveys the distinction to
| Lisp programs by representing the former as the integer 9, and the
| latter as the symbol `tab'.
|
| Most of the time, it's not useful to distinguish the two. So
| normally `function-key-map' (*note Translation Keymaps::) is set
| up to map `tab' into 9. Thus, a key binding for character code 9
| (the character `C-i') also applies to `tab'. Likewise for the
| other symbols in this group. The function `read-char' likewise
| converts these events into characters.
`----

(member '(tab . [9]) function-keymap)

-ap

jeep

unread,
Oct 24, 2008, 11:32:40 AM10/24/08
to
> Some devices are known to treat C-i and TAB as the same signal, as
> well as C-m and RET. I think this is why it is not so easy to
> dissociate them in emacs, even when your device allows it.

I can disassociate them... if I set them both. My understanding is
that
C-i and <tab> are both, by default, set to ASCII character 9, which is
given the notation TAB.

If I set both "C-i" and "<tab>", then C-i and the tab key do different
things.
Unfortunately, many modes bind the tab key differently. I want to keep
all those other bindings while reassigning C-i.

It's the same thing with <return> and C-m. They are both aliased to
RET (ASCII 13). But the following code works fine:
(global-set-key [return] 'newline)
(global-set-key [?\C-m] 'open-line)

I don't know how to make one different than the other without binding
them both. The <tab> is so useful, I don't want to globally rebind it.
I only want C-i rebound.

-JEEP

jeep

unread,
Oct 24, 2008, 11:40:34 AM10/24/08
to
On Oct 24, 2:30 am, Andreas Politz <poli...@fh-trier.de> wrote:
> (member '(tab . [9]) function-keymap)

Would you mind explaining this a little? I cannot evaluate that in
emacs. And I don't understand what it's supposed to do.

Thanks,
-JEEP

Andreas Politz

unread,
Oct 24, 2008, 1:37:37 PM10/24/08
to

I forgot a hyphen. The thing is called `function-key-map'.

(member '(tab . [9]) function-key-map)

After reading the mentioned info page (what you should have done as well)
, I would do it like so:

1. Don't translate tab into C-i.
(define-key function-key-map [tab] nil)

2. Swap the meanings of tab and C-i.
(define-key key-translation-map [9] [tab])
(define-key key-translation-map [tab] [9])

3. Bind tab (which is now actually C-i)
(global-set-key [tab] 'isearch-forward)

Note that I am an emacs newbie as well, so I can't tell what
sideeffects this has. But it seems to work. Unless the system
can't differentiate this 2 keys, like in an xterm.

-ap

jeep

unread,
Oct 24, 2008, 2:45:44 PM10/24/08
to
Thank you! That seems to work. I'll post again if I find any weird
side effects.

> After reading the mentioned info page (what you should have done as well)

In my defense, I did read the info page... I just didn't understand
it. *blush*
I should have mentioned that, I guess.

Thanks,
-JEEP

jeep

unread,
Oct 25, 2008, 1:13:05 AM10/25/08
to
> 1. Don't translate tab into C-i.
> (define-key function-key-map [tab] nil)
> 2. Swap the meanings of tab and C-i.
> (define-key key-translation-map [9] [tab])
> (define-key key-translation-map [tab] [9])
> 3. Bind tab (which is now actually C-i)
> (global-set-key [tab] 'isearch-forward)

I really do appreciate the help and I'm sorry that I'm being a bit
dense, but I want to understand this.

This works for what I want to do, but I still don't grok it. I
understand all the steps, but now... if I want to reassign the tab
key, how would I go about doing that? Everything I try seems to fail,
just like it did before for C-i. I've been reading info for hours now
and I understand a lot more about emacs, but this still bothers me.

Thanks a lot.
-JEEP

Andreas Politz

unread,
Oct 25, 2008, 6:02:39 AM10/25/08
to

What are you doing and what doesn't work ?

-ap

jeep

unread,
Oct 29, 2008, 1:29:24 AM10/29/08
to

Sorry, I don't recall what I was doing wrong, but I managed to figure
it out. I guess I just needed a day to let things soak in.

Thanks!
-JEEP

0 new messages