简体   繁体   English

如何编写适用于 GNU Emacs 的 Node.js REPL?

[英]How to write Node.js REPL that works with GNU Emacs?

I have Scheme interpreter in JavaScript called LIPS.我在 JavaScript 中有名为 LIPS 的 Scheme 解释器。 I have executable file, it works in terminal emulator but it's broken in GNU Emacs inferior mode (using run-scheme function).我有可执行文件,它在终端仿真器中工作,但在 GNU Emacs 劣等模式下(使用run-scheme函数)被破坏了。

I've reproduced the issue with this simple Node.js REPL using Readline:我使用 Readline 用这个简单的 Node.js REPL 重现了这个问题:

var prompt = 'lips> ';
var continuePrompt = '... ';
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
    prompt: prompt,
    terminal: !!process.stdin.isTTY // true in Emacs
});
if (process.stdin.isTTY) {
    rl.prompt();
}

rl.on('line', function(line) {
    if (process.stdin.isTTY) {
        rl.prompt();
    }
});

First issue was that when I type something the output is duplicated, it's literal command line echo:第一个问题是,当我输入某些内容时,输出是重复的,它是文字命令行回显:

lips> 10
10
10
lips> '(1 2 3)
'(1 2 3)
(1 2 3)
lips>

I've found solution, which:我找到了解决方案,其中:

(setq comint-process-echoes t)

But another issue is that on resize it keep appending prompt to prompt.但另一个问题是,在调整大小时,它会不断附加提示以提示。 so I have this:所以我有这个:

lips> lips> lips> lips> lips>

This is prompt because if I set:这是提示,因为如果我设置:

(setq comint-prompt-read-only t)

I can't delete that text.我无法删除该文本。

EDIT:编辑:

The same happen if I call (read) that is also using readline to get input, it keep adding spaces.如果我调用 (read) 也使用 readline 来获取输入,也会发生同样的情况,它会不断添加空格。

I was reading Node.js source code and it also use readline and it works fine when run using run-js , Kawa Scheme Interpreter works correctly but it don't use readline:我正在阅读 Node.js 源代码,它也使用 readline 并且在使用run-js时工作正常,Kawa Scheme Interpreter 工作正常但不使用 readline:

 (setq inferior-js-program-command "node --interactive")
 (run-js)

This works, it's not run-scheme but it's same mode, I've also tried to run same run-js code but with my Scheme interpreter, and it also show same prompt duplication on resize.这有效,它不是 run-scheme 但它是相同的模式,我也尝试运行相同的run-js代码,但使用我的 Scheme 解释器,并且它也在调整大小时显示相同的提示重复。

 (setq inferior-js-program-command "/home/kuba/projects/jcubic/lips/bin/lips.js")
 (run-js)

Got answer in Emacs devel mailing list, the solution is to turn off readline when inside Emacs:在 Emacs devel 邮件列表中得到了答案,解决方案是在 Emacs 中关闭 readline:

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
    prompt: prompt,
    terminal: !!process.stdin.isTTY && !(process.env.EMACS || process.env.INSIDE_EMACS)
});

Lot of interpreters do the same thing.许多口译员做同样的事情。 eg: Bash.例如:巴什。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM