.load, .save and local scope tab completion
authorseebees <seebees@gmail.com>
Sat, 12 Nov 2011 01:44:39 +0000 (17:44 -0800)
committerRyan Dahl <ry@tinyclouds.org>
Sat, 12 Nov 2011 19:34:55 +0000 (11:34 -0800)
commit3421f433519411c290c732c64dadbb6547e42235
treed6bd2427ef01f7028259343c25a640aa70a956d6
parentb00f5e2e14b98188d275be411a3ce03bffce69af
.load, .save and local scope tab completion

Fixes #2063.

REPLServer.prototype.resetContext:
Reset the line cache

REPLServer.prototype.memory (don't know if I like that name, called from finish)
pushes what cmd's have been executed against it into this.lines
pushes the "tab depth" for bufferedCommands, in this.lines.level

REPLServer.prototype.displayPrompt:
Uses "tab depth" from this.lines.level to adjust the prompt to visually
denote this depth e.g.
> asdf = function () {
… var inner = {
….. one:1

REPLServer.prototype.complete:
Now notices if there is a bufferedCommand and attempts determine locally
scoped variables by removing any functions from this.lines and evaling these
lines in a nested REPL e.g.
> asdf = function () {
… var inner = { one: 1};
… inn\t
will complete to 'inner' and inner.o\t will complete to 'inner.one'
If the nested REPL still has a bufferedCommand it will falls back to the
default.

ArrayStream is a helper class for the nested REPL to get commands pushed to it.
new REPLServer('', new ArrayStream());

Finally added two new REPL commands .save and .load, each takes 1 parameter,
a file and attempts to save or load the file to or from the REPL
respectively.
lib/repl.js
test/simple/test-repl-tab-complete.js
test/simple/test-repl.js