Skip to content

Commit

Permalink
emacs: remove broken line overflow behaviour
Browse files Browse the repository at this point in the history
In emacs.c, some absolute breakage happens when the command line
being entered exceeds MAXLINE - 2 (1022) characters:

345: if ((eol+1) >= (scend)) /* will not fit on line */
346: {
347: 	ed_ungetchar(ep->ed,c); /* save character for next line */
348:	goto process;
349: }

The PS2 line continuation prompt is inserted in the display
(without starting a new line) and you cannot backspace beyond it.
E.g., when entering a series of more than 1024 'x' characters:

[...] xxxxxxxxxxxxxxxxxxxxxxxx> xxxxxxx▂
                              ^^ $PS2
^^^^^^^^^now inaccessible^^^^^

Except for the corrupted display of PS2 and the inability to
access/edit text preceding it, this sort of works, although it's a
botch. However, it's much worse when the maximum command line
length is exceeded while inserting new text *before* the current
end of the line. PS2 is displayed at the current cursor position,
but the overflow character is inserted at the start of the "new"
line, and not at the cursor position! And that's where editing
continues, though the display is not reflecting this fact.

The vi mode simply beeps in this situation, refusing to add more
characters when the line is full. From now on, emacs does the same:
beep, kill any remaining lookahead, update command line display if
necessary, and continue to read the next keyboard input.
  • Loading branch information
McDutchie committed Jan 8, 2025
1 parent 6b69b4f commit 63c7571
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ This documents significant changes in the dev branch of ksh 93u+m.
For full details, see the git log at: https://github.com/ksh93/ksh
Uppercase BUG_* IDs are shell bug IDs as used by the Modernish shell library.

2025-01-08:

- Fixed buggy emacs mode behaviour on exceeding the maximum line length.

2025-01-07:

- Fixed the expansion ${variable//""/string}; since the shell pattern is
Expand Down
9 changes: 6 additions & 3 deletions src/cmd/ksh93/edit/emacs.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,11 +341,14 @@ int ed_emacsread(void *context, int fd,char *buff,int scend, int reedit)
}
do_default_processing:
default:

/* ordinary typing: insert one character */
if ((eol+1) >= (scend)) /* will not fit on line */
{
ed_ungetchar(ep->ed,c); /* save character for next line */
goto process;
beep();
lookahead = 0;
if (!ep->scvalid)
draw(ep,UPDATE);
continue;
}
for(i= ++eol; i>cur; i--)
out[i] = out[i-1];
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/ksh93/include/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <ast_release.h>
#include "git.h"

#define SH_RELEASE_DATE "2025-01-07" /* must be in this format for $((.sh.version)) */
#define SH_RELEASE_DATE "2025-01-08" /* must be in this format for $((.sh.version)) */
/*
* This comment keeps SH_RELEASE_DATE a few lines away from SH_RELEASE_SVER to avoid
* merge conflicts when cherry-picking dev branch commits onto a release branch.
Expand Down

0 comments on commit 63c7571

Please sign in to comment.