Page MenuHomeFreeBSD

sh: improve emacs mode
ClosedPublic

Authored by bapt on Aug 28 2021, 1:01 PM.
Tags
None
Referenced Files
F81668344: D31706.id94304.diff
Fri, Apr 19, 5:03 PM
Unknown Object (File)
Thu, Apr 18, 11:37 AM
Unknown Object (File)
Dec 22 2023, 11:43 PM
Unknown Object (File)
Nov 13 2023, 12:33 PM
Unknown Object (File)
Nov 11 2023, 12:34 PM
Unknown Object (File)
Nov 9 2023, 10:09 AM
Unknown Object (File)
Oct 13 2023, 10:16 AM
Unknown Object (File)
Oct 12 2023, 4:42 PM
Subscribers

Details

Reviewers
pstef
jilles
manu
Summary

in emacs mode ^W should delete the previous word by default

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 41245
Build 38134: arc lint + arc unit

Event Timeline

bapt requested review of this revision.Aug 28 2021, 1:01 PM

OK, but perhaps this fix should be in libedit instead. The same issue can be seen in other libedit clients such as ftp(1).

Not tested but looks good :)

This revision is now accepted and ready to land.Aug 28 2021, 1:23 PM

OK, but perhaps this fix should be in libedit instead. The same issue can be seen in other libedit clients such as ftp(1).

my plan is to first commit in sh(1) and have behaving correctly, then I will work on fixing libedit. (and discuss with upstream) for sure I will drop those lines from sh(1) once they are in libedit for long enough.

By the way, since this is in histedit(), the binding won't survive bind -e which ultimately does keymacro_reset() and the binding from histedit() never get the chance to be restored. I think bindcmd() should call histedit() somewhere near the INTON. histedit() should be clever enough to do only the if (el) { part that is expanded in this patch.

#0  keymacro_reset (el=el@entry=0x800a41000) at /usr/src/contrib/libedit/keymacro.c:165
#1  0x000000080028e30d in map_init_emacs (el=el@entry=0x800a41000) at /usr/src/contrib/libedit/map.c:1068
#2  0x000000080028eae1 in map_bind (el=0x800a41000, argc=1, argv=<optimized out>) at /usr/src/contrib/libedit/map.c:1296
#3  0x000000080028f1eb in el_wparse (el=<optimized out>, el@entry=0x800a41000, argc=argc@entry=2, argv=0x800ad12a0) at /usr/src/contrib/libedit/parse.c:130
#4  0x000000080028624a in el_parse (el=0x800a41000, argc=argc@entry=2, argv=<optimized out>, argv@entry=0x800aa3480) at /usr/src/contrib/libedit/eln.c:97
#5  0x00000000002166dd in bindcmd (argc=2, argv=0x800aa3480) at /usr/src/bin/sh/histedit.c:557
In D31706#715350, @bapt wrote:

OK, but perhaps this fix should be in libedit instead. The same issue can be seen in other libedit clients such as ftp(1).

my plan is to first commit in sh(1) and have behaving correctly, then I will work on fixing libedit. (and discuss with upstream) for sure I will drop those lines from sh(1) once they are in libedit for long enough.

It seems this change has been made in libedit already. So perhaps instead of adding ^W we could remove ^R and update libedit.

And make bindcmd() call histedit():

commit 514fa9eda503d8781fea160d368825e5be2b3594 (HEAD -> private)
Author: Piotr Pawel Stefaniak <pstef@FreeBSD.org>
Date:   Sun Sep 19 22:17:01 2021 +0200

    sh: reset sh bindings on bind -e, bind -v

    Until this change, any bindings set in histedit() were lost on calls to
    bindcmd().

    Only bind -e and bind -v call libedit's keymacro_reset(). Currently you
    cannot fool libedit/map.c:map_bind() by trying something like bind -le
    as when p[0] == '-', it does a switch statement on p[1].

diff --git a/bin/sh/histedit.c b/bin/sh/histedit.c
index 7f1cfce3069..cabfaa8e734 100644
--- a/bin/sh/histedit.c
+++ b/bin/sh/histedit.c
@@ -560,6 +560,13 @@ bindcmd(int argc, char **argv)

        fclose(out);

+       if (argc > 1 &&
+           (strncmp(argv[1], "-e", 2) == 0 || strncmp(argv[1], "-v", 2) == 0)) {
+               Vflag = argv[1][1] == 'v';
+               Eflag = argv[1][1] == 'e';
+               histedit();
+       }
+
        INTON;

        return ret;