emacs.js 1.4 KB

123456789101112131415161718192021222324252627282930
  1. // TODO number prefixes
  2. (function() {
  3. // Really primitive kill-ring implementation.
  4. var killRing = [];
  5. function addToRing(str) {
  6. killRing.push(str);
  7. if (killRing.length > 50) killRing.shift();
  8. }
  9. function getFromRing() { return killRing[killRing.length - 1] || ""; }
  10. function popFromRing() { if (killRing.length > 1) killRing.pop(); return getFromRing(); }
  11. CodeMirror.keyMap.emacs = {
  12. "Ctrl-X": function(cm) {cm.setOption("keyMap", "emacs-Ctrl-X");},
  13. "Ctrl-W": function(cm) {addToRing(cm.getSelection()); cm.replaceSelection("");},
  14. "Ctrl-Alt-W": function(cm) {addToRing(cm.getSelection()); cm.replaceSelection("");},
  15. "Alt-W": function(cm) {addToRing(cm.getSelection());},
  16. "Ctrl-Y": function(cm) {cm.replaceSelection(getFromRing());},
  17. "Alt-Y": function(cm) {cm.replaceSelection(popFromRing());},
  18. "Ctrl-/": "undo", "Shift-Ctrl--": "undo", "Shift-Alt-,": "goDocStart", "Shift-Alt-.": "goDocEnd",
  19. "Ctrl-S": "findNext", "Ctrl-R": "findPrev", "Ctrl-G": "clearSearch", "Shift-Alt-5": "replace",
  20. "Ctrl-Z": "undo", "Cmd-Z": "undo", "Alt-/": "autocomplete", "Alt-V": "goPageUp",
  21. "Ctrl-J": "newlineAndIndent", "Enter": false, "Tab": "indentAuto",
  22. fallthrough: ["basic", "emacsy"]
  23. };
  24. CodeMirror.keyMap["emacs-Ctrl-X"] = {
  25. "Ctrl-S": "save", "Ctrl-W": "save", "S": "saveAll", "F": "open", "U": "undo", "K": "close",
  26. auto: "emacs", nofallthrough: true
  27. };
  28. })();