30

Normally, for historic reasons, emacs treats the TAB keycode and the C-i key as the same, cf. the emacs lisp documentation on function keys or abo-abo's answer on the question "What is the difference between TAB and ?".

NOTE: In this post, keycodes are TAB, <tab>, and C-i; tab and Ctrl + i on the other hand are the physical keys on the keyboard.

However, at the moment, emacs treats the TAB and C-i as the same thing, i.e. (equal (kbd "TAB") (kbd "C-i")) -> t.

However, since we are no longer living in the stoneage of computing I find this extremely annoying. There's a few suggestions out there what can be done to work around this, e.g.

  • "How do I bind a command to C-i without changing TAB?"

    • Trey's Solution did not work for my, the variable local-function-key-maps is not changed. Modifying it to use delete rather than delq does result in a modified variable but it does not bring resolve ... tab and Ctrl+i are still the same.
    • Translating to the hyper map seems like a 1980s workaround ... I might want to use Hyper+i as well.
  • Using the input-decode-map to map Ctrl+i to some post-ASCII control code is almost what I'm looking for. Except that it does not work properly with the kbd macro meaning that one must modify all bits of source code that will bind Ctrl + i. Arguably this is the best solution given that all source code is modified properly.

  • Using (kbd "<tab>") for tab and (kbd "C-i") (which translates to (kbd "TAB") i.e. the \t literal) for Ctrl+i does work but you'd have to modify all source files which use the wrong kind of tab [Read: the keycode TAB] which is annoying.
    This has been suggested e.g. in a github issue and on emacs.sx as well.

None of these solutions seem real solutions, I'd rather consider them workarounds or hacks (of the existing bug).

Is there a way out there to force emacs to map tab to (kbd "<tab>") and (kbd "TAB") while Ctrl+i is mapped to (kbd "C-i") short of modyfing the emacs source code?

This approach should be completely invisible to the user, meaning that the tab like keycodes <tab> and TAB should map to one binding whilst the Ctrl+i like keycode C-i should map to another binding.

On a less serious note: Any emacs developers here who can comment whether this will be changed / fixed in the emacs source code at some point?

elemakil
  • 2,517
  • 1
  • 18
  • 26
  • 2
    Note that `TAB` and `C-i` (the codes, not the keys) are one and the same by definition of `TAB`. – Stefan Oct 19 '15 at 16:36
  • @Stefan That's why I added the _Note_ thing. I'm going to edit the post and put it in there. – elemakil Oct 19 '15 at 16:39
  • Possible duplicate of [How to bind C-i as different from TAB?](http://emacs.stackexchange.com/questions/220/how-to-bind-c-i-as-different-from-tab) – Gilles 'SO- stop being evil' Feb 14 '16 at 00:39
  • 1
    IMO, this question is not a duplicate, because it wants to relocate all keybindings defined on TAB (even those from external packages), to use instead. While the other question was asking how to differentiate them in your own code. – Malabarba Feb 14 '16 at 01:30
  • My suggestion would be to advise `kbd` to translate TAB as [tab]. It just won't work for the preloaded parts of Emacs. – Malabarba Feb 14 '16 at 01:32
  • @Malabarba That was what the previous question asked for, too. It got an answer that only covered part of the job, but that doesn't make the question less of a duplicate. I've now posted a more thorough answer. – Gilles 'SO- stop being evil' Feb 14 '16 at 03:14

1 Answers1

29

The future is long gone, and the stone age of computing is just about to come. All text terminals I know still send the exact same byte-sequence to Emacs for C-i as for TAB, so the original need to "unify" them is still very much with us.

The input-decode-map (à la (define-key input-decode-map "\C-i" [C-i])) is probably about as good as it gets right now.

As Emacs ex-maintainer, I'd welcome a better solution to this problem, so as to free up the C-i (and C-m and C-[) keys under GUIs (probably make them "reserved for the user"). But I don't know how to do that without causing lots of problems with existing packages.

Stefan
  • 26,154
  • 3
  • 46
  • 84
  • [The bronze age has arrived, but so far in xterm only](http://emacs.stackexchange.com/questions/220/how-to-bind-c-i-as-different-from-tab/20290#20290) – Gilles 'SO- stop being evil' Feb 14 '16 at 03:14
  • Wonder what kind of keyboards do you use? With the typical QWERT keyboards the distinction is just apparent, and not being able to distinguish these keys is such a pain... – Joseph Tesfaye Dec 03 '19 at 03:42