From be0cfbffcb1b94a4d5cbda723cc9a1f567b771f4 Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Sun, 29 Dec 2024 01:05:24 +0100 Subject: [PATCH] [v1.1] emacs: accept numeric parameter for ^Y 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. --- ANNOUNCE | 3 +++ NEWS | 5 +++++ src/cmd/ksh93/edit/emacs.c | 25 +++++++++++++------------ src/cmd/ksh93/include/version.h | 2 +- src/cmd/ksh93/sh.1 | 1 + 5 files changed, 23 insertions(+), 13 deletions(-) diff --git a/ANNOUNCE b/ANNOUNCE index 161e13291990..f3e95564e4cf 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -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 diff --git a/NEWS b/NEWS index dda58f0c8b32..bee1a3506e74 100644 --- a/NEWS +++ b/NEWS @@ -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. diff --git a/src/cmd/ksh93/edit/emacs.c b/src/cmd/ksh93/edit/emacs.c index b0aa035b3a52..9783ffe98bba 100644 --- a/src/cmd/ksh93/edit/emacs.c +++ b/src/cmd/ksh93/edit/emacs.c @@ -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'; diff --git a/src/cmd/ksh93/include/version.h b/src/cmd/ksh93/include/version.h index 1593d171e2ec..96af922cfbb9 100644 --- a/src/cmd/ksh93/include/version.h +++ b/src/cmd/ksh93/include/version.h @@ -18,7 +18,7 @@ #include #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. diff --git a/src/cmd/ksh93/sh.1 b/src/cmd/ksh93/sh.1 index b2161945c7c7..758929f1306f 100644 --- a/src/cmd/ksh93/sh.1 +++ b/src/cmd/ksh93/sh.1 @@ -5489,6 +5489,7 @@ The commands that accept a parameter are .BR ^R , .BR ^P , .BR ^N , +.BR ^Y , .BR ^] , .BR M-. , .BR M-^] ,