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

Matthias Bussonnier bussonniermatthias at gmail.com
Mon Nov 16 11:18:07 EST 2015


Having to do that is definitively annoying. Can you open a bug report so that we can find a better solution ?

Envoyé de mon iPhone

> Le 16 nov. 2015 à 06:03, Tom Quarendon <tom.quarendon at teamwpc.co.uk> a écrit :
> 
> 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: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:
> 
> 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
> IPython-dev at scipy.org
> https://mail.scipy.org/mailman/listinfo/ipython-dev
> _______________________________________________
> IPython-dev mailing list
> IPython-dev at scipy.org
> https://mail.scipy.org/mailman/listinfo/ipython-dev



More information about the IPython-dev mailing list