Re: Extend the existing alternative set of key bindings for terminals (was: Second Ctl in keychord not detected)
Ihor Radchenko writes: > Tim Cross writes: > >> Ihor Radchenko writes: >> >>> Also, it appears to me that we may keep losing terminal-incompatible >>> keys in future unless we provide some mechanisms to check terminal >>> compatibility automatically. Any ideas? >>> >> >> No ideas on this. Problem being I don't think there is anything like a >> terminfo service which will tell you about what capabilities/bindings a >> terminal emulator has. >> >> Just some thoughts on this - >> >> I fear any such attempt is likely to end up in a game of 'wack-a-mole'. >> While it makes some sense to provide alternative key bindings for Emacs >> running under the GNU Linux console, especially given the limitations >> under the console are well defined and constant, I'm not sure >> we can provide reliable solutions or tests for different terminal >> emulators (which will often 'reserve' various key bindings for their own >> use. This is especially true for more advanced terminal emulators like >> tmux. > > We cannot even handle GNU Linux console now. Technically, man 5 terminfo > describes all the details on how to obtain terminal specs, but I am not > sure how to extract useful information for key binding purposes. Can we > do it programatically? > I probably wasn't clear enough in what I was trying to explain/suggest. I'll try to clarify. I think there are two different issues at play here. Key binding limitations in the Linux console and key handling in different terminal emulators. The first is fundamentally a limitation in the low level kernel terminal driver and not much which can be done except choose alternative key bindings when running under the linux console. The second is more about limitations within the specific terminal emulator program. Some emulators handle this better than others and it will be near impossible to find key bindings which will work across all different terminal emulators unless we restrict which key bindings we use to a much smaller subset, which will inevitably mean many difficult to use or less convenient bindings. This will just make everyone, including those using more capable terminal emulators, suffer less convenient key bindings and key bindings which are significantly different from those used when running native window/GUI version. It would make switching between GUI versions and terminal versions of Emacs even less convenient. As an example, on my Ubuntu 21.10 system, when running Emacs under the Linux console, C-c C-, completely fails. In fact,if you try to do describe key for that combination, it won't work because Emacs never sees the second key press. On the other hand, if I run Emacs inside mate-terminal, Emacs will see C-c , and not C-c C-, (but it does get both key presses). If I run Emacs under xterm, lxterm or uxterm, everything actually works just fine. Describe key will report the correct binding for C-c C-, I don't believe terminfo will be of any help here. If you look at the TERM setting for mate-terminal, uxterm, lxterm and xterm, they will all reference various versions of xterm (often xterm-color or xterm-256color etc). Looking at the terminfo definitions, I cannot see anything with would indicate whether C-, for example is supported or not. I know of no convenient and consistent way to determine if the terminal emulator being used will support things like C-, or not. For the Linux console, I think we can use the TERM environment variable to know when we are running under the Linux console if we want to provide different key bindings for some commands under the Linux console. There is also the possibility you could create a keymap for the Linux console which would configure some of the 'missing' modifier combinations to issue escape sequences which can be used to emulate the modifier behaviour under GUI environment - for example, I think you can create a keymap which will allow C-up/C-dwon/C-left/C-right etc. The question is, how useful will alternative key bindings actually be for the Linux console. I imagine the user base for people who only work under the Linux console is pretty small. For occasional use, the alternative bindings are unlikely to be that useful as it is too hard to change finger memory for occasional use and you probably won't remember the different bindings anyway (I would probably just use M-x command in these situations). For the terminal emulator situation, I believe we should do nothing except provide documentation on how to find or identify an appropriate terminal emulator which will support the key bindings used by orc, such as C-c C-,.
Re: Extend the existing alternative set of key bindings for terminals (was: Second Ctl in keychord not detected)
Tim Cross writes: > Ihor Radchenko writes: > >> Also, it appears to me that we may keep losing terminal-incompatible >> keys in future unless we provide some mechanisms to check terminal >> compatibility automatically. Any ideas? >> > > No ideas on this. Problem being I don't think there is anything like a > terminfo service which will tell you about what capabilities/bindings a > terminal emulator has. > > Just some thoughts on this - > > I fear any such attempt is likely to end up in a game of 'wack-a-mole'. > While it makes some sense to provide alternative key bindings for Emacs > running under the GNU Linux console, especially given the limitations > under the console are well defined and constant, I'm not sure > we can provide reliable solutions or tests for different terminal > emulators (which will often 'reserve' various key bindings for their own > use. This is especially true for more advanced terminal emulators like > tmux. We cannot even handle GNU Linux console now. Technically, man 5 terminfo describes all the details on how to obtain terminal specs, but I am not sure how to extract useful information for key binding purposes. Can we do it programatically? > An alternative which might be worth considering would be to improve > documentation on using different popular terminal emulators, like tmux > which could cover both adapting org key bindings and adapting the key > bindings the emulator uses (a very quick google on this indicates you > can change the tmux bindings, but that detail is apparently not well > documented). Such documentation could include some guidelines on how to > identify the issue, identify at what layer (window manager, terminal > emulator, communication protocol etc) the problematic binding is being > intercepted etc. The interactions at this layer can be complex and > confusing, especially for users who don't have a clear model of how all > the layers interact. I am not aiming there for now. Just basic terminals. tmux, WMs, system-wide key bindings, etc are all higher level and can be configured by the user. We _might_ want to support the most popular shadowed bindings, but the problem with terminals is a lot more pressing. Users cannot really change what is supported. > A more long term strategy which I wonder if we should consider is > whether org would benefit from adopting the use of something like the > hydra package. Org needs a lot of key bindings - many more than most > other modes. Available bindings are in short supply. Perhaps leveraging > off something like hydras would both offer more flexibility and make it > easier to manage. Likewise, could transient mode help in this area? It may be a good idea. However, not all the users like hydra style. Note that we already have org-speed-commands. They provide somewhat similar functionality. We may extend them, allow using via transient keymap, or integrate org-speed-command-help with hydra/transient.el. Patches are welcome! Best, Ihor
Re: Extend the existing alternative set of key bindings for terminals (was: Second Ctl in keychord not detected)
Ihor Radchenko writes: > Also, it appears to me that we may keep losing terminal-incompatible > keys in future unless we provide some mechanisms to check terminal > compatibility automatically. Any ideas? > No ideas on this. Problem being I don't think there is anything like a terminfo service which will tell you about what capabilities/bindings a terminal emulator has. Just some thoughts on this - I fear any such attempt is likely to end up in a game of 'wack-a-mole'. While it makes some sense to provide alternative key bindings for Emacs running under the GNU Linux console, especially given the limitations under the console are well defined and constant, I'm not sure we can provide reliable solutions or tests for different terminal emulators (which will often 'reserve' various key bindings for their own use. This is especially true for more advanced terminal emulators like tmux. An alternative which might be worth considering would be to improve documentation on using different popular terminal emulators, like tmux which could cover both adapting org key bindings and adapting the key bindings the emulator uses (a very quick google on this indicates you can change the tmux bindings, but that detail is apparently not well documented). Such documentation could include some guidelines on how to identify the issue, identify at what layer (window manager, terminal emulator, communication protocol etc) the problematic binding is being intercepted etc. The interactions at this layer can be complex and confusing, especially for users who don't have a clear model of how all the layers interact. A more long term strategy which I wonder if we should consider is whether org would benefit from adopting the use of something like the hydra package. Org needs a lot of key bindings - many more than most other modes. Available bindings are in short supply. Perhaps leveraging off something like hydras would both offer more flexibility and make it easier to manage. Likewise, could transient mode help in this area?
Extend the existing alternative set of key bindings for terminals (was: Second Ctl in keychord not detected)
"Loris Bennett" writes: >> Then, it is terminal input problem. See >> https://stackoverflow.com/questions/0801/why-does-ctrl-not-work-when-i-bind-it-to-a-command-in-emacs/8511#8511 > > You're right, the problem also happens locally when I start Emacs with > '-nw'. Thanks for the link - I'll have a look at the various solutions, > although it might just be easier to rebind the command ;-) On Org side, we have an alternative set of key bindings that is more compatible with terminals (see org-use-extra-keys). I think that C-c C-, should also be covered there. Or maybe some other keys as well. Loris, would you be interested to check which default bindings from org-mode-map work and which don't work in tmux/terminal and report here? Also, it appears to me that we may keep losing terminal-incompatible keys in future unless we provide some mechanisms to check terminal compatibility automatically. Any ideas? Best, Ihor