emacs.html 1.8 KB

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