stdlib icon indicating copy to clipboard operation
stdlib copied to clipboard

[RFC]: add support for custom key bindings in the REPL

Open Snehil-Shah opened this issue 1 year ago • 6 comments

Description

This RFC proposes adding support for custom key bindings in the REPL.

Some prior art:

  • Julia: supports key bindings for actions like editing, cursor movement, and program control. Here's the full list of actions

  • IPython: They also support multiple key bindings for a single action. Similar to how we have the right arrow and TAB to auto-complete a suggestion. They also have auto-closing pairs as "key bindings", to trigger the 'auto-close-parentheses' is mapped to the key (. Here's the full list of actions

We would also want to support having custom key bindings for current actions like Ctrl+O for inserting a new line, or right arrow for accepting a suggestion, or the TAB key to toggle the completions etc.

Would suggest reading the above lists of actions for further discussion on what we should support

Checklist

  • [X] I have read and understood the Code of Conduct.
  • [X] Searched for existing issues and pull requests.
  • [X] The issue name begins with RFC:.

Snehil-Shah avatar Jul 22 '24 18:07 Snehil-Shah

Most of Julia's keybindings seem reasonable. IPython's are a little hard to follow; however, some of the autosuggestion bindings could be useful.

kgryte avatar Jul 22 '24 20:07 kgryte

Should we allow multiple keybindings for an action?

Snehil-Shah avatar Jul 26 '24 04:07 Snehil-Shah

Seems fine to me.

kgryte avatar Jul 26 '24 07:07 kgryte

Should we allow configuring basic actions like backspace and moving left/right (using arrow keys) which are implemented by readline? We would have to override the default readline behavior to make it configurable.

Update: Let's just make it configurable, instead of reimplementing the behavior, we can just "pipe" the new key binding to call the old key binding sequence.

Snehil-Shah avatar Aug 01 '24 13:08 Snehil-Shah

Whatever you think makes sense. My initial thought was that supporting overriding for those keybindings seems like a rabbit hole if it means overriding readline, but if you think you have a reasonable workaround, seems fine to me.

kgryte avatar Aug 01 '24 16:08 kgryte

Should I break it into separate PRs, namely:

  • adding editor actions and keybinding support
  • updating current actions to be configurable
  • add settings and updating docs

Snehil-Shah avatar Aug 03 '24 13:08 Snehil-Shah

@Snehil-Shah This issue isn't fully closed, correct? IIUC, we still need to add settings and add support for configuration.

kgryte avatar Nov 24 '24 09:11 kgryte

We could move those tasks to separate issues to better map to expected PRs.

kgryte avatar Nov 24 '24 09:11 kgryte

@kgryte only adding settings and a couple of more actions (for existing stuff like triggering tab completions etc) is left..

Snehil-Shah avatar Nov 24 '24 10:11 Snehil-Shah