I’m writing an elisp module that requires an external text file.
For the curious, the module integrates the interactive JS REPL for Cscript.exe with shell mode in emacs.
It allows me to run an interactive javascript shell in emacs, on Windows.
This was motivated by js-comint.el, but is a separate implementation dependent upon Windows and cscript.exe.
It’s currently working, but there are two distinct files: the .el file and the .js file. I’d prefer to have just one file.
The question I have is this: how can I package the external .js file which is a pre-requisite for this thing, into the .el file, so that I can have a one-file install?
I imagine I could just define a string variable with the (maybe minified) js file and insert that into the .el module. I suppose there will be a few string-escapement issues but this will work. Is that the best way? Any other suggestions?
ok, I didn’t find a better way to do this. But I did decide that embedding the Javascript code into the elisp module as a string… worked pretty well.
To make it happen, I wrote a short elisp function, which creates a new elisp module.
It picks a new name based on the old name – xxxx-bundle.el instead of xxxx.el . Then it writes the content from the original .el file into a file with the new name. Then it writes a simple
setqstatement into the same file; the entire Javascript program is the literal string value in that statement. The thing that makes thesetqeasy is thepp-to-stringfunction in elisp, which escapes all the Javascript code into a literal string suitable for use in emacs.The fn to generate the bundle Looks like this:
The helper fn to minimize the contents just collapses whitespace and eliminates consecutive newlines, that sort of thing.
The resulting .el file can then reference the variable,
jsshell-js-src, which contains the minimized Javascript source. It looks like this:I’m posting this here because I think the approach would probably be useful in other modules as well – anything that needs to bundle a separate data file.