Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

<tab> v. TAB in emacs

Tags:

emacs

macos

elisp

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.

like image 733
Arpon Avatar asked Oct 04 '14 18:10

Arpon


2 Answers

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).

like image 118
amitp Avatar answered Nov 02 '22 04:11

amitp


Using TAB with define-key should automatically bind whatever event your keyboard sends for the key labeled "Tab", whether it is the ASCII TAB character, also known as C-i (Control + i) or something else -- including what Emacs writes as the pseudo-function key <tab>.

This might not work automatically in all cases. If it does not work for your particular keyboard then use C-h k and hit your Tab key, to find out what it is bound to. Whatever Emacs tells you is the key sequence, try binding that. For example, if it tells you that the key sequence is <foobar> then use (kbd "<foobar>").

But in most cases, all you need to do is use (kbd "TAB") (or "\C-i" or [control ?i]).

like image 22
Drew Avatar answered Nov 02 '22 03:11

Drew