This is a rephrase of my SO question https://stackoverflow.com/questions/44147993, which didn't receive much attention in SO.

Basically, I suspect that I enountered a problem with nodejs-repl.el (which is based on comint-mode) when C++ style comments are mixed with quotations.

For example, when evaluated using nodejs-repl-send-region, the following line:

var says = function ( ) {  return this.saying || ''; };

gives an error :

var says = function ( ) {  return this.saying   ''; };
SyntaxError: repl: Unexpected token, expected ; (1:48)
> 1 | var says = function ( ) {  return this.saying   ''; };

|| seems to have been dropped. There is no error if I replace || with +.

Another example:

var url = "http://www.ora.com:80/goodparts?q#fragment";


> var url = "http:/*www.ora.com:80/goodparts?q#fragment"; */
SyntaxError: repl: Unexpected token (1:56)
> 1 | var url = "http:/*www.ora.com:80/goodparts?q#fragment"; */

Here, http:// seems to be misinterpreted as http:/*, beginning a comment, despite the fact that // is in a quote.

In both cases, the error only occurs when the problem lines are sent from the buffer to the REPL using nodejs-repl-send-region. No error is returned if the line is evaluated directly in the REPL.

Can anyone please help explain how to fix my Emacs environment (maybe nodejs-repl.el or the underlying comint-mode)?

I have tested this under Emacs 24.5 (Ubuntu 16.04) with a minimal .emacs.d/init.el file below (as suggested by the nodejs-repl.el homepage):

$ cat .emacs.d/init.el
(add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))

(require 'comint)
(add-to-list 'comint-preoutput-filter-functions
         (lambda (output)
           (let ((case-fold-search nil))
         (replace-regexp-in-string "\033\\[[0-9]+[A-Z]" "" output))))

(setq babel-repl-cli-arguments '("--presets"  "es2015" ))

;; Interactive commands
(eval-after-load 'js2-mode '(progn
  (define-key js2-mode-map (kbd "C-c C-b") 'babel-repl-send-buffer)
  (define-key js2-mode-map (kbd "C-c C-z") 'babel-repl)
  (define-key js2-mode-map (kbd "C-c C-r") 'babel-repl-send-current-region)

Other than the init.el, I have installed babel-repl using ELPA and its folder looks like:


-- EDIT --

@db48x Further info about my system:

emacs -Q works fine with a normal welcome screen. So does emacs --debug-init and emacs --debug-init -Q. emacs --version says GNU Emacs 24.5.1.

If tested with the following .js file:

$ cat test2.js 
var says = function ( ) {  return this.saying || ''; };

the outcome is:

$ emacs --script test2.js 
Loading 00debian-vars...
Loading /etc/emacs/site-start.d/50autoconf.el (source)...
Loading /etc/emacs/site-start.d/50cmake-data.el (source)...
Loading /etc/emacs/site-start.d/50dictionaries-common.el (source)...
Loading debian-ispell...
Loading /var/cache/dictionaries-common/emacsen-ispell-default.el (source)...
Loading /var/cache/dictionaries-common/emacsen-ispell-dicts.el (source)...
Loading /etc/emacs/site-start.d/50mmm-mode.el (source)...
Loading /etc/emacs/site-start.d/50proofgeneral.el (source)...
Loading /usr/share/emacs24/site-lisp/proofgeneral/generic/proof-site.elc...
Loading /etc/emacs/site-start.d/50psvn.el (source)...
Loading /etc/emacs/site-start.d/50python-docutils.el (source)...
Symbol's value as variable is void: var
  • I can't reproduce the problem, with or without your configuration options. Does the problem still happen if you run emacs -Q? What about if you run emacs -Q but specifically run those two lines of your emacs configuration? Does the problem go away if you upgrade to Emacs 25? – db48x May 27 '17 at 9:18
  • run emacs -Q, then open up your init.el and use C-x C-e to execute just the lines you care about. Then you can compare the results after executing each one, and see (if) they're the cause. – db48x May 27 '17 at 15:42
  • @db48x Thanks. But when I use C-x C-e to evaluate init.el, the line (add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode)) does not seem to have effect on .js files that I am opening (C-x C-f) for test. Nor is the babl-repl command available via M x. The init.el above is complete. Am I missing some other system wide configuration files that load e.g. elpa/? – user15945 May 27 '17 at 15:54
  • Well, before we dive into that, what was the result with just emacs -Q? If the bug still occurs, then the problem is not your configuration. – db48x May 27 '17 at 17:07
  • @db48x I've added updated info about my emacs configuration. Please see the edit. – user15945 May 27 '17 at 22:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy