diff --git a/NEWS b/NEWS index ee018af28..3379fb49e 100644 --- a/NEWS +++ b/NEWS @@ -8,6 +8,11 @@ Any uppercase BUG_* names are modernish shell bug IDs. - Fixed buggy tab completion of tilde-expanded paths such as ~/some in 'vi' mode. +- In the raw/default Bourne Shell-like editing mode that occurs when neither + the 'emacs' nor the 'vi' shell option is active: + * tab completion is now correctly disabled, instead of enabled and broken; + * entering tab characters now moves the cursor the correct amount. + 2020-06-23: - Fixed a bug that caused combining process substitution with redirection diff --git a/src/cmd/ksh93/edit/edit.c b/src/cmd/ksh93/edit/edit.c index 705db4e43..1f94331ce 100644 --- a/src/cmd/ksh93/edit/edit.c +++ b/src/cmd/ksh93/edit/edit.c @@ -1342,8 +1342,7 @@ int ed_virt_to_phys(Edit_t *ep,genchar *virt,genchar *phys,int cur,int voff,int if(c=='\t') { c = dp-phys; - if(sh_isoption(SH_VI)) - c += ep->e_plen; + c += ep->e_plen; c = TABSIZE - c%TABSIZE; while(--c>0) *dp++ = ' '; @@ -1354,8 +1353,7 @@ int ed_virt_to_phys(Edit_t *ep,genchar *virt,genchar *phys,int cur,int voff,int *dp++ = '^'; c = printchar(c); } - /* in vi mode the cursor is at the last character */ - if(curp == sp && sh_isoption(SH_VI)) + if(curp == sp) r = dp - phys; } *dp++ = c; diff --git a/src/cmd/ksh93/edit/vi.c b/src/cmd/ksh93/edit/vi.c index 41fa1cbdc..99d2e20ff 100644 --- a/src/cmd/ksh93/edit/vi.c +++ b/src/cmd/ksh93/edit/vi.c @@ -1541,7 +1541,11 @@ static void getline(register Vi_t* vp,register int mode) return; case '\t': /** command completion **/ - if(mode!=SEARCH && last_virt>=0 && (vp->ed->e_tabcount|| !isblank(cur_virt)) && vp->ed->sh->nextprompt) + if(sh_isoption(SH_VI) && + mode != SEARCH && + last_virt >= 0 && + (vp->ed->e_tabcount || !isblank(cur_virt)) && + vp->ed->sh->nextprompt) { if(virtual[cur_virt]=='\\') { diff --git a/src/cmd/ksh93/tests/pty.sh b/src/cmd/ksh93/tests/pty.sh index d4c445eb1..b81af65be 100755 --- a/src/cmd/ksh93/tests/pty.sh +++ b/src/cmd/ksh93/tests/pty.sh @@ -470,5 +470,40 @@ u ^/tmp/fakehome/testfile\r?\n$ ! rm -r /tmp/fakehome +# err_exit # +LC_ALL=C tst $LINENO <<"!" +L raw Bourne mode literal tab characters with wide characters disabled + +# This gets handled by ed_read() in edit.c; it does not expand tab +# characters on the command line. + +w set +o vi +o emacs +p :test-2: +w true /de\tv/nu\tl\tl +r ^:test-2: true /de\tv/nu\tl\tl\r\n$ +p :test-3: +! + +# err_exit # +LC_ALL=C.UTF-8 tst $LINENO <<"!" +L raw Bourne mode literal tab characters with wide characters enabled + +# This gets handled by ed_viread() in vi.c (even though vi mode is off); +# it expands tab characters to spaces on the command line. + +w set +o vi +o emacs +p :test-2: +w true /de\tv/nu\tl\tl + +# TODO: there is some race condition in either pty or in ksh's default edit +# mode, which causes it to expect/generate either tabs ('\t') or expanded +# spaces, randomly, intermittently. This is functionally equivalent as it +# only affects either pty or (invisibly) the editing command line, so not a +# high priority. Until this is tracked down and fixed, accept both. + +r ^:test-2: true (/de\tv/nu\tl\tl|/de v/nu l l)\r\n$ +p :test-3: +! + # ====== exit $((Errors<125?Errors:125))