I’m trying to use loadmode.js, more specifically autoLoadMode.

In my tests, I do

codeMirror.autoLoadMode(editor, “python”);

(codeMirror is a CodeMirror object loaded by requirejs)

But while I see the <script> element being added (and the content is retrieved correctly), The mode is never loaded in my codeMirror instance. The codeMirror.modes object never has a “python” property and of course the editor is never updated to set the mode.

I was wondering: is loadmode.js compatible with require.js ?

In principle loadmode should work with require.js. Have you tried adding a console.log to the top level of python.js to see if it is actually being ran?

The script itself is called, the ’ (function(mod) {…} ’ itself is executed, the require.js ‘define’ function is called, but if I understand everything correctly, the ‘load’ event listener is not added so the function is never applied to the CodeMirror object.

Oh. That’s odd – can you put together a demo that illustrates the problem? For some reason, loadmode appears to be polling instead of registering a "load" handler on the script tag. In the demo, this works fine, but I guess something is going wrong in your setup.

Well it does the poll

var count = 0, poll = setInterval(function() {

  if (++count &gt; 100) return clearInterval(poll);

  if (CodeMirror.modes.hasOwnProperty(mode)) {

I follow it using breakpoints, and I see it fail each time the hasOwnProperty(mode).

That suggests the mode is not actually being loaded successfully. Does the define call in python.js actually end up calling the module body? (The function that makes the defineMode call.)

No it never reaches the module body.

I tried to set an example.


That’s very different from what I have (my app is GWT with JSO).

It seems requirejs gets very confused when a define call occurs in a script that it did not itself load. That seems unnecessarily lame, but I’ve updated the loadmode module to simply use the module loader when one is present, and that should work around this. See this patch

Thanks you.

I wasn’t able to test that yet, I’ll keep you informed.