1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-02-15 04:32:24 +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:
Martijn Dekker 2020-09-15 00:49:05 +02:00
parent f0be4d95e8
commit f2a3f4e36b
4 changed files with 50 additions and 13 deletions

2
NEWS
View file

@ -8,6 +8,8 @@ Any uppercase BUG_* names are modernish shell bug IDs.
- Corrected rounding of floating point values by ksh's printf %f formatting
operator. Fix contributed by @hyenias.
- The forward-delete key now works as expected in emacs and vi editing modes.
2020-09-11:
- The 'command' regular builtin utility (which runs a simple command, removing

View file

@ -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);
}

View file

@ -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

View file

@ -4597,6 +4597,11 @@ operate from any place on the line
Neither the `RETURN' nor the `LINE FEED' key is
entered after edit commands except when noted.
.PP
The \fBM-[\fR multi-character commands below are DEC VT220 escape sequences
generated by keys on modern PC/Mac keyboards, such as the arrow keys.
You could type them directly but they are meant to recognize the keys
in question, which are indicated in parentheses.
.PP
.PD 0
.TP 10
.BI ^F
@ -4604,7 +4609,7 @@ Move cursor forward (right) one character.
.PP
.TP 10
.BI M-[C
Move cursor forward (right) one character.
(Right arrow) Same as \fB^F\fR.
.PP
.TP 10
.BI M-f
@ -4620,7 +4625,7 @@ Move cursor backward (left) one character.
.PP
.TP 10
.BI M-[D
Move cursor backward (left) one character.
(Left arrow) Same as \fB^B\fR.
.PP
.TP 10
.BI M-b
@ -4632,15 +4637,19 @@ Move cursor to start of line.
.PP
.TP 10
.BI M-[H
Move cursor to start of line.
(Home) Same as \fB^A\fR.
.PP
.TP 10
.BI ^E
Move cursor to end of line.
.PP
.TP 10
.BI M-[F
(End) Same as \fB^E\fR.
.PP
.TP 10
.BI M-[Y
Move cursor to end of line.
Same as \fB^E\fR.
.PP
.TP 10
.BI ^] char
@ -4664,9 +4673,7 @@ Interchange the cursor and mark.
by the
.IR stty (1)
command, usually
.B ^H
or
.BR # .)
.B ^H .)
Delete previous character.
.PP
.TP 10
@ -4686,6 +4693,10 @@ editing features (if any).
Delete current character.
.PP
.TP 10
.BI M-[3~
(Forward delete) Same as \fB^D\fR.
.PP
.TP 10
.BI M-d
Delete current word.
.PP
@ -4748,15 +4759,16 @@ Push the region from the cursor to the mark on the stack.
.I kill
(User defined kill character as defined
by the stty command, usually
.B ^G
or
.BR @ .)
.B ^U .)
Kill the entire current line.
If two
.I kill
characters are entered in succession, all
kill characters from then on cause a line feed
(useful when using paper terminals).
A subsequent pair of
.I kill
characters undoes this change.
.PP
.TP 10
.BI ^Y
@ -4805,6 +4817,7 @@ Moves back one line when not on the first line of a multi-line command.
.PP
.TP 10
.BI M-[A
(Up arrow)
If the cursor is at the end of the line, it is equivalent to
.B ^R
with
@ -4812,7 +4825,7 @@ with
set to the contents of the current line.
Otherwise, it is
equivalent to
.BR ^P.
.BR ^P .
.PP
.TP 10
.BI M-<
@ -4832,8 +4845,9 @@ the next command line forward in time is accessed.
.PP
.TP 10
.BI M-[B
(Down arrow)
Equivalent to
.BR ^N.
.BR ^N .
.PP
.TP 10
.BI ^R string