Search code examples
macosemacselisp

<tab> v. TAB in emacs


I'm using emacs 24.3 in the OS X terminal, and have run into something strange.

In markdown-mode.el, the tab key is bound to a specific function in the keymap via (define-key map (kbd "<tab>") 'markdown-cycle), but for some reason this wasn't registering for me (though other parts of the keymap were working fine).

What fixed this was changing <tab> to TAB in the above. Is this something wonky in the OS X terminal? Is there a way to fix this; I feel like this shouldn't occur.


Solution

  • I believe markdown-mode should be using TAB, not <tab>.

    As far as I can tell, <tab> is the Tab key on the keyboard, and TAB is control-I, or ascii character 9 (written \t or \x09). The Tab key doesn't have an ascii value.

    In GUI Emacs, Emacs sees that you pressed the Tab key (<tab>) and converts it to C-i (TAB) by default. Emacs can distinguish Tab and C-i, but converts Tab to C-i unless you specifically bind <tab> to something else (which markdown-mode does).

    In the terminal, the terminal converts the Tab key to C-i (ascii 9), and Emacs sees only C-i. Emacs can't distinguish the two because they both show up as C-i.

    The same thing happens with <return> vs RET (C-m, ascii 13).