Giter Club home page Giter Club logo

js-comint's Introduction

js-comint.el (v1.2.0)

Run a JavaScript interpreter in an inferior process window

The first release, js-comint 0.0.1, is hosted on sourceforge but it has not been updated for five years.

Features

Installation

Direct download of js-comint.el

Place the js-comint.el somewhere say “~/mylisp/”.

Insert below code to “~/.emacs.d/init.el”,

(add-to-list 'load-path "~/mylisp/")
(require 'js-comint)

Using ELPA

Insert below code to “~/.emacs.d/init.el”,

(require 'package)
(package-initialize)
(add-to-list 'package-archives
             '("melpa" . "http://melpa.org/packages/"))
(package-install 'js-comint)
(require 'js-comint)

Using Cask

Add js-comint to your Cask file:

(depends-on "js-comint")

Windows

On window, you may need below setup:

(setq js-comint-program-command "C:/Program Files/nodejs/node.exe")

Usage

After installation, do `M-x run-js` to create a comint buffer with the JavaScript interpreter.

Please note the directory node_modules is automatically searched and appended into environment variable `NODE_PATH’. So you can use third party javascript without setup. For example, after npm install --save moment, run below command in js-comint shell,

require('moment')().format('YYYY-MM-DD');

You can M-x js-clear before M-x js-send-buffer to get clean output.

In order to get cleaner output when using NodeJS, I suggest add below setup into .emacs,

(defun inferior-js-mode-hook-setup ()
  (add-hook 'comint-output-filter-functions 'js-comint-process-output))
(add-hook 'inferior-js-mode-hook 'inferior-js-mode-hook-setup t)

Customization

You can set the `js-comint-program-command’ string and the `js-comint-program-arguments’ list to the executable that runs the JS interpreter and the arguments to pass to it respectively.

E.g., the default is:

;; You can also customize `js-comint-drop-regexp' to filter output
(setq js-comint-program-command "node")
(setq js-comint-program-arguments '("--interactive"))

Note that in the example above, the version of node that is picked up will be the first found in `exec-path’.

But you could use Rhino or SpiderMonkey or whatever you want. E.g. to set up the Rhino JAR downloaded from https://github.com/mozilla/rhino, do

(setq js-comint-program-command "java")
(setq js-comint-program-arguments '("-jar" "/absolute/path/to/rhino/js.jar"))

If you have nvm, you can select the versions of node.js installed and run them. This is done thanks to nvm.el. nvm.el is optional. So you need manually install it.

To enable nvm support, run

(js-do-use-nvm)

The first time you start the JS interpreter with run-js, you will be asked to select a version of node.js. If you want to change version of node js, run (js-select-node-version).

You can add the following couple of lines to your .emacs/init file to take advantage of key bindings for sending things to the JavaScript REPL:

; Remap Elisp's eval-last-sexp (C-x C-e) to eval JavaScript
(define-key js-mode-map [remap eval-last-sexp] #'js-comint-send-last-sexp))
(define-key js-mode-map (kbd "C-c b") 'js-send-buffer))

js-comint's People

Contributors

bremner avatar divinedominion avatar josteink avatar linktohack avatar redguardtoo avatar saffroy avatar stefano-m avatar syohex avatar yorkz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

js-comint's Issues

Determine correct licensing for js-comint

I've created a package forked from js-comint (ts-comint) and would like to add a license-file to it.

But to do so, I need to know what license this code which I've based my fork on is licensed under to ensure it is consistent or not in violation.

How about GPL3? Since that's what Emacs and the ELPA guys want everything to be?

Highlight output window after buffer evaluation

I use javascript mode (js-mode) in emacs. When i send a file to node repl using js-load-file command, it doesn't highlight the output window (js) by default. Mostly, emacs highlights the output window after doing buffer evaluation. Now, i am made to navigate to it manually by using switch-buffer command.

smart way to detect current node

(js2-node-abs-pos (js2-node-at-point (1- (point))))
(js2-node-len (js2-node-abs-pos (js2-node-at-point (1- (point)))))

test [1, 2, 3].slice(0,2)
maybe we can apply this into expand-region

Add tests and Travis CI support

I think it would be good if we added tests and CI support to this repo. It would make it easier to contribute to and more confident that we are not breaking people's setups.

We could set up Travis CI jobs that test against different versions of Emacs and we could use Cask and ert-runner.el.

I am slowly working on adding tests on a branch of my fork now. I will submit a PR once this is done.

Of course, any other contributor is more than welcome to give a hand!

docs: refs to non-existent functions/vars

README mentions inferior-js-mode-hook and js-send-buffer-and-go, neither of which are included in this package. Can you update with the replacements and/or restore the original functions? Thank you!!

nvm from .nvmrc?

Is it possible to select npm version form the .nvmrc file in a project?

new features

features:

  • es6, babel
  • import, can scan files in certain root directory
  • 3rd party library
  • auto-complete (company, ivy?)
  • can read webpack.config.js

plan:

  • start from moment.js

connect to a socket REPL

is it possible to add connect to a socket REPL feature like in inf-clojure, please?
There is possible to define inf-clojure-program like cons pair ("localhost" . 5555).

Add support for Deno

Deno is a newer alternative to Node, by the same author.

js-comint ostensibly supports multiple JS engines, but there are some places in the code which are hard-coded to support node.

For instance, the function js-comint-start-or-switch-to-repl appends -e to any user supplied command line arguments (-e is "eval-script" in Node), and this is an unsupported command line option in Deno.

Add tab completion

TAB works fine in when starting node from bash, so we should be able to do the same thing inside Emacs.

Send multiline string

Node has special key for multiline string. .editor. The patch bellow will allow you to evaluate all or partial of this code for example

[1, 2, 3]
  .map((it) => it + 1)
  .filter((it) => it > 0)
  .reduce((prev, curr) => prev + curr, 0);
  (el-patch-feature js-comint)

  (with-eval-after-load 'js-comint
    (el-patch-defun js-comint-send-string (str)
      "Send STR to repl."
      (el-patch-swap
	(comint-send-string (js-comint-get-process)
			    (concat str "\n"))
	(let ((lines (string-lines str)))
	  (if (length= lines 1)
	      (comint-send-string (js-comint-get-process)
				  (concat str "\n"))
	    (comint-send-string (js-comint-get-process)
				(concat ".editor" "\n" str "\n"))
	    (process-send-eof (js-comint-get-process)))))))

TODO

  • clean doc
  • Add auto-completion
  • switch project and find node_modules automatically
  • can use recentf
  • use ivy
  • company-mode

Customization for Windows

It might be useful to add the following to the documentation, when using js-comint on Windows.

This disables nodes own readline:

(setenv "NODE_NO_READLINE" "1")

See the discussion on Stackoverflow

And this sets the executable. Otherwise js-comint will search just for node without the .exe extension.

(setq inferior-js-program-command "C:/Program Files/nodejs/node.exe")

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.