commit 48a87fd0c5ff8c3cf0e053ceb3294fa3a51195fe
parent 29cea247b252fcab9c6924b35f78b30604a53c2e
Author: Dimitris Zervas <dzervas@dzervas.gr>
Date:   Thu, 10 Jul 2014 11:03:12 +0300
Added parameter mode
Diffstat:
| sandy.c |  |  | 28 | ++++++++++++++++++++++------ | 
1 file changed, 22 insertions(+), 6 deletions(-)
diff --git a/sandy.c b/sandy.c
@@ -138,8 +138,9 @@ enum { /* To use in statusflags */
 	S_AutoIndent = 1<<10, /* Perform autoindenting on RET */
 	S_DumpStdout = 1<<11, /* Dump to stdout instead of writing to a file */
 	S_Command    = 1<<12, /* Command mode */
-	S_Sentence   = 1<<13, /* Sentence mode (A verb was pressed and an adjective should be pressed) */
-	S_Multiply   = 1<<14, /* Multiply mode. Replay a command x times */
+	S_Sentence   = 1<<13, /* Sentence mode. Pass the next command's parameters (if adjective) to the verb's function */
+	S_Parameter  = 1<<14, /* Parameter mode. Pass the next character as parameter to the function of the command */
+	S_Multiply   = 1<<15, /* Multiply mode. Replay a command x times */
 };
 
 enum { /* To use in Undo.flags */
@@ -187,7 +188,7 @@ static int       lastaction=LastNone;               /* The last action we took (
 static int       cols, lines;                       /* Ncurses: to use instead of COLS and LINES, wise */
 static mmask_t   defmmask = 0;                      /* Ncurses: mouse event mask */
 static void    (*verb)(const Arg *arg);             /* Verb of current sentence */
-static int       multiply = 1;                          /* Times to replay a command */
+static int       multiply = 1;                      /* Times to replay a command */
 
 /* Functions */
 /* f_* functions can be linked to an action or keybinding */
@@ -759,6 +760,7 @@ i_edit(void) {
 	char c[7];
 	fd_set fds;
 	Filepos oldsel, oldcur;
+	Arg *param = { 0 };
 
 	oldsel.l=oldcur.l=fstline;
 	oldsel.o=oldcur.o=0;
@@ -865,12 +867,26 @@ i_edit(void) {
 				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;
+						}
+
 						if(t_sent() && commkeys[i].func != f_adjective) {
 							statusflags&=~S_Sentence;
 							break;
@@ -878,7 +894,7 @@ i_edit(void) {
 
 						if(commkeys[i].func != f_insert) statusflags&=~(S_GroupUndo);
 
-						// FIXME: Some weird thing can be executed (example: 5a)
+						// 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));
@@ -888,8 +904,8 @@ i_edit(void) {
 						} else
 							commkeys[i].func(&(commkeys[i].arg));
 
-
-						if(i+1 < LENGTH(commkeys)) { // FIXME: Compare the exact tests to be the same
+						// 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;
 						}