Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
581 views
in Technique[技术] by (71.8m points)

key bindings - Emacs global-set-key to C-TAB

I'm trying to set a key-binding to Ctrl+TAB in Emacs. I used the following call:

(global-set-key (read-kbd-macro "C-TAB") 'my-func)

However, whenever I use it, I get a

<C-tab> is undefined

error message. Trying to set the binding to "C-tab" results in an error message.

How can I set my binding to C-TAB?

question from:https://stackoverflow.com/questions/916797/emacs-global-set-key-to-c-tab

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Unlike others have suggested, it is a good idea to use kbd (or read-kbd-macro which is basically the same thing) in case you ever want to use the same configuration files in other versions of Emacs; kbd works across several versions of Emacs and XEmacs, where the internal representation of key sequences are different.

(global-set-key (kbd "<C-tab>") 'my-func)

The input format used by read-kbd-macro is documented in the docstring of edmacro-mode:

  • The special words RET, SPC, TAB, DEL, LFD, ESC, and NUL represent special control characters. The words must be written in uppercase.

  • A word in angle brackets, e.g., <return>, <down>, or <f1>, represents a function key. (Note that in the standard configuration, the function key <return> and the control key RET are synonymous.) You can use angle brackets on the words RET, SPC, etc., but they are not required there.

This is written somewhat unfortunately; the TAB referred to in the first bullet point is the ASCII character for TAB, and adding the Control modifier does something nonsensical to it. When you press Control-Tab, Emacs sees it (via your windowing system; it will not work in a text terminal) as <tab> with a Control modifier, which you can represent as C-<tab> or <C-tab>.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...