The REPL design of read-eval-print-loop is confusing and difficult to use when programming. For example, user's cannot remove or modify specific lines of code. While the node.js REPL contains a save and load functionality, to write to and load from files, it doesn't have a way to view the previously written lines within the REPL.
It would be a great idea to integrate an improved editor mode that bridges the gap between REPL and code editor. Not forcing user's to put their code into an external editor means we can have a more comprehensive tool, and be able to use the user's code to help recommend snippets.
The node.js REPL already has the .editor command which is used for multiline input, but doesn't show what code has already been processed. I think for now I will just overwrite this.
I will need to make a new prompt that functions more like an editor. We could in the future allow a custom command like vim, but for now it will just be a prompt with modified keybindings and UI because that's the simplest.
The only caveat is that it appears loading in a file into the REPL runs it again, so this will need to be documented. I don't think there will be any avoiding this, as the REPL must run code to maintain it's context. And as per the general read-eval-print-loop design, this happens every line.
User Story
I been using the REPL to try out different file reading packages. I save the REPL, which is the only way I can see what code snippets I've tried besides my terminal history, but the file is messy:
const package1 = require("package1")
var result;
//#1 how to read files
result = package1.readFile("text.txt");
//#2 how to read files with a specified encoding
result = package1.readFile("text.txt", {encoding: "utf-8"});
const package2 = require("package2")
//#3 get an array of lines from a file
var result2 = package2.readLines("text.txt");
I have decided I want to use code snippet2 from package1, so I no longer need package2. However, I now want to see how package1 goes reading a larger file, and then maybe try out some other things in NCQ, so I don't want the unwanted code interfering or slowing things down.
I don't want to start a new REPL and I don't want to clear the REPL and get rid of my snippets. I just want to make changes to the lines I've already submitted.
I can't use an external editor then the .load command, as this only appends onto my existing REPL context. I would have to use .clear beforehand. And I don't really want to open up my editor just to change a few lines.
So I would enter some command like the node.js REPL editor command that already exists:
And a new prompt would open, showing me my code, and allowing me to edit it.
< NCQ EDITOR >
================================
const package1 = require("package1")
var result;
//#1 how to read files
result = package1.readFile("text.txt");
//#2 how to read files with a specified encoding
result = package1.readFile("text.txt", {encoding: "utf-8"});
const package2 = require("package2")
//#3 get an array of lines from a file
var result2 = package2.readLines("text.txt");
===============================
fn | Save | fn | Exit
I could press a button to save and a button to cancel out. I save the file as:
const package1 = require("package1")
var result;
//#2 how to read files with a specified encoding
result = package1.readFile("largeFile.txt", {encoding: "utf-8"});
Then, when I return to the REPL, this updated code will run. If I type:
The variable will now be undefined. If I looked for snippets, any snippets containing a variable result2 would no longer conflict with my code and cause errors (meaning they could be ranked higher than previously). The REPL now more accurately represents the environment I will be using this code in later.
The REPL design of read-eval-print-loop is confusing and difficult to use when programming. For example, user's cannot remove or modify specific lines of code. While the node.js REPL contains a save and load functionality, to write to and load from files, it doesn't have a way to view the previously written lines within the REPL.
It would be a great idea to integrate an improved editor mode that bridges the gap between REPL and code editor. Not forcing user's to put their code into an external editor means we can have a more comprehensive tool, and be able to use the user's code to help recommend snippets.
The node.js REPL already has the
.editorcommand which is used for multiline input, but doesn't show what code has already been processed. I think for now I will just overwrite this.I will need to make a new prompt that functions more like an editor. We could in the future allow a custom command like vim, but for now it will just be a prompt with modified keybindings and UI because that's the simplest.
The only caveat is that it appears loading in a file into the REPL runs it again, so this will need to be documented. I don't think there will be any avoiding this, as the REPL must run code to maintain it's
context. And as per the general read-eval-print-loop design, this happens every line.User Story
I been using the REPL to try out different file reading packages. I save the REPL, which is the only way I can see what code snippets I've tried besides my terminal history, but the file is messy:
I have decided I want to use code snippet2 from package1, so I no longer need package2. However, I now want to see how package1 goes reading a larger file, and then maybe try out some other things in NCQ, so I don't want the unwanted code interfering or slowing things down.
I don't want to start a new REPL and I don't want to clear the REPL and get rid of my snippets. I just want to make changes to the lines I've already submitted.
I can't use an external editor then the
.loadcommand, as this only appends onto my existing REPL context. I would have to use.clearbeforehand. And I don't really want to open up my editor just to change a few lines.So I would enter some command like the node.js REPL editor command that already exists:
And a new prompt would open, showing me my code, and allowing me to edit it.
I could press a button to save and a button to cancel out. I save the file as:
Then, when I return to the REPL, this updated code will run. If I type:
The variable will now be undefined. If I looked for snippets, any snippets containing a variable
result2would no longer conflict with my code and cause errors (meaning they could be ranked higher than previously). The REPL now more accurately represents the environment I will be using this code in later.