On Tue, Nov 10, 2020 at 06:49:28PM +0100, Sven M. Hallberg wrote: > Apologies for jumping in as a bystander, but if I may comment: > > Anton Lindqvist on Tue, Nov 10 2020: > > Been brought up before[1] and rejected[2][3]. > > Anton Lindqvist on Sun, Jul 02, 2017: > > diff below in which slashes are discarded when comparing the length. I > > don't know if any other character should be discarded as well, if true > > then it might be worth passing the input buffer through ksh's own > > lexer and [...] > > The patch then seems to have been rejected for further complicating some > already hairy code and the above does sound rather unsafe. > > Michael's aim here appears to be to simplify things: > > Michael Forney on Mon, Nov 09, 2020: > > emacs.c:do_complete() using `end - start` for olen (which counts the > > backslashes), but nlen (the longest prefix length) does not. [...] > > > > I don't believe vi.c:complete_word() has this issue [...] > > > > [my diff] is longer than I had hoped. Perhaps there is a simpler patch > > to make emacs.c:do_complete() use the same approach as vi completion. > > Maybe some iteration is all that is needed.
I not saying the diff is bad in anyway, just sharing a related data point. I do think this would be an improvement and the approach looks better than mine. As I would address this, the numbers of arguments passed to the completion related routines is already painfully^W long. I would rather take a step back and introduce a `struct globstate' (just an example, could be renamed) which includes all the necessary parameters. Getting such refactoring in place first would make the diff even smaller. Also, emacs mode has its own regress suite located in regress/bin/ksh/edit/emacs.sh. Tricky logic like this should be covered in my opinion. Below is a rough diff how to test file name completion. Michael, is this something you would like to continue work on? Index: emacs.sh =================================================================== RCS file: /cvs/src/regress/bin/ksh/edit/emacs.sh,v retrieving revision 1.11 diff -u -p -r1.11 emacs.sh --- emacs.sh 3 Apr 2019 14:59:34 -0000 1.11 +++ emacs.sh 10 Nov 2020 19:53:30 -0000 @@ -139,7 +139,11 @@ testseq "a\0033#" " # a\r # #a \0010\001 # XXX ^[^[: complete # XXX ^X^[: complete-command -# XXX ^[^X: complete-file + +# ^[^X: complete-file +: >abc +testseq "ls \0033\0030" " # abc" + # XXX ^I, ^[=: complete-list # [n] ERASE, ^?, ^H: delete-char-backward Index: subr.sh =================================================================== RCS file: /cvs/src/regress/bin/ksh/edit/subr.sh,v retrieving revision 1.8 diff -u -p -r1.8 subr.sh --- subr.sh 21 Nov 2017 19:25:46 -0000 1.8 +++ subr.sh 10 Nov 2020 19:53:30 -0000 @@ -18,7 +18,7 @@ testseq() { stdin=$1 exp=$(echo "$2") - act=$(echo -n "$stdin" | ./edit -p "$PS1" ${KSH:-/bin/ksh} -r 2>&1) + act=$(echo -n "$stdin" | "$EDIT" -p "$PS1" ${KSH:-/bin/ksh} -r 2>&1) [ $? = 0 ] && [ "$exp" = "$act" ] && return 0 dump input "$stdin" @@ -32,3 +32,9 @@ dump() { printf '%s:\n>>>%s<<<\n' "$1" "$(echo -n "$2" | vis -ol)" echo -n "$2" | hexdump -Cv } + +EDIT="${PWD}/edit" + +TMP="$(mktemp -dt ksh.XXXXXX)" +trap 'rm -r $TMP' EXIT +cd "$TMP"