Skip to content

Commit

Permalink
improve working on REPL in Emacs
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Mar 9, 2024
1 parent a59abdc commit bc02330
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
* fix unintentional unboxing in `iterator->array` [#328](https://github.com/jcubic/lips/issues/328)
* fix `replace` with async `lambda` [#319](https://github.com/jcubic/lips/issues/319)
* fix `values` without arguments [#331](https://github.com/jcubic/lips/issues/331)
* improve working of REPL in Emacs

## 1.0.0-beta.18
### Breaking
Expand Down
22 changes: 14 additions & 8 deletions bin/lips.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ function run_repl(err, rl) {
rl.prompt();
}
let prev_line;
const is_emacs = process.env.INSIDE_EMACS;
bootstrap(interp).then(function() {
if (supports_paste_brackets) {
process.stdin.on('keypress', (c, k) => {
Expand Down Expand Up @@ -495,7 +496,7 @@ function run_repl(err, rl) {
}).then(function(result) {
if (process.stdin.isTTY) {
print(result);
if (newline) {
if (newline || is_emacs) {
// readline doesn't work with not ended lines
// it ignore those, so we end them ourselves
process.stdout.write("\n");
Expand All @@ -505,33 +506,38 @@ function run_repl(err, rl) {
multiline = false;
}
}
rl.setPrompt(prompt);
rl.prompt();
rl.resume();
}).catch(function() {
if (process.stdin.isTTY) {
if (multiline) {
multiline = false;
}
}
}).finally(function() {
rl.setPrompt(prompt);
rl.prompt();
rl.resume();
});
} else {
multiline = true;
if (cmd.match(/\x1b\[200~/) || !supports_paste_brackets) {
rl.setPrompt(continuePrompt);
rl.prompt();
if (is_emacs) {
rl.setPrompt('');
} else {
rl.setPrompt(continuePrompt);
}
if (terminal) {
rl.write(' '.repeat(prompt.length - continuePrompt.length));
}
} else {
const ind = indent(code, 2, prompt.length - continuePrompt.length);
const spaces = new Array(ind + 1).join(' ');
rl.setPrompt(continuePrompt);
rl.prompt();
if (terminal) {
if (is_emacs) {
rl.setPrompt('');
rl.prompt();
} else {
rl.setPrompt(continuePrompt);
rl.prompt();
rl.write(spaces);
}
}
Expand Down

0 comments on commit bc02330

Please sign in to comment.