5 <title>CodeMirror: Emacs bindings demo</title>
6 <link rel="stylesheet" href="../lib/codemirror.css">
7 <script src="../lib/codemirror.js"></script>
8 <script src="../mode/clike/clike.js"></script>
9 <script src="../keymap/emacs.js"></script>
10 <script src="../addon/edit/matchbrackets.js"></script>
11 <script src="../addon/comment/comment.js"></script>
12 <script src="../addon/dialog/dialog.js"></script>
13 <script src="../addon/search/searchcursor.js"></script>
14 <script src="../addon/search/search.js"></script>
15 <link rel="stylesheet" href="../addon/dialog/dialog.css">
16 <link rel="stylesheet" href="../doc/docs.css">
18 <style type="text/css">
19 .CodeMirror {border-top: 1px solid #eee; border-bottom: 1px solid #eee;}
23 <h1>CodeMirror: Emacs bindings demo</h1>
25 <form><textarea id="code" name="code">
27 /* getchar: simple buffered version */
30 static char buf[BUFSIZ];
31 static char *bufp = buf;
33 if (n == 0) { /* buffer is empty */
34 n = read(0, buf, sizeof buf);
37 return (--n >= 0) ? (unsigned char) *bufp++ : EOF;
41 <p>The emacs keybindings are enabled by
42 including <a href="../keymap/emacs.js">keymap/emacs.js</a> and setting
43 the <code>keyMap</code> option to <code>"emacs"</code>. Because
44 CodeMirror's internal API is quite different from Emacs, they are only
45 a loose approximation of actual emacs bindings, though.</p>
47 <p>Also note that a lot of browsers disallow certain keys from being
48 captured. For example, Chrome blocks both Ctrl-W and Ctrl-N, with the
49 result that idiomatic use of Emacs keys will constantly close your tab
50 or open a new window.</p>
53 CodeMirror.commands.save = function() {
54 var elt = editor.getWrapperElement();
55 elt.style.background = "#def";
56 setTimeout(function() { elt.style.background = ""; }, 300);
58 var editor = CodeMirror.fromTextArea(document.getElementById("code"), {