diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2015-09-15 15:04:45 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2015-10-05 15:57:13 +0200 |
| commit | 7c7683e48a62a678deceaaf17d40a3fac730bff2 (patch) | |
| tree | ccbf85418791541c9ab9cc27ae3219c1fa80a8ed | |
| parent | d61df439c79bdce0923d14aea7f96501a908fdb1 (diff) | |
| download | vis-7c7683e48a62a678deceaaf17d40a3fac730bff2.tar.gz vis-7c7683e48a62a678deceaaf17d40a3fac730bff2.tar.xz | |
vis: convert macro recording / replay to new input handling code
| -rw-r--r-- | vis.c | 35 |
1 files changed, 19 insertions, 16 deletions
@@ -817,15 +817,15 @@ static const char *changelist(const char *keys, const Arg *arg) { return keys; } -static Macro *key2macro(const Arg *arg) { - if (arg->i) - return &vis->macros[arg->i]; - const char *key = getkey(); - if (key && key[0] >= 'a' && key[0] <= 'z') - return &vis->macros[key[0] - 'a']; - if (key && key[0] == '@') - return vis->last_recording; - return NULL; +static const char *key2macro(const char *keys, Macro **macro) { + *macro = NULL; + if (keys[0] >= 'a' && keys[0] <= 'z') + *macro = &vis->macros[keys[0] - 'a']; + else if (keys[0] == '@') + *macro = vis->last_recording; + else if (keys[0] == '\0') + return NULL; + return keys+1; } static const char *macro_record(const char *keys, const Arg *arg) { @@ -837,19 +837,22 @@ static const char *macro_record(const char *keys, const Arg *arg) { vis->last_recording = vis->recording; vis->recording = NULL; } else { - vis->recording = key2macro(arg); - if (vis->recording) - macro_reset(vis->recording); + Macro *macro; + keys = key2macro(keys, ¯o); + if (macro) { + macro_reset(macro); + vis->recording = macro; + } } editor_draw(vis); return keys; } static const char *macro_replay(const char *keys, const Arg *arg) { - Macro *macro = key2macro(arg); - if (!macro || macro == vis->recording) - return keys; - keypress(macro->data); + Macro *macro; + keys = key2macro(keys, ¯o); + if (macro && macro != vis->recording) + keypress(macro->data); return keys; } |
