sim

the sim text editor
git clone git://ssnf.xyz/sim
Log | Files | Refs | README

commit b759e7242bcc4d5467c48672662a06b0af431d35
parent 4028cd41c96a55da45f854eecc1e845676b15fe4
Author: ssnf <ssnf@ssnf.xyz>
Date:   Wed, 18 May 2022 11:52:23 +0000

move(Top) now follows the global counter. Introcution of pline().

Diffstat:
Mconfig.def.h | 1+
Msim.c | 77+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------
2 files changed, 60 insertions(+), 18 deletions(-)

diff --git a/config.def.h b/config.def.h @@ -28,6 +28,7 @@ Key keys[] = { { 'a', insert , Right }, { 'o', insert , Down }, { 'O', insert , Up }, + { '!', pline }, { 'h', move, Left }, { 'j', move, Down }, { 'k', move, Up }, diff --git a/sim.c b/sim.c @@ -104,9 +104,10 @@ static void fr_close(Frame* fr); static void fr_init(Frame* fr); static void fr_insert(Frame* p, Frame* q, ushort n); static void fr_insure(Frame* fr, ushort n); -static void fr_update(int arg); +static void fr_update(); static void fr_zero(Frame*); static void paste(int arg); +static void pline(); static void search(int arg); static int selection(int arg); static void str_init(String* p); @@ -276,7 +277,7 @@ change(int arg) buf->c[f->i] = Change; buf->arg[f->i] = arg; buf->count[f->i] = count; - fr_update(1); + fr_update(); } static void @@ -299,7 +300,7 @@ delete(int arg) if (!f->s->n) return; if (!arg) { - switch ((arg = fgetc(stdin))) { + switch (arg = fgetc(stdin)) { case 'x': arg = Letter; break; case 'd': arg = Line; break; case 'G': arg = Bottom; break; @@ -323,7 +324,7 @@ delete(int arg) if (f->dot.p0 == f->s->n && f->dot.p0) --f->dot.p0; f->dot.p1 = f->dot.p0; - fr_update(1); + fr_update(); } static void @@ -363,7 +364,7 @@ dot(int arg) f->dot.p1 = f->dot.p0; break; } - fr_update(1); + fr_update(); } static void @@ -377,7 +378,7 @@ redo(int arg) str_insert(f->s, &buf->is[f->i], buf->p0[f->i]); f->dot.p0 = f->dot.p1 = buf->p0[f->i]; f->dirty = '*'; - fr_update(1); + fr_update(); } static void @@ -458,8 +459,8 @@ insert(int arg) } for (;;) { win_query(&w); - fr_update(1); - switch ((c.s[0] = fgetc(stdin))) { + fr_update(); + switch (c.s[0] = fgetc(stdin)) { case Esc: goto endmode; case Del: @@ -623,10 +624,10 @@ fr_insure(Frame* fr, ushort n) } static void -fr_update(int arg) +fr_update() { - Frame fr0; - Posn p0, p1; + Frame fr0; + Posn p0, p1; ushort half; half = w.wy >> 1; @@ -635,7 +636,7 @@ fr_update(int arg) printf(ED); goto status; } - if (arg || !fr->n || f->dot.p1 < fr->a[fr->dot].p0 + if (1 || !fr->n || f->dot.p1 < fr->a[fr->dot].p0 || f->dot.p1 > fr->a[fr->n ? fr->n - 1 : 0].p1 || (((fr->dot < half && fr->a[0].p0 && (fr->n > w.wy * 3)) || (fr->dot + half + 1 > fr->n)) @@ -732,6 +733,11 @@ move(int arg) break; case Top: f->dot.p1 = 0; + if (counter) + for (counter ? --counter : 0; counter; --counter) { + move(EndLine); + move(Right); + } break; case Bottom: if (f->s->n) @@ -746,8 +752,8 @@ move(int arg) for (;f->dot.p1 + 1 < f->s->n && f->s->s[f->dot.p1] != '\n'; ++f->dot.p1); break; case Word: - for (;f->dot.p1 < f->s->n && isword(f->s->s[f->dot.p1]); ++f->dot.p1); - for (;f->dot.p1 < f->s->n && !isword(f->s->s[f->dot.p1]); ++f->dot.p1); + for (;f->dot.p1 + 1 < f->s->n && isword(f->s->s[f->dot.p1]); ++f->dot.p1); + for (;f->dot.p1 + 1 < f->s->n && !isword(f->s->s[f->dot.p1]); ++f->dot.p1); break; case EndWord: move(Right); @@ -784,6 +790,41 @@ paste(int arg) buf_add(buf, &istr, NULL, Insert, 0, 1, f->dot.p0); } + +static void +pline() +{ + ulong i, j, c, l; + + for (l = f->dot.p1 = 0; f->dot.p1 < f->dot.p0; ++l) { + for (;f->dot.p1 + 1 < f->s->n && f->s->s[f->dot.p1] != '\n'; ++f->dot.p1); + if (f->dot.p1 + 1 < f->s->n) + ++f->dot.p1; + } + ++l; + j = 1; + if (!counter) + counter = 1; + for (;;) { + for (i = 0; i < j * counter && i < w.wy/2 ; ++i) + printf(CSI "%luH" EL "%lu", w.wy/2 + i, i ? i : l); + switch (c = fgetc(stdin)) { + case '!': + ++j; + break; + case '+': + ++counter; + break; + case '-': + if (counter > 1) + --counter; + default: + counter = 0; + return; + } + } +} + static void search(int arg) { @@ -821,7 +862,7 @@ search(int arg) f->dot.p0 = f->dot.p1 = p - f->s->s; if (srch.s[0] == '\n' && srch.s[1] != '\n') move(Right); - fr_update(1); + fr_update(); } static int @@ -970,7 +1011,7 @@ undo(int arg) str_insert(f->s, &buf->ds[f->i], buf->p0[f->i]); f->dot.p0 = f->dot.p1 = buf->p0[f->i--]; f->dirty = '*'; - fr_update(1); + fr_update(); } static void @@ -979,7 +1020,7 @@ yank(int arg) if (!f->s->n) return; if (!arg) { - switch ((arg = fgetc(stdin))) { + switch (arg = fgetc(stdin)) { case 'y': arg = Line; break; case 'G': arg = Bottom; break; case 'g': arg = Top; break; @@ -1008,7 +1049,7 @@ main(int argc, char* argv[]) } for (;;) { win_query(&w); - fr_update(0); + fr_update(); c = fgetc(stdin); for (i = 0; i < LENGTH(keys); ++i) { if (keys[i].key == c) {