From 29b11bba3ac25f468ef8db4829cd64d4d0ca5330 Mon Sep 17 00:00:00 2001 From: Johnothan King Date: Mon, 15 Feb 2021 17:47:15 -0800 Subject: [PATCH] Fix the Alt+D and Alt+H keyboard shortcuts in emacs mode (#178) This commit fixes the functionality of Alt+D and Alt+H in emacs mode. These keyboard shortcuts are intended to work on whole words, but after commit 13c3fb21 their functionality was reduced to deleting only singular letters: $ Test word # This should delete 'word', not just 'd'. $ Foo # This should delete 'Foo', not just 'F'. Man page entries for reference: M-d Delete current word. M-^H (Meta-backspace) Delete previous word. M-h Delete previous word. src/cmd/ksh93/edit/emacs.c: - 'count' cannot be overridden when handling Alt+D or Alt+H, so add the total number of repetitions to count (the number of repetitions can't be negative). - If 'count' is a negative number, set it to one before adding the number of repetitions. --- NEWS | 3 +++ src/cmd/ksh93/edit/emacs.c | 10 +++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/NEWS b/NEWS index e1602b007..fecc39850 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,9 @@ Any uppercase BUG_* names are modernish shell bug IDs. 2021-02-15: +- Fixed a bug in the emacs built-in editor, introduced on 2020-09-17, that + made the Meta-D and Meta-H keys delete single characters instead of words. + - A new 'backslashctrl' shell option has been added. It is on by default. Turning it off (set +o backslashctrl or set --nobackslashctrl) disables the special escaping behaviour of the backslash character in the emacs and vi diff --git a/src/cmd/ksh93/edit/emacs.c b/src/cmd/ksh93/edit/emacs.c index cefb4b033..b5e483645 100644 --- a/src/cmd/ksh93/edit/emacs.c +++ b/src/cmd/ksh93/edit/emacs.c @@ -318,13 +318,13 @@ int ed_emacsread(void *context, int fd,char *buff,int scend, int reedit) killing = 0; #endif oadjust = count = adjust; - if(vt220_save_repeat) - { - count = vt220_save_repeat; - vt220_save_repeat = 0; - } if(count<0) count = 1; + if(vt220_save_repeat>0) + { + count += vt220_save_repeat; + vt220_save_repeat = 0; + } adjust = -1; i = cur; if(c!='\t' && c!=ESC && !digit(c))