简体   繁体   English

如何在Windows上的Emacs中以交互方式运行node.js

[英]how to run node.js interactively in Emacs on Windows

I thought this would work: 我认为这会奏效:

(defun my-node ()
  (interactive)
  (pop-to-buffer (make-comint "my-node" "node")))

But when I do Mx my-node and enter 1+1 in the comint buffer, it does not display any output. 但是当我执行Mx my-node并在comint缓冲区中输入1+1时,它不会显示任何输出。

This is in Emacs 24.0.50.1 on Windows 7 and NodeJS is installed without any special configuration. 这是在Windows 7上的Emacs 24.0.50.1中安装的NodeJS没有任何特殊配置。

Calling node.js non-interactively as in Mx compile RET node hello-world.js RET works fine. 非接触地调用node.js,如在Mx compile RET node hello-world.js RET工作正常。 Running node interactively in cmd works fine. cmd交互方式运行node工作正常。

This might be related: when I run Mx shell and enter node in the shell buffer and then enter 1+1 , it doesn't display the result. 这可能是相关的:当我运行Mx shell并在shell缓冲区中输入node然后输入1+1 ,它不会显示结果。 I must be missing something very basic. 我必须遗漏一些非常基本的东西。

Update: 更新:

Probably related: emacs/Python: running python-shell in line buffered vs. block buffered mode - Stack Overflow 可能相关: emacs / Python:在行缓冲与块缓冲模式下运行python-shell - Stack Overflow

The simplest way to have node.js (tested using node v0.8.1) as an inferior shell under Emacs is to use the js-comint package. 将node.js(使用节点v0.8.1测试)作为Emacs下的劣质shell的最简单方法是使用js-comint包。 Then, set (setq inferior-js-program-command "node --interactive") to force node to run in interactive mode. 然后,设置(setq inferior-js-program-command "node --interactive")以强制节点以交互模式运行。 The command Mx run-js will then open the interpreter. 然后命令Mx run-js将打开解释器。

Similarly, you can easily verify that node --interactive works within an eshell. 同样,您可以轻松验证node --interactive是否在eshell中工作。

From http://www.gnu.org/software/emacs/windows/Sub_002dprocesses.html , it looks as if what may be happening is that the output is being buffered by node. http://www.gnu.org/software/emacs/windows/Sub_002dprocesses.html看,可能发生的事情是输出是由节点缓冲的。 If there is an option that modifies it's buffering, you could try passing that. 如果有一个选项可以修改它的缓冲,你可以尝试传递它。

There may be another way to solve it, assuming it's a buffering issue, but my windows lore isn't nearly complete enough to know. 可能还有另一种方法可以解决它,假设这是一个缓冲问题,但我的Windows知识还不够完整。 I, for one, would love a general solution to this on windows platforms, it's an annoying problem when it crops up. 我认为,在Windows平台上,我会喜欢这种解决方案的一般解决方案,当它突然出现时,这是一个令人讨厌的问题。

I found one solution. 我找到了一个解决方案

Make a node script which starts a JavaScript REPL interface. 创建一个启动JavaScript REPL接口的节点脚本。

node-in-node.js: 节点在-的node.js:

var repl = require("repl");
repl.start();

Pass "node path\\to\\node-in-node.js" to make-comint instead of simply "node". 将“node path \\ to \\ node-in-node.js”传递给make-comint而不是简单的“node”。

(defun my-node-shell ()
  (interactive)
  (pop-to-buffer (make-comint "Node Shell" "node" nil "C:\\run\\node-in-node.js")))

Run Mx my-node-shell to run a JavaScript shell in Windows Emacs. 运行Mx my-node-shell以在Windows Emacs中运行JavaScript shell。 I don't know why this works. 我不知道为什么会这样。 Tab completion, syntax highlight, multiline input via Shift+Enter does not work. 通过Shift + Enter选项卡完成,语法突出显示,多行输入不起作用。

If js-comint does not work for you, you can try : 如果js-comint不适合您,您可以尝试

 (defun node-repl () (interactive) (setenv "NODE_NO_READLINE" "1") ;avoid fancy terminal codes (pop-to-buffer (make-comint "node-repl" "node" nil "--interactive"))) (node-repl) 

The js-comint way seems to work better. js-comint方式似乎更好用。

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

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