Reputation: 1231
I am watching one of Jim Weirich's presentations about Y combinator using JavaScript in Emacs, at http://v.youku.com/v_show/id_XNDQ4NDY0NjM2.html
(The presentation is pretty much similar, I think, to what he gave at RubyConf 2012 using Ruby instead of javascript ..http://confreaks.com/videos/1287-rubyconf2012-y-not-adventures-in-functional-programming)
One thing I noticed that he was evaluating JS in the buffer from within Emacs (by node.js, as some of the error msgs shown) via "C-c v" short-cut, and also got the output back into another buffer.
I am wondering is there a simple instruction (before diving into comint/call-process details) on how to get that setup on latest Emacs on windows...I searched, but so far no success. Btw, I alreay get node.exe installed, and can get node interactively run as a REPL in Emacs by "M-x run-js", following instruction at in an article "setting-up-emacs-as-a-javascript-editing-environment-for-fun-and-profit" (sorry not able to post more than 2 links...)
Thanks,
/bruin
Upvotes: 2
Views: 1973
Reputation: 349
install js3-mode
then:
(require 'js-comint)
(setq inferior-js-program-command "node --interactive")
(setenv "NODE_NO_READLINE" "1")
;; Use your favorited js mode here:
(add-hook 'js3-mode-hook '(lambda ()
(local-set-key "\C-x\C-e"
'js-send-last-sexp)
(local-set-key "\C-\M-x"
'js-send-last-sexp-and-go)
(local-set-key "\C-cb"
'js-send-buffer)
(local-set-key "\C-c\C-b"
'js-send-buffer-and-go)
(local-set-key "\C-cl"
'js-load-file-and-go)
))
Upvotes: 1
Reputation: 1231
I defined the following function and its key map. So far it works.
(defun node-js-eval-region-or-buffer ()
"Evaluate the current buffer (or region if mark-active),
and return the result into another buffer,
which is to be shown in a window."
(interactive)
(let ((debug-on-error t) (start 1) (end 1))
(cond
(mark-active
(setq start (point))
(setq end (mark)))
(t
(setq start (point-min))
(setq end (point-max))))
(call-process-region
start end ; seems the order does not matter
"node" ; node.js
nil ; don't delete region
"node.js" ; output buffer
nil) ; no redisply during output
(message "Region or buffer evaluated!")
(setq deactivate-mark t))) ; deactive the region, regardless
(define-key global-map (kbd "C-c v") 'node-js-eval-region-or-buffer)
I still have another thing to dig a bit: how to automatically split the screen to show the output buffer? I guess it should be not too difficult...
Btw, I install Git and Node.js for Windows, and copy "node.exe" into Git's "/bin" directory (which has been added to PATH environment during installation).
Upvotes: 1