Re: Notebook codemirror support for language not distributed with codemirror?

Tom Quarendon <[email protected]>
Newsgroups gmane.comp.python.ipython.devel
Message-ID <AM2PR05MB0771538EF957124338C46102B01E0@AM2PR05MB0771.eurprd05.prod.outlook.com>
OK, I posted too hastily :-)

If in my kernel.js file I put:
/* following myst go here, not inside define, and not inside onload. */
requirejs({
	paths:{
		A:"/kernelspecs/mykernel/js"
	}
});
define(
function(require) {
	return {
		onload: function() {
			require('kernelspecs/mykernel/js/mymode');	
		}
	};
});

Then it works :-)

In case anyone else encounters the same.

Thanks.

-----Original Message-----
From: IPython-dev [mailto:[email protected]] On Behalf Of Tom Quarendon
Sent: 16 November 2015 13:57
To: IPython developers list <[email protected]>
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:

define(["require", 
	"codemirror/lib/codemirror", 
	"A/tokenization", 
	"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.

Thanks.

_______________________________________________
IPython-dev mailing list
[email protected]
https://mail.scipy.org/mailman/listinfo/ipython-dev
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.