all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* How to separate key bindings of TAB and C-i?
@ 2006-11-08  5:07 gniuxiao
  2006-11-08 21:04 ` Kevin Rodgers
  0 siblings, 1 reply; 2+ messages in thread
From: gniuxiao @ 2006-11-08  5:07 UTC (permalink / raw)


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)

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.

I think TAB and C-i are internally stick to each other, and I wanna
know how to separate them, thanks ;-)

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: How to separate key bindings of TAB and C-i?
  2006-11-08  5:07 How to separate key bindings of TAB and C-i? gniuxiao
@ 2006-11-08 21:04 ` Kevin Rodgers
  0 siblings, 0 replies; 2+ messages in thread
From: Kevin Rodgers @ 2006-11-08 21:04 UTC (permalink / raw)


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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-11-08 21:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-11-08  5:07 How to separate key bindings of TAB and C-i? gniuxiao
2006-11-08 21:04 ` Kevin Rodgers

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.