sandy

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

commit aa1450de7036134ee2e0986ec044933b9e75b39b
parent 48a87fd0c5ff8c3cf0e053ceb3294fa3a51195fe
Author: Dimitris Zervas <dzervas@dzervas.gr>
Date:   Thu, 10 Jul 2014 11:48:08 +0300

Now double pressing a verb acts in the same line

Diffstat:
config.h | 3+--
sandy.c | 85+++++++++++++++++++++++++++++++++++++++++++------------------------------------
2 files changed, 47 insertions(+), 41 deletions(-)

diff --git a/config.h b/config.h @@ -171,14 +171,13 @@ 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 } }, -// TODO: Find a non-complex way to insert line above and beneath { .keyv.c = { 'o' }, { t_rw, 0, 0, 0 }, f_moveboth, { .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, 0, 0, 0 }, f_moveboth, { .m = m_bol } }, { .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 } }, -// TODO: add P support +// TODO: add better paste support and P { .keyv.c = { 'p' }, { t_rw, 0, 0, 0 }, f_pipenull, FROMCLIP }, { .keyv.c = { 's' }, { t_sel, t_rw, 0, 0 }, f_delete, { .m = m_tosel } }, { .keyv.c = { 's' }, { t_sel, t_rw, 0, 0 }, f_toggle, { .i = S_Command } }, diff --git a/sandy.c b/sandy.c @@ -760,7 +760,7 @@ i_edit(void) { char c[7]; fd_set fds; Filepos oldsel, oldcur; - Arg *param = { 0 }; + Arg param = { 0 }; oldsel.l=oldcur.l=fstline; oldsel.o=oldcur.o=0; @@ -863,56 +863,63 @@ i_edit(void) { statusflags|=S_Multiply; multiply=(int)ch-'0'; } - } else - for(i=0; i<LENGTH(commkeys); i++) { - if(memcmp(c, commkeys[i].keyv.c, sizeof commkeys[i].keyv.c) == 0 && i_dotests(commkeys[i].test) ) { - - // FIXME: Find a better way to tell if a verb or parameter command - if(!t_sent() && commkeys[i].arg.i == 0) { - statusflags|=(long)S_Sentence; - verb=commkeys[i].func; - break; - } - - if(!t_sent() && commkeys[i].arg.m == 0) { - statusflags|=(long)S_Parameter; - verb=commkeys[i].func; - break; - } - - if(statusflags & S_Parameter) { - statusflags&=~S_Parameter; - param->v=c; - verb(param); - break; + } else for(i=0; i<LENGTH(commkeys); i++) { + if(memcmp(c, commkeys[i].keyv.c, sizeof commkeys[i].keyv.c) == 0 && i_dotests(commkeys[i].test) ) { + if(commkeys[i].func != f_insert) statusflags&=~(S_GroupUndo); + + /* Handle sentences */ + // FIXME: Find a better way to tell if a func is a verb or parameter + if(t_sent()) { + if(commkeys[i].func == verb) { + param.m=m_nextline; + verb(&param); } - if(t_sent() && commkeys[i].func != f_adjective) { + if(commkeys[i].func != f_adjective) { statusflags&=~S_Sentence; break; } + } else if(commkeys[i].arg.i == 0) { + statusflags|=(long)S_Sentence; + verb=commkeys[i].func; + break; + } - if(commkeys[i].func != f_insert) statusflags&=~(S_GroupUndo); + /* Handle parameter sentences (verb is used here to define the command to execute) */ + if(statusflags & S_Parameter) { + statusflags&=~S_Parameter; + param.v=c; + verb(&param); + break; + } else if(commkeys[i].arg.m == 0) { + statusflags|=(long)S_Parameter; + verb=commkeys[i].func; + break; + } - // FIXME: Some weird thing can be executed (example: 5a or 0a which does nothing) - if(statusflags & S_Multiply) { - for(j=0; j<multiply; j++) - commkeys[i].func(&(commkeys[i].arg)); - statusflags&=~S_Multiply; - multiply=1; - } else + /* Handle multiplication */ + // FIXME: Some weird thing can be executed (example: 5a or 0a which does nothing) + if(statusflags & S_Multiply) { + for(j=0; j<multiply; j++) commkeys[i].func(&(commkeys[i].arg)); - // FIXME: Compare the exact tests to be the same - 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; - } - - break; + statusflags&=~S_Multiply; + multiply=1; + } else + 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; } + + break; } + } } #else if(t_rw()) f_insert(&(const Arg){ .v = c });