1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

No completion before 1st char or in empty line (re: b6c8bb7b) (#523)

There are still two contexts in which the unhelpful "alias +
builtin + path" completion occurs:

* After the start of an empty line
* After the start of a line, but before the first character

To stop completion from being attempted in these contexts, a loop
is added to vi.c and emacs.c that looks over the previous positions
(current position inclusive) and allows the completion process to
continue once it finds the first non-space character. The existing
placement restrictions remain in case the cursor arrives in a
negative position via a bug.

Co-authored-by: Martijn Dekker <martijn@inlv.org>
This commit is contained in:
pghvlaans 2022-08-25 02:09:33 +09:00 committed by Martijn Dekker
parent 9e7ecb1b17
commit a874586fdc
3 changed files with 48 additions and 6 deletions

View file

@ -1001,8 +1001,19 @@ static int escape(register Emacs_t* ep,register genchar *out,int count)
/* FALLTHROUGH */
case '*': /* filename expansion */
case '=': /* escape = - list all matching file names */
{
char allempty = 1;
int x;
ep->mark = cur;
if(cur<1)
for(x=0; x < cur; x++)
{
if(!isspace(out[x]))
{
allempty = 0;
break;
}
}
if(cur<1 || allempty)
{
beep();
return(-1);
@ -1040,6 +1051,7 @@ static int escape(register Emacs_t* ep,register genchar *out,int count)
draw(ep,UPDATE);
}
return(-1);
}
/* search back for character */
case cntl(']'): /* feature not in book */

View file

@ -1537,6 +1537,22 @@ static void getline(register Vi_t* vp,register int mode)
return;
case '\t': /** command completion **/
{
char allempty = 1;
int x;
for(x=0; x <= cur_virt; x++)
{
if(!isspace(virtual[x]))
{
allempty = 0;
break;
}
}
if(allempty)
{
ed_ringbell();
break;
}
if(sh_isoption(SH_VI) &&
mode != SEARCH &&
last_virt >= 0 &&
@ -1566,6 +1582,7 @@ static void getline(register Vi_t* vp,register int mode)
break;
}
/* FALLTHROUGH */
}
default:
fallback:
if( mode == REPLACE )
@ -2545,7 +2562,18 @@ addin:
case '*': /** do file name expansion in place **/
case '\\': /** do file name completion in place **/
case '=': /** list file name expansions **/
if( cur_virt == INVALID )
{
char allempty = 1;
int x;
for(x=0; x <= cur_virt; x++)
{
if(!isspace(virtual[x]))
{
allempty = 0;
break;
}
}
if(cur_virt == INVALID || allempty)
return(BAD);
/* FALLTHROUGH */
save_v(vp);
@ -2584,6 +2612,7 @@ addin:
return(APPEND);
}
break;
}
case '@': /** macro expansion **/
if( mode )

View file

@ -4987,6 +4987,8 @@ will provide a numbered list of matching alternatives.
A specific selection can be made by entering the
selection number followed by a
.IR tab .
Neither completion nor listing operations are attempted before
the first character in a line.
.SS Key Bindings.
The
.B
@ -5581,10 +5583,9 @@ or
character.
.TP 10
.BI ^I " tab"
Except at the start of the line, attempts command or
file name completion as described above and returns to
input mode. If a partial completion occurs, repeating
this will behave as if
Attempts command or file name completion as described
above and returns to input mode. If a partial completion
occurs, repeating this will behave as if
.B =
were entered from control mode.
If no match is found or entered after