Skip to content

repl: Add editor mode support - #7275

Closed
princejwesley wants to merge 6 commits into
nodejs:masterfrom
princejwesley:repl-paste-mode
Closed

repl: Add editor mode support#7275
princejwesley wants to merge 6 commits into
nodejs:masterfrom
princejwesley:repl-paste-mode

Conversation

@princejwesley

@princejwesleyprincejwesley commented Jun 12, 2016

Copy link
Copy Markdown
Contributor
Checklist
  • make -j4 test (UNIX) or vcbuild test nosign (Windows) passes
  • a test and/or benchmark is included
  • documentation is changed or added
  • the commit message follows commit guidelines
Affected core subsystem(s)

repl, doc

Description of change

Enabling paste editor mode support for REPL (inspired by scala REPL).

>node>.editor// Entering editor mode (^D to finish, ^C to cancel)functiontest(){console.log('tested!');}test();// ^Dtested!undefined>

@nodejs-github-botnodejs-github-bot added the repl Issues and PRs related to the REPL subsystem. label Jun 12, 2016
@benjamingr

benjamingr commented Jun 12, 2016

Copy link
Copy Markdown
Member

I think this change needs to be voted on or at least discussed first - but personally I'm in favor - thanks for the contribution!

@TrottTrott added the semver-minor PRs that contain new features and should be released in the next minor version. label Jun 12, 2016
@Trott

Copy link
Copy Markdown
Member

Can you add a test for paste mode? Existing repl tests are in test/parallel/test-repl*.

@princejwesley

Copy link
Copy Markdown
ContributorAuthor

@Trott Done!

@Trott

Copy link
Copy Markdown
Member

/cc @Fishrock123

@Fishrock123Fishrock123 self-assigned this Jun 13, 2016
Comment threadtest/parallel/test-repl-.paste.js Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code looks strange because of the indentation. Maybe change it to string concatenations.

@Trott

Copy link
Copy Markdown
Member

The doc could probably use some information about what paste mode is.

@Trott

Copy link
Copy Markdown
Member

Based on git shortlog -n -s lib/repl.js --since 'one year ago', /cc @thefourtheye@bnoordhuis@addaleax

@Fishrock123

Copy link
Copy Markdown
Contributor

Based on git shortlog -n -s lib/repl.js --since 'one year ago'

Keep in mind that more of us have touched the internal module.

I probably won't get to taking a look soon, but I'll leave my assignee as a self reminder for now.

Comment threadlib/repl.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably line up with e instanceof Recoverable…

Comment threadlib/repl.js Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better as a .prototype method?

@Fishrock123

Copy link
Copy Markdown
Contributor

Could someone elaborate on the benefits of this vs just normally pasting? Is it because you can edit the paste?

@Fishrock123

Copy link
Copy Markdown
Contributor

@princejwesley

princejwesley commented Jun 17, 2016

Copy link
Copy Markdown
ContributorAuthor

@Fishrock123

  • All lines of code entered in the paste mode will be executed at one shot. No more guesses on whether the emitted error is recoverable or not! It fixes most of the multiline mode issues.
  • Even though its called paste mode (copied the name and idea from scala REPL), Its precisely an instant, line buffered editor (Lazy multiline mode).
  • In paste mode, tab completion, history navigation shortcuts are turned off. All other terminal shortcuts are preserved
  • We can cancel the whole input but the history is preserved since terminal is line buffered(Worked the same way like scala REPL)

@Fishrock123

Copy link
Copy Markdown
Contributor

@princejwesley Shouldn't tab completion still work?

Sounds like I should give this a try. I'm not so sure .paste is appropriate... maybe .editor?

@princejwesley

Copy link
Copy Markdown
ContributorAuthor

@Fishrock123 Yes. .editor is good. I turned off tab complete to keep editor clean from tab completion output! Comment those statements and try!

@princejwesley

Copy link
Copy Markdown
ContributorAuthor

@princejwesley

Copy link
Copy Markdown
ContributorAuthor

CI is green

@trevnorris

Copy link
Copy Markdown
Contributor

@princejwesley To confirm, there's nothing here that checks for tab press anymore (i.e. would conflict with #7754)?

@princejwesley

Copy link
Copy Markdown
ContributorAuthor

@trevnorris Good point. I'll pull the patch and test locally.

@princejwesley

Copy link
Copy Markdown
ContributorAuthor

```js
> node
> .editor
// Entering editor mode (^D to finish, ^C to cancel)
function test() {
console.log('tested!');
}
test();
// ^D
tested!
undefined
>
```
@princejwesley

Copy link
Copy Markdown
ContributorAuthor

@princejwesley

Copy link
Copy Markdown
ContributorAuthor

Irrelevant CI failures: #3520, #3626, #3550@Fishrock123

@jasnell

Copy link
Copy Markdown
Member

New run to see if we can get all green... https://ci.nodejs.org/job/node-test-pull-request/3551/

