CodeMirror mode apparently not being applied -- need help troubleshooting

Hi, I am trying to create a CodeMirror mode for Maxima (a computer algebra system, project page: for use in the IPython notebook. From what I understand, IPython uses CodeMirror to highlight code in the notebook so I am just trying to extend that to Maxima code. I have already gotten the IPython front end to talk to a Maxima kernel (IPython back end) so that’s great.

I created a maxima.js mode file by modifying the existing Mathematica mode. Following instructions from IPython, I’ve put a statement to load maxima.js in the JS code which is always loaded by IPython.

From what I can tell, the attempt to load maxima.js (via jQuery getScript) succeeds. However, the CodeMirror.requireMode is either never called or fails, and there is no highlighting applied in the browser.

Can anyone think of something I can try to debug this? I know this is not much to go on, but unfortunately I don’t have a simple, reproducible example, as this stuff is a work in progress and has many dependencies which would make it very time consuming for anyone else to try.

For the record, here are the relevant lines from the code which is supposed to load maxima.js:


 $.getScript('/static/components/codemirror/mode/maxima/maxima.js').done (function (script, textStatus) { console.log ('HEY APPARENTLY SUCCESSFUL GETSCRIPT FOR MAXIMA.JS; STATUS=' + textStatus); }).fail (function (jqhxr, settings, exception) { console.log ('HEY GETSCRIPT ERROR: ' + jqhxr + ', ' + settings + ', ' + exception); });

console.log ('HEY CODEMIRROR.MODEURL=' + CodeMirror.modeURL);
CodeMirror.requireMode('maxima', function(){

This is certainly a mess and I apologize for its terrible appearance. I do see the messages “PER-PAGELOAD STUFF”, “APPARENTLY SUCCESSFUL GETSCRIPT”, and “CODEMIRROR.MODEURL” in the web browser console, but I don’t see “MAXIMA MODE SHOULD NOW BE AVAILABLE”. (By the way, about the modeURL, it is indeed pointing to the location where maxima.js lives.)

I’ll let this be enough for now; I’ll be happy to post additional info as needed. Thanks for your time, and thanks for any light you can shed on this problem.


Robert Dodier

If you’ve already loaded maxima.js, why are you calling requireMode on it in the first place?

Marijn, thanks for your reply. As to why I am calling requireMode, well, I am copying someone else’s code which had that in it. I’m not sure that code was working, so I may well be copying something that isn’t working to start with. But if the requireMode call is superfluous, it shouldn’t cause any harm, right?

The bigger picture that I am not seeing is, how is CodeMirror triggered anyway? Apparently my CodeMirror mode (maxima.js) is loaded successfully, yet I don’t see any highlighting applied, nor do I see any of the console.log output from maxima.js. Again, since I am working from someone else’s project, there may be something lacking that I need to ensure in order to get CodeMirror to work. In general, how is CodeMirror supposed to be hooked into an application?

I have attached maxima.js to this message for reference. Any advice is greatly appreciated.


Robert Dodier

PS. Here is my mode file.
maxima.js (3.8 KB)

A quick update: I was able to get my maxima.js mode loaded by putting it in the system installation directory, which I discovered by running Jupyter with the --debug option and noting the location from which the notebook server was successfully loading JS extensions. Highlighting now works as expected in the Jupyter notebook.

I had been trying to put maxima.js somewhere in my home directory (under ~/.ipython) but was never able to get that to work. Incidentally custom.js is unneeded now.

Just posting this message in case someone else runs into a similar problem.


Robert Dodier

These are all ipython-related questions and observations though, and as such would fit better on an ipython-related forum.