be

based editor
git clone git://git.kocotian.pl/be.git
Log | Files | Refs | README | LICENSE

commit 53daaef7dd2f360cb314b3d9fd8915f8ab919046
parent dda0091eb1d7e8302c972c49200d5c76744a8680
Author: kocotian <kocotian@kocotian.pl>
Date:   Sun, 18 Apr 2021 17:10:45 +0200

Appending, opening lines

Diffstat:
Mbe.c | 38++++++++++++++++++++++++++++++++++++++
Mconfig.h | 7+++++++
2 files changed, 45 insertions(+), 0 deletions(-)

diff --git a/be.c b/be.c @@ -117,11 +117,13 @@ static void echo(const Arg *arg); static void echoe(const Arg *arg); static void normalmode(const Arg *arg); static void insertmode(const Arg *arg); +static void appendmode(const Arg *arg); static void cursormove(const Arg *arg); static void beginning(const Arg *arg); static void ending(const Arg *arg); static void insertchar(const Arg *arg); static void removechar(const Arg *arg); +static void openline(const Arg *arg); static void quit(const Arg *arg); /* global variables */ @@ -483,6 +485,17 @@ insertmode(const Arg *arg) } static void +appendmode(const Arg *arg) +{ + Arg a; + a.i = 3; + cursormove(&a); + if (arg->i) + ending(NULL); + switchmode(ModeEdit); +} + +static void cursormove(const Arg *arg) { switch (arg->i) { @@ -555,6 +568,31 @@ removechar(const Arg *arg) } static void +openline(const Arg *arg) +{ + CURBUF(editor).rows.data = + realloc(CURBUF(editor).rows.data, + (++CURBUF(editor).rows.len + 1) * sizeof *(CURBUF(editor).rows.data)); + memmove(CURBUF(editor).rows.data + CURBUF(editor).y + 1, + CURBUF(editor).rows.data + CURBUF(editor).y, + CURBUF(editor).rows.len - (unsigned)CURBUF(editor).y + 1); + + if (arg->i != 1) ++CURBUF(editor).y; + CURBUF(editor).rows.data[CURBUF(editor).y].data = + malloc(CURBUF(editor).rows.data[CURBUF(editor).y].len = + (CURBUF(editor).rows.data[CURBUF(editor).y - 1].len - + (unsigned)CURBUF(editor).x)); + if (arg->i == 2) { + memmove(CURBUF(editor).rows.data[CURBUF(editor).y].data, + CURBUF(editor).rows.data[CURBUF(editor).y - 1].data + CURBUF(editor).x, + CURBUF(editor).rows.data[CURBUF(editor).y - 1].len - (unsigned)CURBUF(editor).x); + CURBUF(editor).rows.data[CURBUF(editor).y - 1].len = (unsigned)CURBUF(editor).x; + } + CURBUF(editor).x = 0; + switchmode(ModeEdit); +} + +static void quit(const Arg *arg) { (void)arg; diff --git a/config.h b/config.h @@ -14,6 +14,8 @@ normalbindings[] = { /* edit mode */ { ModNone, 'i', insertmode, {.i = 0} }, { ModShift, 'i', insertmode, {.i = 1} }, + { ModNone, 'a', appendmode, {.i = 0} }, + { ModShift, 'a', appendmode, {.i = 1} }, /* advanced movement */ { ModNone, '^', beginning, {0} }, @@ -21,6 +23,10 @@ normalbindings[] = { { ModNone, '$', ending, {0} }, { ModNone, 'E', ending, {0} }, + { ModNone, 'o', openline, {0} }, + { ModNone, 'O', openline, {1} }, + { ModNone, '\r', openline, {2} }, + /* other */ { ModShift, 'q', quit, {0} }, { ModNone, 0, echoe, {.v = "Key is not bound"} }, @@ -29,6 +35,7 @@ normalbindings[] = { editbindings[] = { /* modifier key function argument */ { ModNone, 033, normalmode, {0} }, + { ModNone, '\r', normalmode, {1} }, { ModNone, 127, removechar, {0} }, { ModNone, 0, insertchar, {.v = REPLACE} }, };