Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[suggestion] Evaluate JavaScript with node.js / io.js #483

Closed
stormpat opened this issue Jan 26, 2015 · 23 comments
Closed

[suggestion] Evaluate JavaScript with node.js / io.js #483

stormpat opened this issue Jan 26, 2015 · 23 comments

Comments

@stormpat
Copy link
Contributor

It would be really cool if you could eval a buffer with node or io.js. This should be a part of the JavaScript contrib layer. Even better, if there was a way to evaluate just a block instead of the entire buffer.

There is bindings in the clojure layer to eval a region or buffer, so i was thinking of something similar.

@oppenlander
Copy link
Contributor

I used to have something like this in my last setup with js-comint.
It lets you evaluate code like this, but it was infuriatingly slow.

I was going add something like this once I had time to look in to other options.

@syl20bnr
Copy link
Owner

PR welcome. There are conventions for such actions: https://github.com/syl20bnr/spacemacs/blob/master/doc/CONVENTIONS.md#interactions-with-repls

@stormpat
Copy link
Contributor Author

I have never done any LISP before, im still learning. Ill definitely make a PR once i have something worth sharing.

@mkcode
Copy link
Contributor

mkcode commented Jan 30, 2015

Checkout swankjs too.

https://github.com/swank-js/swank-js

@mkcode
Copy link
Contributor

mkcode commented Jan 30, 2015

Wow. A video of swank! :) https://m.youtube.com/watch?v=qwtVtcQQfqc

@stormpat
Copy link
Contributor Author

Thats just amazing! We really need to get that included in JS layer!

@esiegel
Copy link
Contributor

esiegel commented Feb 1, 2015

There's also skewer. I haven't used either, but it seems that skewer is trying to replace swank with the claimed advantage of being easier to install.

Here is a video of it in action.

@oppenlander
Copy link
Contributor

Skewer seems to have solved some usability issues with live coding in a browser, but I can't find anything about node.js/io.js REPL support.
There's this issue, which hasn't been updated in a year, but I also can't find any reference to an alternate engine in the source, other than browser and phantom.

Slime on the other hand seems like it is really good for nodejs/io.js, but the CSS/HTML eval is dreadful.

It would probably be best to have both available, but mixing them will likely be problematic.

@robbyoconnor
Copy link
Contributor

Why has nobody done work on this?...I mean I'm not demanding, just am curious :)

@stormpat
Copy link
Contributor Author

I have tried but failed, as I just suck at Lisp, and also am very new to the Emacs ecosystem. The solutions out there seems very big (swank) as it seems to be connected to the browser (via sockets) too.

I would like to (start) with something very basic/minimal, im very fond of how to alchemist package evaluates your Elixir code and prints it to the buffer, as a comment. For now i have been using this to eval my buffer.

(defun u/node-eval ()
  "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

The snippet is from SO, http://stackoverflow.com/questions/19743105/how-to-evaluate-javascript-buffer-by-node-js-from-within-emacs-on-windows

It prints the result in a new buffer. Theres a lot of room for improvement, and i have some ideas and have been reading the source for the alchemist package to get a better understanding of how it works.

@ghost
Copy link

ghost commented Oct 3, 2016

As a javascript/node developer, I really disappointed this hasn't been resolved despite being old and much in demand..

@stormpat
Copy link
Contributor Author

stormpat commented Oct 3, 2016

@v3ctr0n The latest master now has skewer-mode included.

@stormpat stormpat closed this as completed Oct 3, 2016
@ghost
Copy link

ghost commented Oct 3, 2016

@stormpat how do I evaluate node.js code in the skewer repl?

@InvisibleTech
Copy link

Wow, I feel like I am retracing the steps of this issue. I am okay with a little LISP not strong yet on emacs ecosystem. Came over to spacemacs for everything I can but I am hitting the same wall here. skewer is fine if I want front development with a nice code to browser flow. However, I really want is node REPL to evaluate application. Been grinding around various search hits. Nothing yet. What am I missing?

@stormpat
Copy link
Contributor Author

@InvisibleTech @ghost If you want a more traditional REPL you could try https://melpa.org/#/nodejs-repl

@InvisibleTech
Copy link

Thanks @stormpat but my issue is twofold, I use spacemacs (not the issue IMO :-) ) and so it seems to have rules of engagement. I tried to add use of noderepl-js setting up site-lisp to contain the required folder with some code used to tell "normal" Emacs how to do the Node REPL. Issue seemed to be spacemacs ignored it. So I would have to then install it use emacs commands. I think it had to be done every restart - don't recall. I tried (just hacking without knowing) to reference the file from the layers list and since it wasn't a proper layer.. rejected. I am an emacs/spacemacs newb... so what do I do to "install" your suggested file?

