emacs.html 2.4 KB

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