vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

commit d67441433f705e49e6f0ac4586f0850a4c3790b6
parent d7684fe037d7b9af1cf7b1c8f10295d16b0cfde5
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Thu, 25 Sep 2014 17:23:20 +0200

Exit command prompt if last character is deleted

Diffstat:
Mconfig.def.h | 1+
Mvis.c | 11+++++++++++
2 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/config.def.h b/config.def.h @@ -456,6 +456,7 @@ static KeyBinding vis_mode_readline[] = { }; static KeyBinding vis_mode_prompt[] = { + BACKSPACE( prompt_backspace, s, NULL ), { { KEY(ENTER) }, prompt_enter, { NULL } }, { { CONTROL('J') }, prompt_enter, { NULL } }, { { KEY(UP) }, prompt_up, { NULL } }, diff --git a/vis.c b/vis.c @@ -422,6 +422,8 @@ static void prompt_enter(const Arg *arg); /* cycle through past user inputs */ static void prompt_up(const Arg *arg); static void prompt_down(const Arg *arg); +/* exit command mode if the last char is deleted */ +static void prompt_backspace(const Arg *arg); /* blocks to read 3 consecutive digits and inserts the corresponding byte value */ static void insert_verbatim(const Arg *arg); /* scroll window content according to arg->i which can be either PAGE, PAGE_HALF, @@ -875,6 +877,15 @@ static void prompt_down(const Arg *arg) { } +static void prompt_backspace(const Arg *arg) { + char *cmd = editor_prompt_get(vis); + if (!cmd || !*cmd) + prompt_enter(NULL); + else + window_backspace_key(vis->win->win); + free(cmd); +} + static void insert_verbatim(const Arg *arg) { int value = 0; for (int i = 0; i < 3; i++) {