简体   繁体   中英

Node REPL in Emacs printing my input

I am having troubles setting up some details in my node REPL:

Whenever I type a command into the prompt this command is reprinted before I get the real output from the REPL. For example:

var n = 1; var n = 1; undefined

I tried to use some code from balajis repo https://github.com/startup-class/dotfiles/blob/master/.emacs.d/js-comint.el , but afterwards my Mx run-js command didn't work.

Here is my init file (I haven't edited my js-comint.el):

(normal-erase-is-backspace-mode 1)


(add-to-list 'load-path "~/.emacs.d/")
(add-to-list 'load-path "~/.emacs.d/auto-complete/")
; Load the default configuration                                                                             
(require 'auto-complete-config)
; Make sure we can find the dictionaries                                                                     
(add-to-list 'ac-dictionary-directories "~/.emacs.d/auto-complete/dict")
; Use dictionaries by default                                                                                
(setq-default ac-sources (add-to-list 'ac-sources 'ac-source-dictionary))
(global-auto-complete-mode t)
; Start auto-completion after 2 characters of a word                                                         
(setq ac-auto-start 2)
; case sensitivity is important when finding matches                                                         
(setq ac-ignore-case nil)
(add-to-list 'load-path "~/.emacs.d/yasnippet/")
(require 'yasnippet)
(yas-global-mode 1)
;; Load the snippet files themselves                                                                         
(yas/load-directory "~/.emacs.d/yasnippet/snippets/text-mode/javascript-mode/")
;; Let's have snippets in the auto-complete dropdown                                                         
(add-to-list 'ac-sources 'ac-source-yasnippet)

(add-to-list 'auto-mode-alist (cons (rx ".js" eos) 'js2-mode))

(require 'js-comint)
(setq inferior-js-program-command "/usr/bin/java org.mozilla.javascript.tools.shell.Main")
(setq inferior-js-program-command "node")

(setq inferior-js-mode-hook
      (lambda ()
        ;; We like nice colors                                                                               
        (ansi-color-for-comint-mode-on)
        ;; Deal with some prompt nonsense                                                                    
        (add-to-list
         'comint-preoutput-filter-functions
         (lambda (output)
           (replace-regexp-in-string "\033\\[[0-9]+[GKCJ]" "" output)))))

(add-hook 'js2-mode-hook '(lambda ()
                           (local-set-key "\C-x\C-e" 'eval-last-sexp)
                           (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)
                           (local-set-key "\C-c!" 'run-js)
                           (local-set-key "\C-c\C-r" 'js-send-region)
                           (local-set-key "\C-c\C-j" 'js-send-line)
                           (local-set-key "\C-c\C-u" 'whitespace-clean-and-compile)
                           ))

If you are ok with changing the approach to solving the problem slightly, you could use replpad instead. It works with any editor, automatically updating whenever a file changes.

Simply install it via: npm install -g replpad

Then use it by running: replpad

If you want it to watch all files in the current and all subdirectories and pipe them into the repl when they change do: replpad .

More details in this answer

This should fix it:

(add-hook 'inferior-js-mode-hook
          (lambda ()
            (setq comint-process-echoes t)))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM