static void StartMultiplierBuilder(ViBuilderContext ctx, ViBuilder nextBuilder) { int factor = 1; int multiplier = 0; ctx.Builder = (ViBuilderContext x) => { int c = (int)x.LastKey.Char; if (c >= (int)'0' && c <= (int)'9') { //don't eat '0' if not preceded by non-zero digit //pass on to interpret as goto line start if (c == (int)'0' && factor == 1) { ctx.Multiplier *= multiplier; ctx.Builder = nextBuilder; return(ctx.Builder(ctx)); } int d = c - (int)'0'; multiplier = multiplier * factor + d; factor *= 10; return(true); } else { ctx.Multiplier *= multiplier; ctx.Builder = nextBuilder; return(ctx.Builder(ctx)); } }; ctx.Builder(ctx); }
static bool Replace(ViBuilderContext ctx) { ctx.RunAction((ViEditor e) => e.SetMode(ViEditorMode.Replace)); ctx.SuppressCompleted(); ctx.Builder = ViBuilders.InsertBuilder(insertActions); return(true); }
public static bool ReplaceChar(ViBuilderContext ctx) { if (ctx.LastKey.Char != '\0') { ctx.RunAction((ViEditor ed) => ed.Data.Replace(ed.Data.Caret.Offset, 1, ctx.LastKey.Char.ToString())); } else { ctx.SetError("Expecting a character"); } return(true); }
public void Reset(string message) { Context = ViBuilderContext.Create(this); Message = message; if (Data.Caret.Mode != CaretMode.Block) { Data.Caret.Mode = CaretMode.Block; if (Data.Caret.Column > DocumentLocation.MinColumn) { Data.Caret.Column--; } } ViActions.RetreatFromLineEnd(Data); }
public static bool GoToMark(ViBuilderContext ctx) { char c = ctx.LastKey.Char; if (!char.IsLetterOrDigit (c)) { ctx.SetError ("Invalid Mark"); return true; } ctx.RunAction ((ViEditor ed) => { ViMark mark; if (ed.Marks.TryGetValue (c, out mark)) mark.LoadMark (ed.Data); else ed.Reset ("Unknown Mark"); }); return true; }
static void StartRegisterBuilder(ViBuilderContext ctx, ViBuilder nextBuilder) { if (ctx.Register != '\0') { ctx.SetError("Register already set"); return; } ctx.Builder = (ViBuilderContext x) => { char c = x.LastKey.Char; if (!ViEditor.IsValidRegister(c)) { x.SetError("Invalid register"); return(true); } x.Register = c; x.Builder = nextBuilder; return(true); }; }
public static bool Mark(ViBuilderContext ctx) { char c = ctx.LastKey.Char; if (!char.IsLetterOrDigit(c)) { ctx.SetError("Invalid Mark"); return(true); } ctx.RunAction((ViEditor ed) => { ViMark mark; if (!ed.Marks.TryGetValue(c, out mark)) { ed.Marks [c] = mark = new ViMark(c); } mark.SaveMark(ed.Data); }); return(true); }
public static bool GoToMark(ViBuilderContext ctx) { char c = ctx.LastKey.Char; if (!char.IsLetterOrDigit(c)) { ctx.SetError("Invalid Mark"); return(true); } ctx.RunAction((ViEditor ed) => { ViMark mark; if (ed.Marks.TryGetValue(c, out mark)) { mark.LoadMark(ed.Data); } else { ed.Reset("Unknown Mark"); } }); return(true); }
public bool Builder(ViBuilderContext ctx) { Action <ViEditor> a; if (actions.TryGetValue(ctx.LastKey, out a)) { ctx.RunAction(a); return(true); } else { BuilderAction b; if (builders.TryGetValue(ctx.LastKey, out b)) { ctx.Builder = b.Builder; if (b.RunInstantly) { ctx.Builder(ctx); } return(true); } } return(false); }
static bool OpenAbove(ViBuilderContext ctx) { // FIXME: this doesn't work correctly on the first line ctx.RunAction((ViEditor e) => ViActions.Up(e.Data)); return(Open(ctx)); }
public static bool ReplaceChar(ViBuilderContext ctx) { if (ctx.LastKey.Char != '\0') ctx.RunAction ((ViEditor ed) => ed.Data.Replace (ed.Data.Caret.Offset, 1, ctx.LastKey.Char.ToString ())); else ctx.SetError ("Expecting a character"); return true; }
static bool Replace(ViBuilderContext ctx) { ctx.RunAction ((ViEditor e) => e.SetMode (ViEditorMode.Replace)); ctx.SuppressCompleted (); ctx.Builder = ViBuilders.InsertBuilder (insertActions); return true; }
static bool OpenAbove(ViBuilderContext ctx) { // FIXME: this doesn't work correctly on the first line ctx.RunAction ((ViEditor e) => ViActions.Up (e.Data)); return Open (ctx); }
static bool Open(ViBuilderContext ctx) { ctx.RunAction ((ViEditor e) => MiscActions.InsertNewLineAtEnd (e.Data)); return Insert (ctx); }
static bool GotoLine(ViBuilderContext ctx) { ctx.RunAction ((ViEditor e) => ViEditorActions.CaretToLineNumber (ctx.Multiplier, e)); ctx.RunAction ((ViEditor e) => CaretMoveActions.LineFirstNonWhitespace (e.Data)); return true; }
static void StartMultiplierBuilder(ViBuilderContext ctx, ViBuilder nextBuilder) { int factor = 1; int multiplier = 0; ctx.Builder = (ViBuilderContext x) => { int c = (int)x.LastKey.Char; if (c >= (int)'0' && c <= (int)'9') { //don't eat '0' if not preceded by non-zero digit //pass on to interpret as goto line start if (c == (int)'0' && factor == 1) { ctx.Multiplier *= multiplier; ctx.Builder = nextBuilder; return ctx.Builder (ctx); } int d = c - (int)'0'; multiplier = multiplier * factor + d; factor *= 10; return true; } else { ctx.Multiplier *= multiplier; ctx.Builder = nextBuilder; return ctx.Builder (ctx); } }; ctx.Builder (ctx); }
public static bool Mark(ViBuilderContext ctx) { char c = ctx.LastKey.Char; if (!char.IsLetterOrDigit (c)) { ctx.SetError ("Invalid Mark"); return true; } ctx.RunAction ((ViEditor ed) => { ViMark mark; if (!ed.Marks.TryGetValue (c, out mark)) ed.Marks [c] = mark = new ViMark (c); mark.SaveMark (ed.Data); }); return true; }
static void StartRegisterBuilder(ViBuilderContext ctx, ViBuilder nextBuilder) { if (ctx.Register != '\0') { ctx.SetError ("Register already set"); return; } ctx.Builder = (ViBuilderContext x) => { char c = x.LastKey.Char; if (!ViEditor.IsValidRegister (c)) { x.SetError ("Invalid register"); return true; } x.Register = c; x.Builder = nextBuilder; return true; }; }
static bool Open(ViBuilderContext ctx) { ctx.RunAction((ViEditor e) => MiscActions.InsertNewLineAtEnd(e.Data)); return(Insert(ctx)); }
static bool GotoLine(ViBuilderContext ctx) { ctx.RunAction((ViEditor e) => ViEditorActions.CaretToLineNumber(ctx.Multiplier, e)); ctx.RunAction((ViEditor e) => CaretMoveActions.LineFirstNonWhitespace(e.Data)); return(true); }
public void Reset(string message) { Context = ViBuilderContext.Create (this); Message = message; if (Data.Caret.Mode != CaretMode.Block) { Data.Caret.Mode = CaretMode.Block; if (Data.Caret.Column > DocumentLocation.MinColumn) Data.Caret.Column--; } ViActions.RetreatFromLineEnd (Data); }