views:

106

answers:

2

In GNU Emacs, what is [C-tab]? Consider:

(version)
"GNU Emacs 23.2.1 (i386-mingw-nt5.1.2600)
 of 2010-05-08 on G41R2F1"

(defun key-binding-test ()
  (interactive)
  (insert " key-binding-test called "))

For a single letter control character, a character constant must be used in the vector:

(global-set-key [C-l] 'key-binding-test) ; does not work
(global-set-key [?\C-l] 'key-binding-test) ; works

?\C-l can be evaluated in the *scratch* buffer:

?\C-l
12

However to bind C-Tab:

(global-set-key [?\C-tab] 'key-binding-test) ;does not work
    ; Debugger entered--Lisp error: (invalid-read-syntax "?")
(global-set-key [C-tab] 'key-binding-test) ; works

When I try to evalulate C-tab though:

C-tab ; Debugger entered--Lisp error: (void-variable C-tab)

Comparing the evaluation of the vectors:

[?\C-l] ; input
[12]    ; result

[C-tab] ; input
[C-tab] ; result

(aref [C-tab] 0) ; input
C-tab            ; result, but C-tab can not be evaulated further.
+2  A: 

Try (kbd "C-TAB"), e.g. (global-set-key (kbd "C-TAB") 'key-binding-test).

Keep in mind though that Tab itself is a control sequence (C-i), so it may not work depending on where you are. It definitely won't work on the terminal, for instance.

One thing you could try to see if emacs will even recognize C-TAB different from TAB is C-h k C-TAB. If the help shows you the help for just normal TAB, you're out of luck. Otherwise it'll say something like "<C-tab> is undefined".

Eric Warmenhoven
1) I'm trying to understand what `[C-tab]` is, I already have a way of binding to `C-Tab` with `(global-set-key [C-tab] 'key-binding-test)`
Shannon Severance
You're right that C-Tab may not always be available. For example when I log into the linux server using VT-100 emulation. It's not. But locally on a Windows XP box, it is available.
Shannon Severance
I did learn something, I had tried `(global-set-key (kbd "C-tab") 'key-binding-test)` earlier which did not work. `TAB` is case sensitive when processed by `kdb`.
Shannon Severance
+6  A: 

[C-tab] is a vector, see the manual for vectors. In there you will find that a vector is considered constant for evaluation (i.e. it evaluates to itself).

So [C-tab] evaluates to [C-tab], a vector of one element, the symbol C-tab, which you can extract like so

(aref [C-tab] 0)

Added in response to the first comment.

Another vector is:

[some-symbol another (a list of things) 9]

it has length 4

(length [some-symbol another (a list of things) 9])

It contains two symbols some-symbol and another, a list (a list of things) and an integer 9.

C-tab is a symbol just like some-symbol and another in the examples above, they have no value unless their value cell is set to something.

Trey Jackson
And `(aref [C-tab] 0)` returns `C-tab`, which I can not evaluate. So by itself, I can't seem to look at `C-tab`, but I can use a vector of `C-tab`, `[C-tab]` with `global-set-keybinding` to bind my C-TAB key. Is `C-tab` just a symbol inside the vector, and not a value? (Don't know if that question even means anything.
Shannon Severance
@ShannonSeverance Yes, it is a symbol - as I said in the second sentence. I'll add more examples to make it clearer.
Trey Jackson
@Shannon: Also, `[C-tab]` is a syntactic shorthand to `(vector 'C-tab)` (similar to `'(C-tab)` for `(list 'C-tab)`).
Gilles
From info, _(global-set-key KEY COMMAND) ... KEY is a key sequence; noninteractively, it is a string or vectorof characters or event types_. Since C-tab is not a character, and since it works, it must be an event type? So when info is talking aobut event types, they are refering to symbols that have no value, but have meaning?
Shannon Severance
@ShannonSeverance Yes, `C-tab` is an event type, you can test that with `(eventp 'C-tab)`, and find more on events in the info page for "Input Events" http://www.gnu.org/software/emacs/manual/html_mono/elisp.html#Input-Events
Trey Jackson
Thank you, now it all ties together.
Shannon Severance