emacs.html (2476B)
1 <!doctype html> 2 3 <title>CodeMirror: Emacs bindings demo</title> 4 <meta charset="utf-8"/> 5 <link rel=stylesheet href="../doc/docs.css"> 6 7 <link rel="stylesheet" href="../lib/codemirror.css"> 8 <link rel="stylesheet" href="../addon/dialog/dialog.css"> 9 <script src="../lib/codemirror.js"></script> 10 <script src="../mode/clike/clike.js"></script> 11 <script src="../keymap/emacs.js"></script> 12 <script src="../addon/edit/matchbrackets.js"></script> 13 <script src="../addon/comment/comment.js"></script> 14 <script src="../addon/dialog/dialog.js"></script> 15 <script src="../addon/search/searchcursor.js"></script> 16 <script src="../addon/search/search.js"></script> 17 <style type="text/css"> 18 .CodeMirror {border-top: 1px solid #eee; border-bottom: 1px solid #eee;} 19 </style> 20 <div id=nav> 21 <a href="http://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../doc/logo.png"></a> 22 23 <ul> 24 <li><a href="../index.html">Home</a> 25 <li><a href="../doc/manual.html">Manual</a> 26 <li><a href="https://github.com/codemirror/codemirror">Code</a> 27 </ul> 28 <ul> 29 <li><a class=active href="#">Emacs bindings</a> 30 </ul> 31 </div> 32 33 <article> 34 <h2>Emacs bindings demo</h2> 35 <form><textarea id="code" name="code"> 36 #include "syscalls.h" 37 /* getchar: simple buffered version */ 38 int getchar(void) 39 { 40 static char buf[BUFSIZ]; 41 static char *bufp = buf; 42 static int n = 0; 43 if (n == 0) { /* buffer is empty */ 44 n = read(0, buf, sizeof buf); 45 bufp = buf; 46 } 47 return (--n >= 0) ? (unsigned char) *bufp++ : EOF; 48 } 49 </textarea></form> 50 51 <p>The emacs keybindings are enabled by 52 including <a href="../keymap/emacs.js">keymap/emacs.js</a> and setting 53 the <code>keyMap</code> option to <code>"emacs"</code>. Because 54 CodeMirror's internal API is quite different from Emacs, they are only 55 a loose approximation of actual emacs bindings, though.</p> 56 57 <p>Also note that a lot of browsers disallow certain keys from being 58 captured. For example, Chrome blocks both Ctrl-W and Ctrl-N, with the 59 result that idiomatic use of Emacs keys will constantly close your tab 60 or open a new window.</p> 61 62 <script> 63 CodeMirror.commands.save = function() { 64 var elt = editor.getWrapperElement(); 65 elt.style.background = "#def"; 66 setTimeout(function() { elt.style.background = ""; }, 300); 67 }; 68 var editor = CodeMirror.fromTextArea(document.getElementById("code"), { 69 lineNumbers: true, 70 mode: "text/x-csrc", 71 keyMap: "emacs" 72 }); 73 </script> 74 75 </article>