sandy

text editor
git clone git://git.suckless.org/sandy
Log | Files | Refs | README | LICENSE

commit 0cf805e572d810cac96c051e09197c005460daa9
parent 7506d2b23b4acd57fd074db5b758070dbc3392de
Author: Dimitris Zervas <dzervas@dzervas.gr>
Date:   Fri, 11 Jul 2014 16:00:38 +0300

Fixed multi-function test coparison

Diffstat:
config.h | 11+++++++++--
sandy.c | 27++++++++++++++++++++-------
2 files changed, 29 insertions(+), 9 deletions(-)

diff --git a/config.h b/config.h @@ -185,11 +185,19 @@ static const Key commkeys[] = { /* Command mode keys here */ { .keyv.c = { 'm' }, { 0, 0, 0, 0 }, f_mark, { 0 } }, { .keyv.c = { 'n' }, { t_sel, 0, 0, 0 }, f_findfw, { 0 } }, { .keyv.c = { 'N' }, { t_sel, 0, 0, 0 }, f_findbw, { 0 } }, +{ .keyv.c = { 'o' }, { t_rw, t_ai, 0, 0 }, f_move, { .m = m_eol } }, +{ .keyv.c = { 'o' }, { t_rw, t_ai, 0, 0 }, f_pipeai, { .v = AUTOINDENT } }, +{ .keyv.c = { 'o' }, { t_rw, t_ai, 0, 0 }, f_toggle, { .i = S_Command } }, { .keyv.c = { 'o' }, { t_rw, 0, 0, 0 }, f_move, { .m = m_eol } }, { .keyv.c = { 'o' }, { t_rw, 0, 0, 0 }, f_insert, { .v = "\n" } }, { .keyv.c = { 'o' }, { t_rw, 0, 0, 0 }, f_toggle, { .i = S_Command } }, +{ .keyv.c = { 'O' }, { t_rw, t_ai, 0, 0 }, f_move, { .m = m_bol } }, +{ .keyv.c = { 'O' }, { t_rw, t_ai, 0, 0 }, f_pipeai, { .v = AUTOINDENT } }, +{ .keyv.c = { 'O' }, { t_rw, t_ai, 0, 0 }, f_move, { .m = m_prevline } }, +{ .keyv.c = { 'O' }, { t_rw, t_ai, 0, 0 }, f_toggle, { .i = S_Command } }, { .keyv.c = { 'O' }, { t_rw, 0, 0, 0 }, f_move, { .m = m_bol } }, { .keyv.c = { 'O' }, { t_rw, 0, 0, 0 }, f_insert, { .v = "\n" } }, +{ .keyv.c = { 'O' }, { t_rw, 0, 0, 0 }, f_move, { .m = m_prevline } }, { .keyv.c = { 'O' }, { t_rw, 0, 0, 0 }, f_toggle, { .i = S_Command } }, { .keyv.c = { 'p' }, { t_rw, 0, 0, 0 }, f_pipenull, { .v = FROMCLIP } }, { .keyv.c = { 's' }, { t_sel, t_rw, 0, 0 }, f_delete, { .m = m_tosel } }, @@ -216,7 +224,6 @@ static const Key commkeys[] = { /* Command mode keys here */ * r replace char (verb) * t/T do until char (adj) * i do inside (adj) (ex. diw deletes current word) - * v visual mode. may not be implemented. * </> ident */ }; @@ -403,7 +410,7 @@ f_pipeai(const Arg *arg) { i_sortpos(&fsel, &fcur); fsel.o=0; f_pipe(arg); - fsel.l=fcur.l; fsel.o=0; + fsel=fcur; } void /* Pipe full lines including the selection */ diff --git a/sandy.c b/sandy.c @@ -371,7 +371,7 @@ f_insert(const Arg *arg) { i_addundo(TRUE, fcur, newcur, strdup((char*)arg->v)); if(fcur.l!=newcur.l) fsel=newcur; } - fcur=newcur; + fcur=fsel=newcur; statusflags|=(S_Modified|S_GroupUndo); lastaction=LastInsert; } @@ -551,7 +551,7 @@ f_undo(const Arg *arg) { i_deltext(start, end); fcur=fsel=start; } else - fcur=i_addtext(u->str, fcur); + fcur=fsel=i_addtext(u->str, fcur); if(isredo) redos=u->prev, u->prev=undos, undos=u; else @@ -760,8 +760,9 @@ i_dotests(bool (*const a[])(void)) { void /* Main editing loop */ i_edit(void) { - int ch, i; + int ch, i, j; char c[7]; + bool pass; fd_set fds; Filepos oldsel, oldcur; @@ -903,15 +904,26 @@ i_edit(void) { break; } - i_multiply(commkeys[i].func, commkeys[i].arg); /* Handle multi-function commands */ - // FIXME: Compare the exact tests to be the same and not the length & validity // TODO: Find a way to handle multi-function verbs if(i+1 < LENGTH(commkeys)) { - if(memcmp(commkeys[i+1].keyv.c, commkeys[i].keyv.c, sizeof commkeys[i].keyv.c) == 0 && LENGTH(commkeys[i].test) == LENGTH(commkeys[i+1].test) && i_dotests(commkeys[i+1].test)) - continue; + if(memcmp(commkeys[i+1].keyv.c, commkeys[i].keyv.c, sizeof commkeys[i].keyv.c) == 0) { + j=-1; + pass=TRUE; + + while(1) + if(commkeys[i].test[++j]) { + if(commkeys[i].test[j] != commkeys[i+1].test[j]) { + pass=FALSE; + break; + } + } else break; + + if(pass) continue; + else break; + } } break; @@ -1041,6 +1053,7 @@ i_multiply(void (*func)(const Arg *arg), const Arg arg) { int i; if(statusflags & S_Multiply) { + //statusflags|=S_GroupUndo; for(i=0; i<multiply; i++) func(&arg);