JShell: three small proposal/feedback

KUBOTA Yuji kubota.yuji at gmail.com
Mon Apr 4 10:33:17 UTC 2016


Hi REPL team,

I enjoyed debugging by using very good REPL - JShell.
And I would like to add following (small) changes for usability.

1. /edit display warn instead of quit by HeadlessException in headless mode

Unfortunately, I did not think the default editor uses swing, so I got
HeadlessException when I used /edit on a headless server, then
my working log has gone. So I want that JShell warn instead of
suddenly quit, as [1].

2. /-n return the available range rather than calculated "n"

Just to avoid small confusion as below.

Example:
-> /-9
|  Cannot find snippet 0 ( - current implementation)
|  Cannot find snippet, select <n> between 1 - 8  ( - proposal [2])

3. Implement /show command to confirm the current configuration

We can set configuration, but cannot check current configuration
except defined feedback modes by /help /set feedback.
Should we provide /show command for easy check as below?

Example for feedback mode:
-> /set newmode test
|  Created new feedback mode: test

-> /show feedback
|  Currently feedback mode: normal
|  All defined feedback mode: normal, test, off


If they accepted, I want to file them to JBS and to upload webrev when ready.
note: I'm jdk9 author, not committer.

Thanks!
Yuji

[1]: patch for /edit
diff --git a/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java
b/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java
--- a/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java
+++ b/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java
@@ -1523,7 +1585,11 @@
         Consumer<String> saveHandler = new SaveHandler(src, srcSet);
         Consumer<String> errorHandler = s -> hard("Edit Error: %s", s);
         if (editor == null) {
-            EditPad.edit(errorHandler, src, saveHandler);
+            try {
+                EditPad.edit(errorHandler, src, saveHandler);
+            } catch (HeadlessException ex) {
+               hard("Cannot launch editor in headless mode. Try /set
editor to use external editor.");
+            }
         } else {
             ExternalEditor.edit(editor, errorHandler, src, saveHandler, input);
         }

[2]: patch for /-n
diff --git a/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java
b/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java
--- a/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java
+++ b/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java
@@ -1777,7 +1843,7 @@
         if (index >= 0 && index < keys.size()) {
             rerunSnippet(keys.get(index));
         } else {
-            hard("Cannot find snippet %d", index + 1);
+            hard("Cannot find snippet, select <n> between 1 - %d",
keys.size());
             return false;
         }
         return true;


More information about the kulla-dev mailing list