Skip to content

Decide when the REPL should enter multi-line mode #5183

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

Closed
smarter opened this issue Oct 1, 2018 · 6 comments
Closed

Decide when the REPL should enter multi-line mode #5183

smarter opened this issue Oct 1, 2018 · 6 comments

Comments

@smarter
Copy link
Member

smarter commented Oct 1, 2018

Right now when pressing Enter, the REPL will add a new line instead of running the current input if:

  • the input is incomplete (eg. "class Foo {")
  • the cursor is in the middle of a line

But after experimenting with it, I think that usually when pressing enter in the middle of a line, I expect the input to be run. I suggest adding another shortcut (maybe Shift+Enter, Ctrl+Enter is not technically possible on most terminals) to signify "I want to add a new line and not run this command". (We might also need a shortcut for the opposite problem: "I want to run this command and not add a new line")

@allanrenucci
Copy link
Contributor

I asked for this in the JLine mailing list

@smarter
Copy link
Member Author

smarter commented Oct 19, 2018

Looks like we can just use alt+enter to make a newline so we should just change enter to only check if the input is incomplete.

@allanrenucci
Copy link
Contributor

allanrenucci commented Dec 20, 2018

You can make this work on the default Mac terminal by going to Terminal -> Preference -> Profiles -> Keyboard and then selecting Use Option as Meta key.

However this is not enabled by default. Do we want to move forward anyway?

@smarter
Copy link
Member Author

smarter commented Dec 20, 2018

Yes, I think so, as a fallback we can always implement Ammonite's behavior where you can force multi-line by wrapping your code in { ... }

@allanrenucci
Copy link
Contributor

allanrenucci commented Dec 20, 2018

I played a bit with ammonite and it seems it submit the buffer, only if the cursor is on the last line. I think it makes sense and is a good compromise. Always submitting would make multi-line editing cumbersome

@smarter
Copy link
Member Author

smarter commented Dec 20, 2018

Sounds reasonable to me

allanrenucci added a commit to dotty-staging/dotty that referenced this issue Dec 20, 2018
allanrenucci added a commit to dotty-staging/dotty that referenced this issue Dec 20, 2018
@odersky odersky closed this as completed in 1b33a36 Jan 4, 2019
odersky added a commit that referenced this issue Jan 4, 2019
Fix #5183: (REPL) Only insert line break when cursor is not on the last line
nicolasstucki pushed a commit to dotty-staging/dotty that referenced this issue Jan 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants