Sha256: fc1cabe14d2196e4d2cce8f4285e80b783057780a39f98ccf5027f7a03ac3100

Contents?: true

Size: 1.43 KB

Versions: 17

Compression:

Stored size: 1.43 KB

Contents

<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <title>CodeMirror: Mode-Changing Demo</title>
    <link rel="stylesheet" href="../lib/codemirror.css">
    <script src="../lib/codemirror.js"></script>
    <script src="../mode/javascript/javascript.js"></script>
    <script src="../mode/scheme/scheme.js"></script>
    <link rel="stylesheet" href="../doc/docs.css">

    <style type="text/css">
      .CodeMirror {border: 1px solid black;}
    </style>
  </head>
  <body>
    <h1>CodeMirror: Mode-Changing demo</h1>

    <form><textarea id="code" name="code">
;; If there is Scheme code in here, the editor will be in Scheme mode.
;; If you put in JS instead, it'll switch to JS mode.

(define (double x)
  (* x x))
</textarea></form>

<p>On changes to the content of the above editor, a (crude) script
tries to auto-detect the language used, and switches the editor to
either JavaScript or Scheme mode based on that.</p>

<script>
  var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
    mode: "scheme",
    lineNumbers: true,
    tabMode: "indent"
  });
  editor.on("change", function() {
    clearTimeout(pending);
    setTimeout(update, 400);
  });
  var pending;
  function looksLikeScheme(code) {
    return !/^\s*\(\s*function\b/.test(code) && /^\s*[;\(]/.test(code);
  }
  function update() {
    editor.setOption("mode", looksLikeScheme(editor.getValue()) ? "scheme" : "javascript");
  }
</script>
  </body>
</html>

Version data entries

17 entries across 17 versions & 3 rubygems

Version Path
mdbe-0.1.0 public/libs/codemirror/demo/changemode.html
bonethug-0.0.17 skel/project_types/silverstripe3/public/abc/lib/codemirror/demo/changemode.html
bonethug-0.0.16 skel/project_types/silverstripe3/public/abc/lib/codemirror/demo/changemode.html
bonethug-0.0.15 skel/project_types/silverstripe3/public/abc/lib/codemirror/demo/changemode.html
bonethug-0.0.14 skel/project_types/silverstripe3/public/abc/lib/codemirror/demo/changemode.html
bonethug-0.0.13 skel/project_types/silverstripe3/public/abc/lib/codemirror/demo/changemode.html
bonethug-0.0.12 skel/project_types/silverstripe3/public/abc/lib/codemirror/demo/changemode.html
bonethug-0.0.11 skel/project_types/silverstripe3/public/abc/lib/codemirror/demo/changemode.html
bonethug-0.0.10 skel/project_types/silverstripe3/public/abc/lib/codemirror/demo/changemode.html
bonethug-0.0.7 skel/project_types/silverstripe3/public/abc/lib/codemirror/demo/changemode.html
bonethug-0.0.6 skel/project_types/silverstripe3/public/abc/lib/codemirror/demo/changemode.html
bonethug-0.0.5 skel/project_types/silverstripe3/public/abc/lib/codemirror/demo/changemode.html
maglev-database-explorer-0.0.5 public/libs/codemirror/demo/changemode.html
maglev-database-explorer-0.0.4 public/libs/codemirror/demo/changemode.html
maglev-database-explorer-0.0.3 public/libs/codemirror/demo/changemode.html
maglev-database-explorer-0.0.2 public/libs/codemirror/demo/changemode.html
maglev-database-explorer-0.0.1 public/libs/codemirror/demo/changemode.html