@princejwesley

Copy link
Copy Markdown
ContributorAuthor

@jasnell CI is green

@jasnell

Copy link
Copy Markdown
Member

Woo! 😀 LGTM, let's land it

princejwesley added a commit that referenced this pull request Aug 6, 2016
```js
> node
> .editor
// Entering editor mode (^D to finish, ^C to cancel)
function test() {
console.log('tested!');
}
test();
// ^D
tested!
undefined
>
```
PR-URL: #7275
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
@princejwesley

Copy link
Copy Markdown
ContributorAuthor

Landed in b779eb42

@cjihrigcjihrig mentioned this pull request Aug 8, 2016
cjihrig pushed a commit that referenced this pull request Aug 10, 2016
```js
> node
> .editor
// Entering editor mode (^D to finish, ^C to cancel)
function test() {
console.log('tested!');
}
test();
// ^D
tested!
undefined
>
```
PR-URL: #7275
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
@cjihrigcjihrig mentioned this pull request Aug 11, 2016
cjihrig added a commit that referenced this pull request Aug 11, 2016
Notable changes:
* build: zlib symbols and additional OpenSSL symbols are now exposed on Windows platforms. (Alex Hultman) #7983 and #7576
* child_process, cluster: Forked child processes and cluster workers now support stdio configuration. (Colin Ihrig) #7811 and #7838
* fs: fs.ReadStream now exposes the number of bytes it has read so far. (Linus Unnebäck) #7942
* repl: The REPL now supports editor mode. (Prince J Wesley) #7275
* util: inspect() can now be configured globally using util.inspect.defaultOptions. (Roman Reiss) #8013
Refs: #8020
PR-URL: #8070
cjihrig added a commit that referenced this pull request Aug 11, 2016
Notable changes:
* build: zlib symbols and additional OpenSSL symbols are now exposed on Windows platforms. (Alex Hultman) #7983 and #7576
* child_process, cluster: Forked child processes and cluster workers now support stdio configuration. (Colin Ihrig) #7811 and #7838
* child_process: argv[0] can now be set to arbitrary values in spawned processes. (Pat Pannuto) #7696
* fs: fs.ReadStream now exposes the number of bytes it has read so far. (Linus Unnebäck) #7942
* repl: The REPL now supports editor mode. (Prince J Wesley) #7275
* util: inspect() can now be configured globally using util.inspect.defaultOptions. (Roman Reiss) #8013
Refs: #8020
PR-URL: #8070
cjihrig added a commit that referenced this pull request Aug 15, 2016
Notable changes:
* build: zlib symbols and additional OpenSSL symbols are now exposed on Windows platforms. (Alex Hultman) #7983 and #7576
* child_process, cluster: Forked child processes and cluster workers now support stdio configuration. (Colin Ihrig) #7811 and #7838
* child_process: argv[0] can now be set to arbitrary values in spawned processes. (Pat Pannuto) #7696
* fs: fs.ReadStream now exposes the number of bytes it has read so far. (Linus Unnebäck) #7942
* repl: The REPL now supports editor mode. (Prince J Wesley) #7275
* util: inspect() can now be configured globally using util.inspect.defaultOptions. (Roman Reiss) #8013
Refs: #8020
PR-URL: #8070
cjihrig added a commit to cjihrig/node that referenced this pull request Aug 16, 2016
Notable changes:
* build: zlib symbols and additional OpenSSL symbols are now exposed on Windows platforms. (Alex Hultman) nodejs#7983 and nodejs#7576
* child_process, cluster: Forked child processes and cluster workers now support stdio configuration. (Colin Ihrig) nodejs#7811 and nodejs#7838
* child_process: argv[0] can now be set to arbitrary values in spawned processes. (Pat Pannuto) nodejs#7696
* fs: fs.ReadStream now exposes the number of bytes it has read so far. (Linus Unnebäck) nodejs#7942
* repl: The REPL now supports editor mode. (Prince J Wesley) nodejs#7275
* util: inspect() can now be configured globally using util.inspect.defaultOptions. (Roman Reiss) nodejs#8013
Refs: nodejs#8020
PR-URL: nodejs#8070
@nbering

Copy link
Copy Markdown

Sorry, a bit late to the issue because I just found it in the release notes. As I understand it this feature is strictly about delaying the execution of the command until you're done entering all the lines? I was hoping when I saw the feature name that it would allow me to fix previous lines if I make an error, but it seems once I hit enter that I can't go back.

@PeterAronZentai

Copy link
Copy Markdown

Yeah, that was my first impression too, maybe because it is called .editor. Probably .paste would create less confusion.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

replIssues and PRs related to the REPL subsystem.semver-minorPRs that contain new features and should be released in the next minor version.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

13 participants

@princejwesley@benjamingr@Trott@Fishrock123@jasnell@thefourtheye@addaleax@evanlucas@trevnorris@nbering@PeterAronZentai@cjihrig@nodejs-github-bot