Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New extended xterm key presets #256

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

choppsv1
Copy link
Contributor

@choppsv1 choppsv1 commented Jan 3, 2016

Add another preset for profiles that maps all the xterm codes I could find (used emacs xterm.el source actually for discovery). Additionally filled in where there were gaps and an obvious pattern (e.g., xterm doesn't define X-2 through X-8 where X is any combination of modifiers.

This creates mappings for all US keys on a laptop for all combinations of control, shift and option (alt). The sequences sent are alt and not meta based (which is what, for example, tmux translates meta to anyway).

@gnachman
Copy link
Owner

gnachman commented Jan 6, 2016

This looks great, thanks for putting it together! Any reason you chose to create a new preset instead of extending the existing "xterm Defaults" preset?

@choppsv1
Copy link
Contributor Author

choppsv1 commented Jan 8, 2016

So my thinking was since I did extend it a little bit (e.g., adding C-2 -> C-8) I wasn't being completely true to what xterm supported (I don't know why it doesn't suppose those in particular), I should create it's own setting.

@choppsv1
Copy link
Contributor Author

choppsv1 commented Jan 8, 2016

actually your question got me thinking what exactly did I change. Originally I started this as just a way to generate some sequences that I could then program emacs to interpret as those keys, but then decided why not use what was there from xterm. If we really want to call this Xterm++ it should probably be as close as possible for all the supported keys. So I reviewed my change in that light. It seems that for meta and meta-shift, all keys are supported simply by their being able to be sent prefixed by the escape character. So I should remove any special handling for those.

I'll update my branch/PR.

@gnachman
Copy link
Owner

Is this based on how function keys are treated as described in the last section of PC-Style Function Keys section of http://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-PC-Style-Function-Keys ?

I want to be really clear on what this key mapping does. It looks like it goes beyond what xterm does (or is there some configuration flag that gives it this behavior?). For example, why does ctrl-shift-A send CSI 27;8;65~? The 27 seems to get used a lot but I can't tell where it comes from. 8 and 65 are obviously the modifier and ASCII code, but their order is reversed versus xterm's PC-style function keys, where the modifier goes last.

If this is really a new invention (versus a tweak to xterm's existing scheme), how does it compare to libtermkey described here: http://www.leonerd.org.uk/hacks/fixterms/

Thanks for the clarification! It's important to get this right because the standards here are pretty crazy and hard to understand.

@choppsv1
Copy link
Contributor Author

You are correct many keys use the "CSI 27;mod;decchar~" sequence. I think perhaps source is simpler in this case, so here's the python I used to generate the data:

https://gist.github.com/8af4d179794c2603362e

You can see the behavior in xterm by setting modifuOtherKeys option (see http://invisible-island.net/xterm/manpage/xterm.html) and playing around in cat. I originally gleamed on to this by looking at emacs xterm.el .

This looks similar to what's being done with libtermkey (the modifiers appear to use the same ascii decimal values for shift and ctrl), but obviously there's some difference.

Actually if you check out the comment from Giles on http://emacs.stackexchange.com/questions/1020/problems-with-keybindings-when-using-terminal he mentions both efforts. I didn't realize that emacs actually enables the xterm setting modifyOtherKeys option!

@choppsv1
Copy link
Contributor Author

I was looking over my control-key exceptions in the python code and realized I missed one keyboard ascii key: space!

I'll update the branch with this key (and of course leave C-space as ^@ which is what I was originally looking for :)

@gnachman
Copy link
Owner

Good to have a name for this! We should call it "xterm modifyOtherKeys mode". What happens with non-US keyboards? Is there a general algorithm? I wonder if this should not be a preset, but if it should be implemented in code to handle these cases.

@orb
Copy link

orb commented Nov 25, 2016

I copied this into my iTerm and set the terminal type to xterm. This is pretty amazing, but I'm seeing several key sequences that don't work as expected. Many of the [27;n;n~ sequences are not recognized.

For example, C-_ sends [27;6;95~ but there's nothing in xterm.el that seems to respond to that.

Another one that doesn't work is M-S-right. This is sending [1;4C, and xterm.el has (define-key map "\e[1;4C" [M-S-right]). Everything seems in order, but it doesn't work.

@DarMontou
Copy link

@orb, it looks like @choppsv1 has a custom/extended version of xterm.el with extra bindings for things like C-_

I was having the same trouble with M-S-right resolving to M-right. I tried the same command in windows emacs and noticed a helpful message when checking the keybinding, translated from M-S-right. Which I'm guessing means that emacs truncated the command to a shorter one that is defined rather than the longer one that isn't defined. So I added the following binding and it worked as expected:

(global-set-key (kbd "M-S-<right>")
  '(lambda ()
    (interactive)
    (message "M-S-right!")))

@choppsv1
Copy link
Contributor Author

choppsv1 commented Nov 27, 2016

I think George is correct here, rather than presets iTerm should instead do this in code. There are 2 methods:

modifyOtherKeys == 1 [implied formatOtherKeys == 0] # xterm patch 214
modifyOtherKeys == 1 formatOtherKeys == 1 # xterm patch 235

The latter method is a bit nicer since it's a shorter sequence, but it is newer as well.

214 method: CSI 27 ; <modifier> ; <ascii> ~
235 method: CSI <ascii> ; <modifier> u

I think iTerm should support both methods with preference settings to enable them.

Here's where you can find the xterm changes by patch. For some reason the files are double gzipped. http://invisible-mirror.net/archives/xterm/patches/

@gnachman
Copy link
Owner

gnachman commented Dec 4, 2016

I opened an issue to track this:

https://gitlab.com/gnachman/iterm2/issues/5377

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants