[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to separate key bindings of TAB and C-i?
From: |
Kevin Rodgers |
Subject: |
Re: How to separate key bindings of TAB and C-i? |
Date: |
Wed, 08 Nov 2006 14:04:32 -0700 |
User-agent: |
Thunderbird 1.5.0.7 (Windows/20060909) |
gniuxiao wrote:
I want to insert a tab when type TAB and indent current line when type
C-i, so I wrote the following codes:
(defun my-insert-tab()
(interactive)
(insert " "))
(global-set-key (kbd "TAB") 'my-insert-tab)
(global-set-key (kbd "C-i") 'lisp-indent-line)
(kbd "TAB") = (kbd "C-i") = "\t"
but both TAB and C-i invoke lisp-indent-line, then I changed the
setting sequence to:
(global-set-key (kbd "C-i") 'lisp-indent-line)
(global-set-key (kbd "TAB") 'my-insert-tab)
now both TAB and C-i invoke my-insert-tab.
Note that TAB/C-i may have a different binding in different buffers.
For example, in Fundamental mode, it is bound (globally) to
indent-for-tab-command. But in Lisp Interaction mode (e.g. the
*scratch* buffer) it is bound (locally) to lisp-indent-line.
I think TAB and C-i are internally stick to each other, and I wanna
know how to separate them, thanks ;-)
From the Function Keys node of the Emacs Lisp manual:
,----
|
| `backspace', `tab', `newline', `return', `delete'
| These keys correspond to common ASCII control characters that have
| special keys on most keyboards.
|
| 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 Translating Input::) 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.
`----
Try binding (kdb "<tab>") = [tab] in the global keymap.
--
Kevin