ipython/ipython — pull request #6996 by bollwyvl (2014-11-20 03:15:00+00:00)
Title: Using codemirror mode/meta for mode detection

Many modes aren't being highlighted with `CodeMirror.runMode` that are supported because they don't follow the `mode\mode` pattern: `json` is `javascript`, `bash` is `shell`, etc. Luckily, as of 4.7, the metadata contained in the [meta addon](http://codemirror.net/doc/manual.html#addon_meta) can do a pretty good job based on different strategies, while `master` is even better.

This PR uses `CodeMirror`'s `.modes.hasOwnProperty`, `.findModeByName`, `.findModeByExtension`, and `.findModeByMIME` successively to try to find a matching mode. `.findModeByName` is monkeypatched in from `master`.

`requireCodeMirrorMode` now also returns the "special," MIME-less mode name (like `ipythongfm`) or the "canonical" mode name (a MIME type), which `getMode` can use to return the best possible mode: previously, the argument to the callback were more inconsistent: sometimes the mode function, sometimes whatever comes out of `require` (usually nothing).

Tests added, but really just testing the resolution for common modes... but a lot of things will have had to have worked for that to work, I suppose.

Potential shortcomings:
- the `find*` methods might be expensive... memoize?
- still sometimes immediately calling require... promise might be better?