sim

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

commit 5b23e1106d00ba4af0764c023a42816cb36165ab
parent 9d053b9c82e28b2da4ad8a778ff1eb590cf5120d
Author: ssnf <ssnf@ssnf.xyz>
Date:   Fri, 15 Oct 2021 12:02:20 +0000

added yank and paste commands

Diffstat:
Mconfig.def.h | 7++++---
Msim.c | 35++++++++++++++++++++++++++++++++++-
2 files changed, 38 insertions(+), 4 deletions(-)

diff --git a/config.def.h b/config.def.h @@ -15,6 +15,7 @@ Key keys[] = { { '8', count, 8 }, { '9', count, 9 }, { 'd', delete }, + { 'd', delete , Line }, { 'x', delete , Letter }, { '.', dot }, { Esc, escape }, @@ -39,15 +40,15 @@ Key keys[] = { { 'w', move, Word }, { 'e', move, EndWord }, { 'b', move, PrevWord }, + { 'p', paste }, { 'Q', quit }, { '/', search, '/' }, { '?', search, '?' }, { 'n', search, 'n' }, { 'N', search, 'N' }, { 'u', undo }, - { Ctrl + 'r', redo } + { Ctrl + 'r', redo }, + { 'y', yank } /*TODO: yank command */ /*TODO: replace command */ - /*TODO: dot command */ - /*TODO: visual selection(?) */ }; diff --git a/sim.c b/sim.c @@ -106,6 +106,7 @@ static void fr_insert(Frame* p, Frame* q, ushort n); static void fr_insure(Frame* fr, ushort n); static void fr_update(); static void fr_zero(Frame*); +static void paste(int arg); static void search(int arg); static int select(int arg); static void str_init(String* p); @@ -120,6 +121,7 @@ static void str_delete(String* p, Posn p0, Posn p1); static void undo(int arg); static void move(int); static void quit(int); +static void yank(int arg); static Frame* fr, frame[FILECOUNT]; static File* f, file[FILECOUNT]; @@ -312,7 +314,9 @@ delete(int arg) if ((arg = select(arg)) < 0) return; str_init(&s); + str_zero(&istr); str_adds(&s, f->s->s + f->dot.p0, f->dot.p1 + 1 - f->dot.p0); + str_adds(&istr, f->s->s + f->dot.p0, f->dot.p1 + 1 - f->dot.p0); buf_add(buf, NULL, &s, Delete, arg, count, f->dot.p0); str_delete(f->s, f->dot.p0, f->dot.p1 + 1); str_close(&s); @@ -772,6 +776,13 @@ quit(int arg) } static void +paste(int arg) +{ + str_insert(f->s, &istr, f->dot.p0); + buf_add(buf, &istr, NULL, Insert, 0, 1, f->dot.p0); +} + +static void search(int arg) { Posn pos; @@ -820,7 +831,7 @@ select(int arg) arg -= 0x7f; goto till; } - f->dot.p1 = f->dot.p0; + p0 = f->dot.p1 = f->dot.p0; if (!counter) ++counter; switch (arg) { @@ -961,6 +972,28 @@ undo(int arg) fr_update(); } +static void +yank(int arg) +{ + if (!f->s->n) + return; + if (!arg) { + switch ((arg = fgetc(stdin))) { + case 'y': arg = Line; break; + case 'G': arg = Bottom; break; + case 'g': arg = Top; break; + case 'w': arg = Word; break; + case 't': arg = Till; break; + default: + return; + } + } + if ((arg = select(arg)) < 0) + return; + str_zero(&istr); + str_adds(&istr, f->s->s + f->dot.p0, f->dot.p1 + 1 - f->dot.p0); +} + int main(int argc, char* argv[]) {