I'm happy with a separate bug, if you prefer/are OK with that. Or I can
incorporate the text into upgrade patch, whichever you prefer.
Comments welcome ---
The jshell tool provides line editing support to allow you to navigate
within and edit snippets and commands. The current command/snippet can
be edited, or prior commands/snippets can be retrieved from history,
edited, and executed. This support is similar to readline/editline
simple emacs-like bindings. There are also jshell tool specific key
--- Line and history navigation ---
Enters the current snippet
Left-arrow or Ctrl+B
Moves backward one character
Right-arrow or Ctrl+F
Moves forward one character
Up-arrow or Ctrl+P
Moves up one line, backward through history
Down arrow or Ctrl+N
Moves down one line, forward through history
Moves to the beginning of the line
Moves to the end of the line
Moves backward one word
Moves forward one word
Search backward through history
--- Line and history basic editing ---
Meta+Return or Ctrl+Return (depending on platform)
Insert a new line in snippet
Ctrl+_ (underscore may require shift key) or Ctrl-X then Ctrl-U
Undo edit - repeat to undo more edits
Deletes the character at or after the cursor, depending on the
Deletes the character before the cursor
Deletes the text from the cursor to the end of the line
Deletes the text from the cursor to the end of the word
Deletes the text from the cursor to the previous white space
Pastes the most recently deleted text into the line
After Ctrl+Y, Meta+Y cycles through previously deleted text
Ctrl+X then Ctrl+K
Delete whole snippet
--- Shortcuts for jshell tool ---
For details, see: /help shortcuts
Complete Java identifier or jshell command
Shift+Tab then v
Convert expression to variable declaration
Shift+Tab then m
Convert statement to method declaration
Shift+Tab then i
Add imports for this identifier
--- More line and history editing ---
Clear screen and reprint snippet
Kill whole line
Ctrl+X then Ctrl+B
Navigate to matching bracket, parenthesis, ...
Ctrl+X then =
Enter show current character position mode
Ctrl+X then Ctrl+O
Toggle overwrite characters vs insert characters
Convert word to uppercase
Convert word to lowercase
Meta+0 through Meta+9 then key
Repeat the specified number of times
Where, for example, "Ctrl+A" means hold down the control key and
Where "Meta" is "Alt" on many keyboards.
Line editing support is derived from JLine 3.
Post by Jan Lahoda Post by Robert Field
Thanks for updating.
(1) The supported keys should be listed without requiring that
user knows or looks-up readline. More so, since only some readline keys
(2) "/edit" is a command, so with this change, typing "/help
would give both the /edit and editing help -- which would be confusing.
I suggest "/help keys", there are no "k" help items.
Post by Robert Field
(3) In jshell tool online docs the tool is spelled "jshell tool"
I'd be happy to write up suggested text.
Thanks, that would be very welcome!
Post by Robert Field
As to the alternative patch: I understand the motivation, it would be
nice to just use the natural "Enter" as new line. Unfortunately it's
functionality is then overloaded. I believe the alternative will be
(1) It breaks backward compatibility in user experience, Enter
always been accept/evaluate
(2) It would be very awkward and non-intuitive (particularly in a
long multiline snippet) to have to navigate to the end of the snippet to
Note: must be the end both vertically and horizontally.
(3) It is inconsistent: Mid snippet Enter on one line does
However, on a continuation line (say after "int x =") it adds a new line
(4) It doesn't solve the problem for the most common location for
adding a new line, the end of snippet -- thus introducing more
Ok. This was meant more as a backup in case there's no reasonable
shortcut we could use to add new lines.
Thanks for the comments!
Post by Robert Field
Post by Jan Lahoda
I've updated the patch to reflect the comments so far, the current
In this version, while editing a snippet, a new line can be added
using Alt-Enter (on platforms that support that), or Ctrl-Enter (on
In the alternative version, Enter will only "confirm" multi-line
snippet when the cursor is at the end of the snippet, otherwise it
will add a new line (so that a special shortcut is not needed; but a
snippet cannot be "confirmed" by pressing Enter in the middle of a
The only difference between the .01 and .01a patches is the way they
allow to add new lines into the multi-line snippets. Other changes are
Any feedback on this is welcome.
I saw no issues with JShell tool and test portions of the webrev. I
not review the nashorn changes.
Thanks for looking at this!
Testing it: editing multi-line snippets is vastly easier and more
There is one issue, with the old mechanism, as horridly clunky as it
was, you could add new lines of code (a frequently needed functionality).
Since <return> is accept, I could find no way to add lines with this
JLine 3 version. Thoughts?
One possibility that comes to mind: pressing Enter inside the snippet
would add a new line, Enter at the very end of a (complete) snippet
would confirm that snippet. Could be fairly convenient/intuitive. What
do you think?
I looked into readline commands as an approach to addressing
nothing. However, most readline commands worked. Ctrl-u however did
behave as documented in readline (instead deleting to the beginning of
the line). I notice that the there is zero in-command documentation of
command-line editing -- not even a mention. Independent from the
of this port, it seems we should have in-command documentation of
command editing -- even more so now that multiline editing is useful.
This is about enhancing /help, right? I'll see what I can do.
The JShell User Manual will also need a little edit in the History
Where is that?
Post by Jan Lahoda
I'd like to update the internal JLine used by JShell and jjs to JLine
3.9.0. Two notable advantages of this version is multi-line snippet
editing and better UI on Windows (escape sequence support on Windows).
As a consequence, this patch drops EditingHistory, as it does
to be needed anymore.
-replacement of existing JLine with the new on in
-tweaks to JLine (repackaging, eliminating references to j.u.l.Logger,
adding hooks to wrap input streams with our stop-detecting input
stream, adding unicode escapes to unicode characters, support for
Windows without JNA), adjustments to JShell and jjs
3.9.0 is not compatible with the JLine 2 branch, so the changes are
Any feedback is welcome!