From 446197fdee72b8960ac587bd61881bd7c5556d9c Mon Sep 17 00:00:00 2001 From: Steve Bennett Date: Fri, 1 Oct 2010 08:32:44 +1000 Subject: [PATCH] Add support for ^W to remove a word on the left Signed-off-by: Steve Bennett --- linenoise.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/linenoise.c b/linenoise.c index 3911a51..0812467 100644 --- a/linenoise.c +++ b/linenoise.c @@ -366,6 +366,24 @@ process_char: free(history[history_len]); return -1; } + case 23: /* ctrl-w */ + /* eat any spaces on the left */ + { + int n = 0; + while (pos > 0 && len > 0 && buf[pos - 1] == ' ') { + pos--; + len--; + n++; + } + /* now eat any non-spaces on the left */ + while (pos > 0 && len > 0 && buf[pos - 1] != ' ') { + pos--; + len--; + n++; + } + memmove(buf+pos,buf+pos+n,len-pos); + refreshLine(fd,prompt,buf,len,pos,cols); + } break; case 18: /* ctrl-r */ { -- 2.44.0