Skip to content

Commit

Permalink
[v1.1] emacs: accept numeric parameter for ^Y
Browse files Browse the repository at this point in the history
As of this commit, the ^Y (yank, a.k.a. paste) command accepts a
numeric parameter that will be taken as a repeat count. This can be
quite handy if you want to repeat text. Delete what you want to
repeat, then do ESC 10 ^Y to re-insert the deleted text 10 times.

src/cmd/ksh93/edit/emacs.c: ed_emacsread(): case cntl('Y'):
- Remove extra indentation due to unnecessary braces.
- Handle the numeric parameter 'count', already provided:
  - Multiply the length of the kill stack by count to check bounds
    and to shift the text under and to the right of the cursor.
  - Reinsert the contents of the kill stack count times.
  • Loading branch information
McDutchie committed Dec 29, 2024
1 parent 64050f7 commit be0cfbf
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 13 deletions.
3 changes: 3 additions & 0 deletions ANNOUNCE
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ New command line editor features:
saved before exiting the editor. This removes the need to empty the file
and save just to cancel execution.

- The emacs ^Y command now accepts a numeric parameter. For example,
ESC 10 ^Y will now "yank" (paste) the latest deleted text 10 times.

New shell language features:

- The appending redirection operator &>>FILE is now available. It is a
Expand Down
5 changes: 5 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ 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.

2024-12-29:

- [v1.1] The emacs ^Y command now accepts a numeric parameter. For example,
ESC 10 ^Y will now "yank" (paste) the latest deleted text 10 times.

2024-12-25:

- The dirname path-bound built-in now accepts multiple operands.
Expand Down
25 changes: 13 additions & 12 deletions src/cmd/ksh93/edit/emacs.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,23 +384,24 @@ int ed_emacsread(void *context, int fd,char *buff,int scend, int reedit)
draw(ep,APPEND);
continue;
case cntl('Y') :
c = count * genlen(kstack);
if (c + eol > scend)
{
beep();
continue;
}
ep->mark = i;
for (i = eol; i >= cur; i--)
out[c + i] = out[i];
while (count--)
{
c = genlen(kstack);
if ((c + eol) > scend)
{
beep();
continue;
}
ep->mark = i;
for(i=eol;i>=cur;i--)
out[c+i] = out[i];
kptr=kstack;
while (i = *kptr++)
out[cur++] = i;
draw(ep,UPDATE);
eol = genlen(out);
continue;
}
draw(ep,UPDATE);
eol = genlen(out);
continue;
case '\n':
case '\r':
c = '\n';
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 "2024-12-25" /* must be in this format for $((.sh.version)) */
#define SH_RELEASE_DATE "2024-12-29" /* 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
1 change: 1 addition & 0 deletions src/cmd/ksh93/sh.1
Original file line number Diff line number Diff line change
Expand Up @@ -5489,6 +5489,7 @@ The commands that accept a parameter are
.BR ^R ,
.BR ^P ,
.BR ^N ,
.BR ^Y ,
.BR ^] ,
.BR M-. ,
.BR M-^] ,
Expand Down

0 comments on commit be0cfbf

Please sign in to comment.