vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit 6be1b08b3cf464f11cccc77917f00d0c29d259e5 parent 7be1b117eb7bf401259780a1d07a7deea53a8084 Author: Marc André Tanner <mat@brain-dump.org> Date: Thu, 11 Sep 2014 18:23:49 +0200 Be stricter on what commands to accept at the ':'- prompt Diffstat:
| M | config.def.h | | | 29 | +++++++++++++---------------- |
| M | vis.c | | | 14 | ++++++++------ |
2 files changed, 21 insertions(+), 22 deletions(-)
diff --git a/config.def.h b/config.def.h @@ -44,23 +44,20 @@ enum { VIS_MODE_REPLACE, }; -/* command recognized at the ':'-prompt, matched using a greedy top to bottom, - * regex search. make sure the longer commands are listed before the shorter ones - * e.g. 'sp' before 's' and 'wq' before 'w'. - */ +/* command recognized at the ':'-prompt. tested top to bottom, first match wins. */ static Command cmds[] = { - { "^[0-9]+", cmd_gotoline }, - { "^e(dit)?", cmd_edit }, - { "^o(pen)?", cmd_open }, - { "^qa(ll)?", cmd_qall }, - { "^q(quit)?", cmd_quit }, - { "^r(ead)?", cmd_read }, - { "^sp(lit)?", cmd_split }, - { "^s(ubstitute)?", cmd_substitute }, - { "^v(split)?", cmd_vsplit }, - { "^wq", cmd_wq }, - { "^w(rite)?", cmd_write }, - { /* array terminator */ }, + { "^[0-9]+$", cmd_gotoline }, + { "^e(dit)?!?$", cmd_edit }, + { "^o(pen)?$", cmd_open }, + { "^qa(ll)?!?$", cmd_qall }, + { "^q(quit)?!?$", cmd_quit }, + { "^r(ead)?$", cmd_read }, + { "^sp(lit)?$", cmd_split }, + { "^s(ubstitute)?$", cmd_substitute }, + { "^v(split)?$", cmd_vsplit }, + { "^wq!?$", cmd_wq }, + { "^w(rite)?$", cmd_write }, + { /* array terminator */ }, }; /* draw a statubar, do whatever you want with win->statuswin curses window */ diff --git a/vis.c b/vis.c @@ -993,6 +993,11 @@ static bool exec_command(char *cmdline) { init = true; } + /* regex should only apply to command name */ + char *s = strchr(cmdline, ' '); + if (s) + *s++ = '\0'; + Command *cmd = NULL; for (Command *c = cmds; c->name; c++) { if (!regexec(&c->regex, cmdline, 0, NULL, 0)) { @@ -1005,15 +1010,12 @@ static bool exec_command(char *cmdline) { return false; const char *argv[32] = { cmdline }; - char *s = cmdline; for (int i = 1; i < LENGTH(argv); i++) { - if (s) { - if ((s = strchr(s, ' '))) - *s++ = '\0'; - } while (s && *s && *s == ' ') s++; - argv[i] = s ? s : NULL; + argv[i] = s; + if (s && (s = strchr(s, ' '))) + *s++ = '\0'; } cmd->cmd(argv);