• Stars
    star
    189
  • Rank 203,430 (Top 5 %)
  • Language
    Emacs Lisp
  • Created over 12 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Run Node.js REPL and communicate with the process

nodejs-repl.el

Run Node.js REPL in Emacs

Description

This program is derived from comint-mode and provides the following features.

  • token completion, same as Node.js REPL
  • file name completion in string
  • incremental history search
  • sending JavaScript codes to REPL

Usage

Put this file in your Emacs lisp path (e.g. ~/.emacs.d/site-lisp) and add the following line to your .emacs:

(require 'nodejs-repl)

Type M-x nodejs-repl to run Node.js REPL. See also comint-mode to check key bindings.

You can define key bindings to send JavaScript codes to REPL like below:

(add-hook 'js-mode-hook
          (lambda ()
            (define-key js-mode-map (kbd "C-x C-e") 'nodejs-repl-send-last-expression)
            (define-key js-mode-map (kbd "C-c C-j") 'nodejs-repl-send-line)
            (define-key js-mode-map (kbd "C-c C-r") 'nodejs-repl-send-region)
            (define-key js-mode-map (kbd "C-c C-c") 'nodejs-repl-send-buffer)
            (define-key js-mode-map (kbd "C-c C-l") 'nodejs-repl-load-file)
            (define-key js-mode-map (kbd "C-c C-z") 'nodejs-repl-switch-to-repl)))

When a version manager such as nvm is used to run different versions of Node.js, it is often desirable to start the REPL of the version specified in the .nvmrc file per project. In such case, customize the nodejs-repl-command variable with a function symbol. That function should query nvm for the Node.js command to run. For example:

(require 'nodejs-repl)
(defun nvm-which ()
  (let* ((shell (concat (getenv "SHELL") " -l -c 'nvm which'"))
         (output (shell-command-to-string shell)))
    (cadr (split-string output "[\n]+" t))))
(setq nodejs-repl-command #'nvm-which)

The nvm-which function can be simpler, and perhaps can run faster, too, if using Bash:

(defun nvm-which ()
  (let ((output (shell-command-to-string "source ~/.nvm/nvm.sh; nvm which")))
    (cadr (split-string output "[\n]+" t))))

Author

Takeshi Arabiki (abicky)

Copyright and License

Copyright (C) 2012-2020 Takeshi Arabiki (abicky)

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

More Repositories

1

activerecord-debug_errors

An extension of activerecord to display useful debug logs on errors
Ruby
28
star
2

swap-pane

Swap tmux panes easily
Shell
5
star
3

pig-latin-mode

major mode for Pig codes
Emacs Lisp
5
star
4

ecswrap

A wrappper program which resolves termination order of ECS containers
Go
4
star
5

ecsmec

A CLI tool for Amazon ECS that provides some commands to execute bothersome operations
Go
4
star
6

rjpusers2011_abicky

R
3
star
7

RUnicode

R package to proceed Unicode characters
C++
3
star
8

R_funcs

R functions abicky is maintaing
R
3
star
9

latex_utils

3
star
10

lda-r

pure R version of LDA-C
R
2
star
11

docker-log-and-fluent-plugin-s3-with-columnify-example

Ruby
2
star
12

packageR

Import R scripts as a package
R
1
star
13

chemacs

Enable Emacs-like keybindings for editing text on Google Chrome
JavaScript
1
star
14

tokyonlp07_abicky

Python
1
star
15

osakar4_abicky

Codes for Osaka.R #4 presentation by a_bicky
R
1
star
16

.emacs.d

My configuration for Emacs
Emacs Lisp
1
star
17

jsx_dynamic_loading

Sample for dynamic loading JavaScript generated by JSX
JavaScript
1
star
18

rollbar-notification-rules-generator

A CLI tool that generates Rollbar notification rules that are mutually exclusive from a simple YAML file
HCL
1
star
19

fluent-plugin-mysql-select-insert

Fluentd output plugin to insert records by SELECT query.
Ruby
1
star
20

query-matcher-js

JavaScript matcher for user queries
CoffeeScript
1
star
21

homebrew-formulae

Homebrew formulae for my development
Ruby
1
star
22

mathjax_for_pukiwiki

MathJax plugin for PukiWiki
PHP
1
star
23

docker-rocksdb-tools

Docker image for rocksdb-tools, such as ldb and sst_dump
Dockerfile
1
star