~ubuntu-branches/ubuntu/utopic/codemirror-js/utopic

« back to all changes in this revision

Viewing changes to demo/emacs.html

  • Committer: Package Import Robot
  • Author(s): David Paleino
  • Date: 2012-04-12 12:25:28 UTC
  • Revision ID: package-import@ubuntu.com-20120412122528-8xp5a8frj4h1d3ee
Tags: upstream-2.23
ImportĀ upstreamĀ versionĀ 2.23

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!doctype html>
 
2
<html>
 
3
  <head>
 
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">
 
10
 
 
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
 
 
18
    <form><textarea id="code" name="code">
 
19
#include "syscalls.h"
 
20
/* getchar:  simple buffered version */
 
21
int getchar(void)
 
22
{
 
23
  static char buf[BUFSIZ];
 
24
  static char *bufp = buf;
 
25
  static int n = 0;
 
26
  if (n == 0) {  /* buffer is empty */
 
27
    n = read(0, buf, sizeof buf);
 
28
    bufp = buf;
 
29
  }
 
30
  return (--n >= 0) ? (unsigned char) *bufp++ : EOF;
 
31
}
 
32
</textarea></form>
 
33
 
 
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>
 
39
 
 
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>
 
44
 
 
45
    <script>
 
46
      CodeMirror.commands.save = function() {
 
47
        var elt = editor.getWrapperElement();
 
48
        elt.style.background = "#def";
 
49
        setTimeout(function() { elt.style.background = ""; }, 300);
 
50
      };
 
51
      var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
 
52
        lineNumbers: true,
 
53
        mode: "text/x-csrc",
 
54
        keyMap: "emacs"
 
55
      });
 
56
    </script>
 
57
 
 
58
  </body>
 
59
</html>