Send "C-(" to Emacs in VT100/xterm terminal (Mac OS X's Terminal)?
Asked Answered
F

1

10

Is it possible in any way to send the key "C-(" to Emacs over a VT100/xterm terminal (Mac OS X Terminal)? Is there an escape sequence that could be sent to achieve the equivalent?

I suspect the fundamental problem is that the concept of combining control with the character "(" (and other such characters that are produced using shift) does not exist.

Note: Using Cocoa Emacs is not an option. And the reason for needing "C-(" is that paredit.el uses it amongst other key combinations, and it would be preferable to not remap it (because it makes sense to have it on "C-(").

Flog answered 2/12, 2010 at 17:21 Comment(0)
D
16

A VT100 terminal couldn't do that, because there is no ^( control character corresponding to (. However, xterm has the so-called "modifyOtherKeys" mode, which does allow to send unique keycodes for combinations like that.

To enable it, set the modifyOtherKeys resource, e.g. in ~/.Xdefaults:

XTerm*vt100.modifyOtherKeys: 1

With that, Ctrl+( will send the following keycode:

^[[27;6;40~

That's rather long though, so another format for keycodes like that was introduced, which can be enabled by setting the formatOtherKeys resource:

XTerm*vt100.formatOtherKeys: 1

With that, Ctrl+( sends:

^[[40;6u

In both of these keycodes, the 40 is the decimal ASCII code for (, and the 6 represents the Ctrl.

See man xterm and http://invisible-island.net/xterm/ctlseqs/ctlseqs.html for further details. No idea whether Terminal.app supports any of it.

Dextrality answered 2/12, 2010 at 21:38 Comment(3)
Thank you, this is almost spot on. Part of the puzzle was finding the escape code which would generate "C-(", which you provided -- I managed to verify it also works in MacOS X's Terminal. Now however I noticed that MacOS X's Terminal unfortunately does not provide for mapping arbitrary keys (in this case, Ctrl + parenthesis) to escape sequences -- only function, arrow and a few other keys can be mapped.Flog
iTerm2 will allow you to remap arbitrary keys to escape sequences.Yorktown
Over 4 years old and still saving peoples behinds. Good guy @Dextrality :)Grate

© 2022 - 2024 — McMap. All rights reserved.