From b9113980642f37d780d646fcbf4ef90dca69ae3f Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Thu, 7 Apr 2016 20:24:43 -0700 Subject: 38248: fix word position calculation when completing on or just before a redirection operator The completion result is still in need of some repair; e.g., if the first thing on the line is the redirection, completion before it is not taken to be in command position, and in this and other cases a necessary space is not inserted between the completed word and the redirection. --- ChangeLog | 6 ++++++ Src/Zle/zle_tricky.c | 15 +++++++++++++++ Src/lex.c | 10 +++++++--- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7aca23750..b6fb070ca 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2016-04-07 Barton E. Schaefer + + * 38248: Src/Zle/zle_tricky.c: fix word position calculation + when completing on or just before a redirection operator; the + completion result is still in need of some repair + 2016-04-03 Barton E. Schaefer * 38229: Src/Zle/zle_tricky.c: fix cursor placement calculation diff --git a/Src/Zle/zle_tricky.c b/Src/Zle/zle_tricky.c index b1709c117..1d4e1d284 100644 --- a/Src/Zle/zle_tricky.c +++ b/Src/Zle/zle_tricky.c @@ -1161,6 +1161,7 @@ get_comp_string(void) inpush(dupstrspace(linptr), 0, NULL); strinbeg(0); wordpos = cp = rd = ins = oins = linarr = parct = ia = redirpos = 0; + we = wb = zlemetacs; tt0 = NULLTOK; /* This loop is possibly the wrong way to do this. It goes through * @@ -1238,6 +1239,20 @@ get_comp_string(void) /* Record if we haven't had the command word yet */ if (wordpos == redirpos) redirpos++; + if (zlemetacs < (zlemetall - inbufct) && + zlemetacs >= wordbeg && wb == we) { + /* Cursor is in the middle of a redirection, treat as a word */ + we = zlemetall - (inbufct + addedx); + if (addedx && we > wb) { + /* Assume we are in {param}> form, wb points at "{" */ + wb++; + /* Should complete parameter names here */ + } else { + /* In "2>" form, zlemetacs points at "2" */ + wb = zlemetacs; + /* Should insert a space under cursor here */ + } + } } if (tok == DINPAR) tokstr = NULL; diff --git a/Src/lex.c b/Src/lex.c index d4132fe76..25b372a3c 100644 --- a/Src/lex.c +++ b/Src/lex.c @@ -1789,9 +1789,13 @@ parse_subst_string(char *s) static void gotword(void) { - we = zlemetall + 1 - inbufct + (addedx == 2 ? 1 : 0); - if (zlemetacs <= we) { - wb = zlemetall - wordbeg + addedx; + int nwe = zlemetall + 1 - inbufct + (addedx == 2 ? 1 : 0); + if (zlemetacs <= nwe) { + int nwb = zlemetall - wordbeg + addedx; + if (zlemetacs >= nwb) { + wb = nwb; + we = nwe; + } lexflags = 0; } } -- cgit 1.4.1