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,527
  • 1
  • 19
  • 26

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,404
  • 3
  • 48
  • 85