Hello Mr. Ankarström, I have challenged to try to make shell_expand_line in ksh. You can check it if you type M-C-e.
$ echo "$(echo a b)" $ echo "a b" $ alias ll='ls -l' $ ll $(echo a b) hoge "$(( 1 + 1 ))" ll bar $ ls -l a b hoge "2" ll bar To be honest, I'm not sure if this is correct. I only like OpenBSD, That's why I'm so sorry if they're wrong Best regards, Hajime Edakawa Index: emacs.c =================================================================== RCS file: /cvs/src/bin/ksh/emacs.c,v retrieving revision 1.84 diff -u -p -r1.84 emacs.c --- emacs.c 16 Jan 2018 17:17:18 -0000 1.84 +++ emacs.c 9 Oct 2018 22:47:44 -0000 @@ -195,6 +195,7 @@ static int x_fold_lower(int); static int x_fold_upper(int); static int x_set_arg(int); static int x_comment(int); +static int x_shell_expand_line(int); #ifdef DEBUG static int x_debug_info(int); #endif @@ -251,6 +252,7 @@ static const struct x_ftab x_ftab[] = { { x_fold_upper, "upcase-word", XF_ARG }, { x_set_arg, "set-arg", XF_NOBIND }, { x_comment, "comment", 0 }, + { x_shell_expand_line, "shell-expand-line", 0 }, { 0, 0, 0 }, #ifdef DEBUG { x_debug_info, "debug-info", 0 }, @@ -1467,6 +1469,7 @@ x_init_emacs(void) kb_add(x_comp_file, CTRL('['), CTRL('X'), 0); kb_add(x_comp_list, CTRL('I'), 0); kb_add(x_comp_list, CTRL('['), '=', 0); + kb_add(x_shell_expand_line, CTRL('['), CTRL('E'), 0); kb_add(x_del_back, CTRL('?'), 0); kb_add(x_del_back, CTRL('H'), 0); kb_add(x_del_char, CTRL('['), '[', '3', '~', 0); /* delete */ @@ -1700,6 +1703,48 @@ x_expand(int c) return KSTD; } } + x_adjust(); + + return KSTD; +} +static int +x_shell_expand_line(int c) +{ + int skip = 0, len = 0, size = 0; + char *cp, *word, *name, *buf; + struct tbl *tp; + + if (xep == xbuf) { + x_e_putc(BEL); + return KSTD; + } + + cp = xbuf; + while (cp != xep && is_mfs(*cp)) + skip += x_size(*cp++); + + word = cp; + while (cp != xep && !is_mfs(*cp)) { + size += x_size(*cp++); + len++; + } + + if (len > 0) { + name = strndup(word, len); + tp = ktsearch(&aliases, name, hash(name)); + if (tp) { + x_goto(xbuf + skip); + x_delete(size, false); + x_ins(tp->val.s); + } + } + + size = x_size_str(xbuf); + buf = substitute(xbuf, 0); + + x_goto(xbuf); + x_delete(size, false); + x_ins(buf); x_adjust(); return KSTD; 2018年10月7日(日) 4:41 John Ankarström <j...@ankarstrom.se>: > > Hello again, > > Is there a way for ksh to expand a $(command substitution) without > having to execute the entire line? > > bash provides this via shell-expand-line (bound to Ctrl-Alt-e by > default), and ksh seems to have expand-file, but that only works for > filenames. > > Any ideas? > > Best regards, > John >