sandy

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

commit de8e7863fbf29ee41290753a3657f96a675e4f23
parent cdcdf558d4014cb52bdada9feb01f82f54071104
Author: Rafael Garcia <rafael.garcia.gallego@gmail.com>
Date:   Sun,  7 Aug 2011 21:09:39 +0200

Honor readonly-ness. Fix bug that ignored the second and later conditions at commands/kybindings.
Diffstat:
config.def.h | 32++++++++++++++++----------------
sandy.c | 15++++++++-------
2 files changed, 24 insertions(+), 23 deletions(-)

diff --git a/config.def.h b/config.def.h @@ -110,7 +110,7 @@ static const Key stdkeys[] = { { .keyv.c = CONTROL('N'), { 0, 0, 0, 0 }, f_move, { .m = m_nextline } }, { .keyv.c = CONTROL('O'), { t_sel, 0, 0, 0 }, f_select, { .m = m_tosel } }, /* Swap fsel and fcur */ { .keyv.c = CONTROL('P'), { 0, 0, 0, 0 }, f_move, { .m = m_prevline } }, -{ .keyv.c = CONTROL('Q'), { 0, 0, 0, 0 }, f_toggle, { .i = S_InsEsc } }, +{ .keyv.c = CONTROL('Q'), { t_rw, 0, 0, 0 }, f_toggle, { .i = S_InsEsc } }, { .keyv.c = CONTROL('R'), { t_sel, 0, 0, 0 }, f_findbw, { 0 } }, { .keyv.c = CONTROL('R'), { 0, 0, 0, 0 }, f_spawn, FINDBW }, { .keyv.c = META('r'), { 0, 0, 0, 0 }, f_findbw, { 0 } }, @@ -124,7 +124,7 @@ static const Key stdkeys[] = { { .keyv.c = CONTROL('V'), { 0, 0, 0, 0 }, f_move, { .m = m_prevscr } }, { .keyv.c = META('v'), { 0, 0, 0, 0 }, f_move, { .m = m_nextscr } }, { .keyv.c = CONTROL('W'), { t_rw, 0, 0, 0 }, f_delete, { .m = m_prevword } }, -{ .keyv.c = CONTROL('X'), { t_mod, 0, 0, 0 }, f_save, { 0 } }, +{ .keyv.c = CONTROL('X'), { t_mod, t_rw, 0, 0 }, f_save, { 0 } }, { .keyv.c = CONTROL('X'), { 0, 0, 0, 0 }, f_toggle, { .i = S_Running } }, { .keyv.c = META('x'), { 0, 0, 0, 0 }, f_spawn, CMD_P }, { .keyv.c = CONTROL('Y'), { t_rw, 0, 0, 0 }, f_pipe, FROMCLIP }, @@ -145,20 +145,20 @@ static const Key stdkeys[] = { /* Commands read at the fifo */ static const Command cmds[] = { /* if(arg == 0) arg.v=regex_match */ -/* regex, tests, func arg */ -{"^([0-9]+)$", { 0, 0 }, f_line , { 0 } }, -{"^/(.*)$", { 0, 0 }, f_findfw, { 0 } }, -{"^\\?(.*)$", { 0, 0 }, f_findbw, { 0 } }, -{"^![ \t]*(.*)$", { t_rw, 0 }, f_pipe, { 0 } }, -{"^![ /t]*(.*)$", { 0, 0 }, f_pipero, { 0 } }, -{"^w[ \t]*(.*)$", { 0, 0 }, f_save, { 0 } }, -{"^syntax (.*)$", { 0, 0 }, f_syntax, { 0 } }, -{"^offset (.*)$", { 0, 0 }, f_offset, { 0 } }, -{"^set icase$", { 0, 0 }, f_toggle, { .i = S_CaseIns } }, -{"^set ro$", { 0, 0 }, f_toggle, { .i = S_Readonly } }, -{"^q$", { t_mod, 0 }, f_toggle, { .i = S_Warned } }, -{"^q$", { 0, 0 }, f_toggle, { .i = S_Running } }, -{"^q!$", { 0, 0 }, f_toggle, { .i = S_Running } }, +/* regex, tests, func arg */ +{"^([0-9]+)$", { 0, 0, 0 }, f_line , { 0 } }, +{"^/(.*)$", { 0, 0, 0 }, f_findfw, { 0 } }, +{"^\\?(.*)$", { 0, 0, 0 }, f_findbw, { 0 } }, +{"^![ \t]*(.*)$", { t_rw, 0, 0 }, f_pipe, { 0 } }, +{"^![ /t]*(.*)$", { 0, 0, 0 }, f_pipero, { 0 } }, +{"^w[ \t]*(.*)$", { t_mod, t_rw, 0 }, f_save, { 0 } }, +{"^syntax (.*)$", { 0, 0, 0 }, f_syntax, { 0 } }, +{"^offset (.*)$", { 0, 0, 0 }, f_offset, { 0 } }, +{"^set icase$", { 0, 0, 0 }, f_toggle, { .i = S_CaseIns } }, +{"^set ro$", { 0, 0, 0 }, f_toggle, { .i = S_Readonly } }, +{"^q$", { t_mod, 0, 0 }, f_toggle, { .i = S_Warned } }, +{"^q$", { 0, 0, 0 }, f_toggle, { .i = S_Running } }, +{"^q!$", { 0, 0, 0 }, f_toggle, { .i = S_Running } }, }; /* Syntax color definition */ diff --git a/sandy.c b/sandy.c @@ -74,14 +74,14 @@ typedef struct { /** A keybinding */ char c[6]; /* Standard chars */ int i; /* NCurses code */ } keyv; - bool (*test[4])(void); /* Conditions to match */ + bool (*test[4])(void); /* Conditions to match, make sure the last one is 0x00 */ void (*func)(const Arg *arg); /* Function to perform */ const Arg arg; /* Argument to func() */ } Key; typedef struct { /** A command read at the fifo */ const char *re_text; /* A regex to match the command, must have a parentheses group for argument */ - bool (*test[2])(void); /* Conditions to match */ + bool (*test[3])(void); /* Conditions to match, make sure the last one is 0x00 */ void (*func)(const Arg *arg); /* Function to perform, argument is determined as arg->v from regex above */ const Arg arg; /* Argument to func() */ } Command; @@ -420,7 +420,7 @@ f_repeat(const Arg *arg) { } } -void /* Save file with arg->v filename, same if NULL. Your responsibility: call only if t_mod() */ +void /* Save file with arg->v filename, same if NULL. Your responsibility: call only if t_mod() && t_rw() */ f_save(const Arg *arg) { Undo *u; @@ -720,11 +720,12 @@ i_deltext(Filepos pos0, Filepos pos1) { bool /* test an array of t_ functions */ i_dotests(bool (*const a[])(void)) { - int i; + int i=0; - for(i=0; i<LENGTH(a); i++) - if(a[i] && !(a[i]())) return FALSE; - return TRUE; + while(1) /* Somehow LENGTH() did not work here */ + if(a[i]) { + if(!a[i++]()) return FALSE; + } else return TRUE; } void /* Main editing loop */