[IPython-dev] Notebook codemirror support for language not distributed with codemirror?

Tom Quarendon tom.quarendon at teamwpc.co.uk
Mon Nov 16 09:03:00 EST 2015

OK, I posted too hastily :-)

If in my kernel.js file I put:
/* following myst go here, not inside define, and not inside onload. */
function(require) {
	return {
		onload: function() {

Then it works :-)

In case anyone else encounters the same.


-----Original Message-----
From: IPython-dev [mailto:ipython-dev-bounces at scipy.org] On Behalf Of Tom Quarendon
Sent: 16 November 2015 13:57
To: IPython developers list <ipython-dev at scipy.org>
Subject: Re: [IPython-dev] Notebook codemirror support for language not distributed with codemirror?

> You can drop a kernel.js next to your kernel.json  at installation 
> time, it should  describe an AMD module that define an `onload` method 
> that will be called when you switch to your kernel.

What I'd *really* like to be able to do, but so far have failed, is modify the require.js configuration from within my kernel.js file.

So my code mirror mode makes us of another javascript library to provide the actual tokenisation and linting code that the code mirror mode then consumes. It finds that code through dependencies, but the way that I've written it requires that there be a path set up in require. So in other words my CodeMirror mode looks like:

	"A/lint" ],
function(require, CodeMirror, tokenizer, linter) {
  CodeMirror.defineMode("mymode", ...

Now maybe this shows my lack of experience with require.js (which amounts to about a week), but I did it this way as I wanted to separate the interesting parts (the tokenisation and linting) and reuse them elsewhere easily, as this is code that can be used outside of CodeMirror.

Anyway, upshot is that what I really want to do in my kernel.js is add to the require configuration to say that path "A" should resolve to "kernelspecs/mykernel/js". 

I suspect though that I can't do this? I suspect that I need to accept that anywhere I use my CodeMirror mode, it finds its dependencies in the same directory, so I refer to them as "./tokenizer" and "./linter" etc.


IPython-dev mailing list
IPython-dev at scipy.org

More information about the IPython-dev mailing list