@stormpat
Copy link
Contributor Author

@InvisibleTech

Heres something to get you started:

First add the package to your .spacemacs file.
dotspacemacs-additional-packages '(nodejs-repl)

The restart emacs to install SPC q R

Optional:

Add some keybindings for easier use
(spacemacs/set-leader-keys "onr" 'nodejs-repl-send-region)

Note. The SPC o namespace is reserved for userland, so it will never conflict with spacemacs.

You can start the repl with nodejs-repl

You will get this:

@syl20bnr
Copy link
Owner

What don't we have node.js REPL in the layer ? Is it just because nobody submitted it or is there any other issue ?

@robbyoconnor
Copy link
Contributor

robbyoconnor commented Feb 14, 2017 via email

@madand
Copy link
Contributor

madand commented Feb 17, 2017

@syl20bnr indeed, there is no Node REPL support in the layer at the moment.

What makes this issue challenging is the fact that we need support for two different REPLs in most cases, within a single project, in the same major mode js2-mode:

  1. The browser REPL. It is already available in the layer with skewer-mode.
  2. NodeJS REPL. As previously mentioned, this can be added with nodejs-repl.

We need a way to define which set of REPL bindings should be activated for a given file within a project. So that conventional leader keybindigs like ,sb and ,ss will invoke the right commands.

Maybe the layer should provide some file/dir-local vars to define which REPL to use. Any hints on how to properly implement this in Spacemacs are welcome.

@zrobisho
Copy link

Is there a spacemacs convention for handling the case where two packages provide the same functionality and then allow the user to configure it by some variable? I am currently using nodejs-repl with my spacemacs config, but I just overwrite all the skewer stuff in my user-config. If there is a convention or example of this I will try implementing what I have in the js layer.

@robbyoconnor
Copy link
Contributor

robbyoconnor commented Mar 14, 2017 via email

@beppu
Copy link

beppu commented Jan 16, 2018

Here's something people can do while they wait for this to be properly integrated into the javascript layer. (Thanks to @stormpat for the example above.)

https://github.com/abicky/nodejs-repl.el/wiki/Spacemacs-Configuration

cyruseuros added a commit to cyruseuros/spacemacs that referenced this issue Feb 4, 2019
Add relevant keybindings and documentation, including a setting
`js2-include-node-externs` as a configuration variable for those that intend to
use `Spacemacs` for node projects, as it currently seems to be mostly aimed at
pure JS (syl20bnr#483).
cyruseuros added a commit to cyruseuros/spacemacs that referenced this issue Apr 23, 2019
Add relevant keybindings and documentation, including a setting
`js2-include-node-externs` as a configuration variable for those that intend to
use `Spacemacs` for node projects, as it currently seems to be mostly aimed at
pure JS (syl20bnr#483).
cyruseuros added a commit to cyruseuros/spacemacs that referenced this issue Apr 30, 2019
Add relevant keybindings and documentation, including a setting
`js2-include-node-externs` as a configuration variable for those that intend to
use `Spacemacs` for node projects, as it currently seems to be mostly aimed at
pure JS (syl20bnr#483).
cyruseuros added a commit to cyruseuros/spacemacs that referenced this issue Jun 7, 2019
Add relevant keybindings and documentation, including a setting
`js2-include-node-externs` as a configuration variable for those that intend to
use `Spacemacs` for node projects, as it currently seems to be mostly aimed at
pure JS (syl20bnr#483).
smile13241324 pushed a commit that referenced this issue Jun 9, 2019
Add relevant keybindings and documentation, including a setting
`js2-include-node-externs` as a configuration variable for those that intend to
use `Spacemacs` for node projects, as it currently seems to be mostly aimed at
pure JS (#483).
thomasheartman pushed a commit to thomasheartman/.emacs.d that referenced this issue Jul 6, 2019
Add relevant keybindings and documentation, including a setting
`js2-include-node-externs` as a configuration variable for those that intend to
use `Spacemacs` for node projects, as it currently seems to be mostly aimed at
pure JS (syl20bnr/spacemacs#483).
stephanschubert pushed a commit to stephanschubert/spacemacs that referenced this issue Oct 23, 2019
Add relevant keybindings and documentation, including a setting
`js2-include-node-externs` as a configuration variable for those that intend to
use `Spacemacs` for node projects, as it currently seems to be mostly aimed at
pure JS (syl20bnr#483).
sei40kr pushed a commit to sei40kr/spacemacs that referenced this issue Nov 11, 2019
Add relevant keybindings and documentation, including a setting
`js2-include-node-externs` as a configuration variable for those that intend to
use `Spacemacs` for node projects, as it currently seems to be mostly aimed at
pure JS (syl20bnr#483).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests