Fix: merge conflict
[myslice.git] / third-party / codemirror-3.15 / demo / changemode.html
1 <!doctype html>
2 <html>
3   <head>
4     <meta charset="utf-8">
5     <title>CodeMirror: Mode-Changing Demo</title>
6     <link rel="stylesheet" href="../lib/codemirror.css">
7     <script src="../lib/codemirror.js"></script>
8     <script src="../mode/javascript/javascript.js"></script>
9     <script src="../mode/scheme/scheme.js"></script>
10     <link rel="stylesheet" href="../doc/docs.css">
11
12     <style type="text/css">
13       .CodeMirror {border: 1px solid black;}
14     </style>
15   </head>
16   <body>
17     <h1>CodeMirror: Mode-Changing demo</h1>
18
19     <form><textarea id="code" name="code">
20 ;; If there is Scheme code in here, the editor will be in Scheme mode.
21 ;; If you put in JS instead, it'll switch to JS mode.
22
23 (define (double x)
24   (* x x))
25 </textarea></form>
26
27 <p>On changes to the content of the above editor, a (crude) script
28 tries to auto-detect the language used, and switches the editor to
29 either JavaScript or Scheme mode based on that.</p>
30
31 <script>
32   var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
33     mode: "scheme",
34     lineNumbers: true,
35     tabMode: "indent"
36   });
37   editor.on("change", function() {
38     clearTimeout(pending);
39     setTimeout(update, 400);
40   });
41   var pending;
42   function looksLikeScheme(code) {
43     return !/^\s*\(\s*function\b/.test(code) && /^\s*[;\(]/.test(code);
44   }
45   function update() {
46     editor.setOption("mode", looksLikeScheme(editor.getValue()) ? "scheme" : "javascript");
47   }
48 </script>
49   </body>
50 </html>