mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
Handle forward-delete key in emacs and vi editors
On every modern system, the forward-delete key on PC/Mac keyboards generates the VT220 sequence ESC [ 3 ~. Every other shell with an editor handles this now, ksh93 seems to be the last not to. src/cmd/ksh93/edit/emacs.c: escape(): - Handle the ^[[3 as part of normal escape processing, then read an extra character to check for the final '~'. If detected, insert an ERASECHAR key event. src/cmd/ksh93/edit/vi.c: mvcursor(): - Replace the ^[[3~ sequence by an 'x' command. We have to special-case its processing, because vi mode parses numbers as repetition operators. The escape sequence contains a number, making it incompatible with normal command handling. This means number repetitions don't work with the forward-delete key. If that annoys anyone enough to fix it, a patch would be welcome. For now, it will do to make the forward-delete key stop exhibiting bizarre behaviour (beep + change case + move forward). src/cmd/ksh93/sh.1 - Copy-edit emacs documentation for VT220-style sequences; map them to their actual key, otherwise it's meaningless to the reader. - Document the new forward-delete key behaviour for emacs mode. - Leave the forward-delete key for vi mode undocumented for now, as repetitions don't work, so it doesn't really match the vi canon. (OTOH, it doesn't work in vim, either...)
This commit is contained in:
parent
f0be4d95e8
commit
f2a3f4e36b
4 changed files with 50 additions and 13 deletions
|
@ -1109,6 +1109,19 @@ static int escape(register Emacs_t* ep,register genchar *out,int count)
|
|||
case 'Y':
|
||||
ed_ungetchar(ep->ed,cntl('E'));
|
||||
return(-1);
|
||||
case '3':
|
||||
if(ed_getchar(ep->ed,1)=='~')
|
||||
{ /*
|
||||
* VT220 forward-delete key.
|
||||
* Since ERASECHAR and EOFCHAR are usually both mapped to ^D, we
|
||||
* should only issue ERASECHAR if there is something to delete,
|
||||
* otherwise forward-delete on empty line will terminate the shell.
|
||||
*/
|
||||
if(cur < eol)
|
||||
ed_ungetchar(ep->ed,ERASECHAR);
|
||||
return(-1);
|
||||
}
|
||||
/* FALLTHROUGH */
|
||||
default:
|
||||
ed_ungetchar(ep->ed,i);
|
||||
}
|
||||
|
|
|
@ -1606,6 +1606,7 @@ static int mvcursor(register Vi_t* vp,register int motion)
|
|||
register int tcur_virt;
|
||||
register int incr = -1;
|
||||
register int bound = 0;
|
||||
int c;
|
||||
|
||||
switch(motion)
|
||||
{
|
||||
|
@ -1632,7 +1633,14 @@ static int mvcursor(register Vi_t* vp,register int motion)
|
|||
break;
|
||||
|
||||
case '[':
|
||||
switch(motion=getcount(vp,ed_getchar(vp->ed,-1)))
|
||||
c = ed_getchar(vp->ed,-1);
|
||||
if(c=='3' && ed_getchar(vp->ed,-1)=='~')
|
||||
{
|
||||
/* VT220 forward-delete key */
|
||||
ed_ungetchar(vp->ed,'x');
|
||||
return(1);
|
||||
}
|
||||
switch(motion=getcount(vp,c))
|
||||
{
|
||||
case 'A':
|
||||
#if SHOPT_EDPREDICT
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue