codemirror-ipython.ts 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. // IPython mode is just a slightly altered Python Mode with `?` beeing a extra
  2. // single operator. Here we define `ipython` mode in the require `python`
  3. // callback to auto-load python mode, which is more likely not the best things
  4. // to do, but at least the simple one for now.
  5. "use strict";
  6. import * as CodeMirror
  7. from 'codemirror';
  8. import "codemirror/mode/python/python";
  9. CodeMirror.defineMode("ipython", (config: CodeMirror.EditorConfiguration, modeOptions: any) => {
  10. var pythonConf: any = {};
  11. for (var prop in modeOptions) {
  12. if (modeOptions.hasOwnProperty(prop)) {
  13. (pythonConf as any)[prop] = (modeOptions as any)[prop];
  14. }
  15. }
  16. pythonConf.name = 'python';
  17. pythonConf.singleOperators = new RegExp("^[\\+\\-\\*/%&|\\^~<>!\\?]");
  18. if (pythonConf.version === 3) {
  19. pythonConf.identifiers = new RegExp("^[_A-Za-z\u00A1-\uFFFF][_A-Za-z0-9\u00A1-\uFFFF]*");
  20. } else if (pythonConf.version === 2) {
  21. pythonConf.identifiers = new RegExp("^[_A-Za-z][_A-Za-z0-9]*");
  22. }
  23. return CodeMirror.getMode(config, pythonConf);
  24. }, 'python');
  25. CodeMirror.defineMIME("text/x-ipython", "ipython");