commit f845b454953b431b3e01f024be6d8f12e5799995
parent 21a5cf59f37671c65c75211db93979bb609290da
Author: Dimitris Zervas <dzervas@dzervas.gr>
Date: Tue, 15 Jul 2014 16:17:27 +0300
Added support for verb arguments on verb definition
Diffstat:
4 files changed, 23 insertions(+), 15 deletions(-)
diff --git a/TODO b/TODO
@@ -14,6 +14,7 @@ In no particular order, at sandy.c:
- Support multiple marks (with S_Parameter)
- Instead of delete, just cut
- Add folding support
+- Add better paste support (if whole line was cut, append it beneath)
At config.def.h:
- Use local/system script path and all
diff --git a/config.def.h b/config.def.h
@@ -182,16 +182,18 @@ static const Key commkeys[] = { /* Command mode keys here */
{ .keyv.c = { '^' }, { 0, 0, 0, 0 }, f_move, { .m = m_bol } },
{ .keyv.c = { 'A' }, { 0, 0, 0, 0 }, f_move, { .m = m_eol } },
{ .keyv.c = { 'A' }, { 0, 0, 0, 0 }, f_toggle, { .i = S_Command } },
+{ .keyv.c = { 'a' }, { t_eol, 0, 0, 0 }, f_toggle, { .i = S_Command } },
{ .keyv.c = { 'a' }, { 0, 0, 0, 0 }, f_move, { .m = m_nextchar } },
{ .keyv.c = { 'a' }, { 0, 0, 0, 0 }, f_toggle, { .i = S_Command } },
{ .keyv.c = { 'b' }, { t_sent,0, 0, 0 }, f_adjective, { .m = m_prevword } },
{ .keyv.c = { 'b' }, { 0, 0, 0, 0 }, f_move, { .m = m_prevword } },
{ .keyv.c = { 'c' }, { t_sel, t_rw, 0, 0 }, f_delete, { .m = m_tosel } },
-{ .keyv.c = { 'c' }, { t_rw, 0, 0, 0 }, f_delete, { .m = m_sentence } }, /* TODO: queue insert mode, similar to 'y' */
+{ .keyv.c = { 'c' }, { t_rw, 0, 0, 0 }, f_delete, { .m = m_sentence } }, /* TODO: queue insert mode, similar to 'y' */
{ .keyv.c = { 'C' }, { t_rw, 0, 0, 0 }, f_delete, { .m = m_eol } },
{ .keyv.c = { 'C' }, { t_rw, 0, 0, 0 }, f_toggle, { .i = S_Command } },
{ .keyv.c = { 'd' }, { t_sel, t_rw, 0, 0 }, f_delete, { .m = m_tosel } },
-{ .keyv.c = { 'd' }, { t_rw, 0, 0, 0 }, f_delete, { .m = m_sentence } },
+{ .keyv.c = { 'd' }, { t_rw, 0, 0, 0 }, f_delete, { .m = m_sentence } },
+//{ .keyv.c = { 'd' }, { t_rw, 0, 0, 0 }, f_pipe, { .m = m_sentence, .v = TOCLIP } },
{ .keyv.c = { 'D' }, { t_rw, 0, 0, 0 }, f_delete, { .m = m_eol } },
{ .keyv.c = { 'g' }, { t_sent,0, 0, 0 }, f_adjective, { .m = m_bof } },
{ .keyv.c = { 'g' }, { 0, 0, 0, 0 }, f_move, { .m = m_bof } },
diff --git a/config.h b/config.h
@@ -160,9 +160,6 @@ static const Key stdkeys[] = {
};
#if VIM_BINDINGS
-/* In order for a key to execute more than 1 function, add consecutive definitions of the key
- with the exact same tests */
-
// TODO: add better paste support (if whole line was yanked, append above, not where you are)
static const Key commkeys[] = { /* Command mode keys here */
/* keyv.c, tests, func, arg */
@@ -178,11 +175,12 @@ static const Key commkeys[] = { /* Command mode keys here */
{ .keyv.c = { 'b' }, { t_sent,0, 0, 0 }, f_adjective, { .m = m_prevword } },
{ .keyv.c = { 'b' }, { 0, 0, 0, 0 }, f_move, { .m = m_prevword } },
{ .keyv.c = { 'c' }, { t_sel, t_rw, 0, 0 }, f_delete, { .m = m_tosel } },
-{ .keyv.c = { 'c' }, { t_rw, 0, 0, 0 }, f_delete, { .m = m_sentence } }, /* TODO: queue insert mode, similar to 'y' */
+{ .keyv.c = { 'c' }, { t_rw, 0, 0, 0 }, f_delete, { .m = m_sentence } }, /* TODO: queue insert mode, similar to 'y' */
{ .keyv.c = { 'C' }, { t_rw, 0, 0, 0 }, f_delete, { .m = m_eol } },
{ .keyv.c = { 'C' }, { t_rw, 0, 0, 0 }, f_toggle, { .i = S_Command } },
{ .keyv.c = { 'd' }, { t_sel, t_rw, 0, 0 }, f_delete, { .m = m_tosel } },
-{ .keyv.c = { 'd' }, { t_rw, 0, 0, 0 }, f_delete, { .m = m_sentence } },
+{ .keyv.c = { 'd' }, { t_rw, 0, 0, 0 }, f_delete, { .m = m_sentence } },
+//{ .keyv.c = { 'd' }, { t_rw, 0, 0, 0 }, f_pipe, { .m = m_sentence, .v = TOCLIP } },
{ .keyv.c = { 'D' }, { t_rw, 0, 0, 0 }, f_delete, { .m = m_eol } },
{ .keyv.c = { 'g' }, { t_sent,0, 0, 0 }, f_adjective, { .m = m_bof } },
{ .keyv.c = { 'g' }, { 0, 0, 0, 0 }, f_move, { .m = m_bof } },
@@ -285,7 +283,7 @@ static const Command cmds[] = { /* REMEMBER: if(arg == 0) arg.v=regex_match */
static const Syntax syntaxes[] = {
#if HILIGHT_SYNTAX
-{"c", "\\.(c(pp|xx)?|h(pp|xx)?|cc)$", {
+{"c", "\\.([ch](pp|xx)?|cc)$", {
/* HiRed */ "$^",
/* HiGreen */ B"(for|if|while|do|else|case|default|switch|try|throw|catch|operator|new|delete)"B,
/* LoGreen */ B"(float|double|bool|char|int|short|long|sizeof|enum|void|static|const|struct|union|typedef|extern|(un)?signed|inline|((s?size)|((u_?)?int(8|16|32|64|ptr)))_t|class|namespace|template|public|protected|private|typename|this|friend|virtual|using|mutable|volatile|register|explicit)"B,
diff --git a/sandy.c b/sandy.c
@@ -190,6 +190,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 Arg varg; /* Arguments of the verb (some will be overwritten by adjective) */
static int multiply = 1; /* Times to replay a command */
/* Functions */
@@ -299,7 +300,12 @@ static regex_t *syntax_res[LENGTH(syntaxes)][SYN_COLORS];
void
f_adjective(const Arg *arg) {
statusflags&=~S_Sentence;
- verb(arg);
+
+ if(arg->m) varg.m=arg->m;
+ if(arg->i) varg.i=arg->i;
+ if(arg->v) varg.v=arg->v;
+
+ i_multiply(verb, varg);
}
#endif /* VIM_BINDINGS */
@@ -599,7 +605,7 @@ void /* Add new undo information to the undo ring */
i_addundo(bool ins, Filepos start, Filepos end, char *s) {
Undo *u;
- if(strlen(s) == 0) return;
+ //if(strlen(s) == 0) return;
if(statusflags & S_GroupUndo) {
end.l = i_lineat((undos->endl - undos->startl) + i_lineno(end.l));
i_addtoundo(end, s);
@@ -780,13 +786,16 @@ i_dotests(bool (*const a[])(void)) {
bool
i_dokeys(const Key bindings[], int index, bool multi) {
- int i;
+ int i=-1;
if(bindings[index].func != f_insert) statusflags&=~(S_GroupUndo);
/* Handle sentences */
if(t_sent()) {
- if(bindings[index].func == verb) i_multiply(verb, (const Arg){ .m = m_nextline });
+ if(bindings[index].func == verb) {
+ varg.m = m_nextline;
+ i_multiply(verb, varg);
+ }
if(bindings[index].func != f_adjective) {
statusflags&=~S_Sentence;
@@ -795,6 +804,7 @@ i_dokeys(const Key bindings[], int index, bool multi) {
} else if(bindings[index].arg.m == m_sentence) {
statusflags|=(long)S_Sentence;
verb=bindings[index].func;
+ varg=bindings[index].arg;
return FALSE;
}
@@ -813,8 +823,6 @@ i_dokeys(const Key bindings[], int index, bool multi) {
/* Handle multi-function commands */
if(multi) {
- i=-1;
-
while(1)
if(bindings[index].test[++i]) {
if(bindings[index].test[i] != bindings[index+1].test[i]) {
@@ -1055,7 +1063,6 @@ i_mouse(void) {
}
#endif /* HANDLE_MOUSE */
-// FIXME: Some weird thing can be executed (example: 5a or 0a which does nothing)
void /* Handle multiplication */
i_multiply(void (*func)(const Arg *arg), const Arg arg) {
int i;