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