Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot load codemirror mode dynamically #54

Open
BoPeng opened this issue Mar 26, 2018 · 2 comments
Open

Cannot load codemirror mode dynamically #54

BoPeng opened this issue Mar 26, 2018 · 2 comments

Comments

@BoPeng
Copy link
Contributor

BoPeng commented Mar 26, 2018

The following patch load mode only when they are needed. It is supposed to work but somehow does not.

diff --git a/src/sos_notebook/kernel.js b/src/sos_notebook/kernel.js
index e5d340c..5b7165a 100644
--- a/src/sos_notebook/kernel.js
+++ b/src/sos_notebook/kernel.js
@@ -25,13 +25,7 @@ define([
     "codemirror/lib/codemirror",
     "codemirror/mode/python/python",
     "codemirror/mode/r/r",
-    "codemirror/mode/octave/octave",
-    "codemirror/mode/ruby/ruby",
-    "codemirror/mode/sas/sas",
-    "codemirror/mode/javascript/javascript",
-    "codemirror/mode/shell/shell",
-    "codemirror/mode/julia/julia",
-    "codemirror/mode/markdown/markdown",
+    'codemirror/lib/util/loadmode',
     "codemirror/addon/selection/active-line",
     "codemirror/addon/fold/foldcode",
     "codemirror/addon/fold/foldgutter",
@@ -2100,6 +2094,7 @@ table.task_table {
 
             "use strict";
 
+            CodeMirror.modeURL = "codemirror/mode/%N/%N.js";
             var sosKeywords = ["input", "output", "depends", "parameter"];
             var sosActionWords = ["script", "download", "run", "bash", "sh", "csh",
                 "tcsh", "zsh", "python", "python2", "python3", "R", "node", "julia",
@@ -2252,7 +2247,7 @@ table.task_table {
                 if ('base_mode' in parserConf) {
                     let mode = findMode(parserConf.base_mode.toLowerCase());
                     if (mode) {
-                        base_mode = CodeMirror.getMode(conf, mode);
+                        base_mode = CodeMirror.loadMode(conf, mode);
                     } else {
                         console.log(`No base mode is found for ${parserConf.base_mode}. Python mode used.`);
                     }
@@ -2502,7 +2497,7 @@ table.task_table {
                                     let mode = findMode(state.sos_state.slice(6).toLowerCase());
                                     if (mode) {
                                         state.sos_state = null;
-                                        state.inner_mode = CodeMirror.getMode(conf, mode);
+                                        state.inner_mode = CodeMirror.loadMode(conf, mode);
                                         state.inner_state = CodeMirror.startState(state.inner_mode);
                                     } else {
                                         state.sos_state = 'nomanland';
@BoPeng
Copy link
Contributor Author

BoPeng commented Mar 26, 2018

Jupyter has (autoLoadMode)[https://github.com/jupyter/notebook/blob/master/notebook/static/notebook/js/cell.js#L642] here but it is not used.

@BoPeng
Copy link
Contributor Author

BoPeng commented Jan 23, 2019

If this can be fixed, we can not only remove most of the modes statically imported in here, but also lines in the template because the modes have to be statically imported to be used by the template, which also means we are limited to these langauges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants