baruchel / vim-notebook

A plugin for the Vim editor for handling any interpreter in a Notebook style
MIT License
95 stars 7 forks source link

Configuring vim-notebook for node #5

Open jonahx opened 7 years ago

jonahx commented 7 years ago

I've tried the following configuration:

" attempt at node
let g:notebook_cmd = 'NODE_DISABLE_COLORS=1 node'
let g:notebook_stop = "process.exit()"
let g:notebook_send0 = ""
let g:notebook_send = "'VIMNODENOTEBOOK'"
let g:notebook_detect = "'VIMNODENOTEBOOK'"

Note that the final two lines reflect the fact that node echoes back quotes when literal strings are entered:

Node REPL

However, when I :NotebookStart, vim just hangs and needs to be killed. Do you know the correct settings for node? If not, any tips for debugging or what I might attempt to make it work?

Thanks!

baruchel commented 7 years ago

Hi, thank you for your interest; using it with Node actually is a good idea. I will have a look at it very soon unless you solve it before me. Most of the time issues are fixed by wrapping the main program in some unbuffer, stdbuf or even script for unbuffering its input/output. Regards.

baruchel commented 7 years ago

I got working settings though a little hacky. First, try to launch it with node -i (though I didn't check it was absolutely necessary). Then add the two characters of the prompt > (greater than followed by one space before the expected output); what I used was:

let g:notebook_sed='console.log(\"VIMNODENOTEBOOK\");'
let g:notebook_detect='> VIMNODENOTEBOOK'

because the prompt is merged with the output. Please, let me know if you get something working. Maybe there is a way to disable the prompt, which would be cleaner.

jonahx commented 7 years ago

Thanks. I got it working with that, but it still outputs the prompt, and, perhaps more difficult to address, it outputs the result of every line, including variable assignments. Probably what you want is for only console.log statements and the result of the final line in a code block to be shown. Any idea how difficult that change would be?

Also, if you do any node dev yourself, I just discovered this, which looks promising (though has the drawback of not existing within vim itself): https://runkit.com