最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - how to run node.js interactively in Emacs on Windows - Stack Overflow

programmeradmin2浏览0评论

I thought this would work:

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

But when I do M-x my-node and enter 1+1 in the comint buffer, it does not display any output.

This is in Emacs 24.0.50.1 on Windows 7 and NodeJS is installed without any special configuration.

Calling node.js non-interactively as in M-x compile RET node hello-world.js RET works fine. Running node interactively in cmd works fine.

This might be related: when I run M-x shell and enter node in the shell buffer and then enter 1+1, it doesn't display the result. I must be missing something very basic.

Update:

Probably related: emacs/Python: running python-shell in line buffered vs. block buffered mode - Stack Overflow

I thought this would work:

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

But when I do M-x my-node and enter 1+1 in the comint buffer, it does not display any output.

This is in Emacs 24.0.50.1 on Windows 7 and NodeJS is installed without any special configuration.

Calling node.js non-interactively as in M-x compile RET node hello-world.js RET works fine. Running node interactively in cmd works fine.

This might be related: when I run M-x shell and enter node in the shell buffer and then enter 1+1, it doesn't display the result. I must be missing something very basic.

Update:

Probably related: emacs/Python: running python-shell in line buffered vs. block buffered mode - Stack Overflow

Share Improve this question edited May 23, 2017 at 10:30 CommunityBot 11 silver badge asked Jan 18, 2012 at 12:07 YooYoo 18.3k6 gold badges43 silver badges48 bronze badges
Add a comment  | 

4 Answers 4

Reset to default 13

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. Then, set (setq inferior-js-program-command "node --interactive") to force node to run in interactive mode. The command M-x run-js will then open the interpreter.

Similarly, you can easily verify that node --interactive works within an 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. 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. I, for one, would love a general solution to this on windows platforms, it's an annoying problem when it crops up.

I found one solution.

Make a node script which starts a JavaScript REPL interface.

node-in-node.js:

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

Pass "node path\to\node-in-node.js" to make-comint instead of simply "node".

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

Run M-x my-node-shell to run a JavaScript shell in Windows Emacs. I don't know why this works. Tab completion, syntax highlight, multiline input via Shift+Enter does not work.

If js-comint does not work for you, you can try:

(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.

发布评论

评论列表(0)

  1. 暂无评论