emacs: adding mark-ring
This commit is contained in:
parent
0a774fbb37
commit
1172f5cb3d
1 changed files with 22 additions and 0 deletions
|
|
@ -96,15 +96,31 @@ exports.handler.attach = function(editor) {
|
||||||
editor.session.$useEmacsStyleLineStart = true;
|
editor.session.$useEmacsStyleLineStart = true;
|
||||||
|
|
||||||
editor.session.$emacsMark = null;
|
editor.session.$emacsMark = null;
|
||||||
|
editor.session.$emacsMarkRing = editor.session.$emacsMarkRing || [];
|
||||||
|
|
||||||
editor.emacsMarkMode = function() {
|
editor.emacsMarkMode = function() {
|
||||||
return this.session.$emacsMark;
|
return this.session.$emacsMark;
|
||||||
}
|
}
|
||||||
|
|
||||||
editor.setEmacsMarkMode = function(p) {
|
editor.setEmacsMarkMode = function(p) {
|
||||||
|
var prevMark = this.session.$emacsMark;
|
||||||
|
if (prevMark)
|
||||||
|
this.session.$emacsMarkRing.push(prevMark);
|
||||||
this.session.$emacsMark = p;
|
this.session.$emacsMark = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
editor.pushEmacsMark = function(p, activate) {
|
||||||
|
var prevMark = this.session.$emacsMark;
|
||||||
|
if (prevMark)
|
||||||
|
this.session.$emacsMarkRing.push(prevMark);
|
||||||
|
if (activate) this.session.$emacsMark = p;
|
||||||
|
else this.session.$emacsMarkRing.push(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
editor.getLastEmacsMark = function(p) {
|
||||||
|
return this.session.$emacsMark || this.session.$emacsMarkRing.reverse()[0];
|
||||||
|
}
|
||||||
|
|
||||||
editor.on("click", $resetMarkMode);
|
editor.on("click", $resetMarkMode);
|
||||||
editor.on("changeSession", $kbSessionChange);
|
editor.on("changeSession", $kbSessionChange);
|
||||||
editor.renderer.screenToTextCoordinates = screenToTextBlockCoordinates;
|
editor.renderer.screenToTextCoordinates = screenToTextBlockCoordinates;
|
||||||
|
|
@ -141,6 +157,8 @@ var $kbSessionChange = function(e) {
|
||||||
|
|
||||||
if (!e.session.hasOwnProperty('$emacsMark'))
|
if (!e.session.hasOwnProperty('$emacsMark'))
|
||||||
e.session.$emacsMark = null;
|
e.session.$emacsMark = null;
|
||||||
|
if (!e.session.hasOwnProperty('$emacsMarkRing'))
|
||||||
|
e.session.$emacsMarkRing = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
var $resetMarkMode = function(e) {
|
var $resetMarkMode = function(e) {
|
||||||
|
|
@ -168,6 +186,10 @@ exports.handler.onCopy = function(e, editor) {
|
||||||
delete editor.$handlesEmacsOnCopy;
|
delete editor.$handlesEmacsOnCopy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exports.handler.onPaste = function(e, editor) {
|
||||||
|
editor.pushEmacsMark(editor.getCursorPosition());
|
||||||
|
}
|
||||||
|
|
||||||
exports.handler.bindKey = function(key, command) {
|
exports.handler.bindKey = function(key, command) {
|
||||||
if (!key)
|
if (!key)
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue