Supports Win/Linux/Mac up to Vim 8.0
It use PyV8 as javascript interpreter. if PyV8 not supported, it use node, cscript, spiderMonkey as fallbacks, it aslo create a browser-based context to execute javascript code if PyV8 is supported.
Copy everything inside autoload to autoload directory of your vim
- sourcebeautify.vim source code beautifier
- jsflakes.vim lint javascript code on the fly
It is a basic library. It does nothing if no other plugin calls it. If you are a vim plugin developer and want to use this library. You need to check if this library exist
try
call javascript#runtime#evalScript("")
let jsruntimePluginAvailable = 1
catch E117
let jsruntimePluginAvailable = 0
endtry
if jsruntimePluginAvailable
" your code
endif
This library is often used with jsoncodecs.vim.
javascript#runtime#evalScript(jsoncodecs#dump_string(getline(1,'$')))
It provide the following functions
-
javascript#runtime#evalScript({script}, {renew_context})
:echo javascript#runtime#evalScript('1+2') // output 3
renew_context is a flag to indicate whether keep the context created by script before
:call javascript#runtime#evalScript('a=3') // we create a context :echo javascript#runtime#evalScript('a;') // we eval this script in context created before // output 1 :echo javascript#runtime#evalScript('a;',1) // we eval this script in a completely new context // output undefined
renew_context is not guaranteed support, if not support renew_context will be simply ignored, please
read javascript#runtime#supportLivingContext for more.
-
javascript#runtime#evalScriptInBrowserContext
because we only implement browser interface using PyV8, so if PyV8 is not supported, this function will not exist, check existence before use
// vim script if exists('javascript#runtime#evalScriptInBrowserContext') // do what you like endif
sample
:call javascript#runtime#evalScriptInBrowserContext('<html><body onload="console.log(1+2);"><p></p></body></html>') //output 3
-
javascript#runtime#isSupportLivingContext
you can use javascript#runtime#isSupportLivingContext to check whether living_context is supported by jsruntime