att / ast

AST - AT&T Software Technology
Eclipse Public License 1.0
556 stars 152 forks source link

esc-\ won't complete after input (but tab will) #1320

Open jgtaylor opened 5 years ago

jgtaylor commented 5 years ago

Description of problem: Using set -o vi For file listing/completion using "tab completion" functions as expected - presents itemized list of files, you type in the number hit tab again and that file name is there.

ESC-\ will present you with the itemized list, however, typing in the item number is a dead end, and won't provide completion.

Ksh version: echo ${.sh.version} Version A 2020.0.0-alpha1-120-g31d2e3e7

How reproducible: very

Steps to reproduce:

  1. ls /tmp/
    1) systemd-private-608540e413214bbc8f3bbebb64ef9f85-bluetooth.service-ugb8RV/
    2) systemd-private-608540e413214bbc8f3bbebb64ef9f85-bolt.service-GVCMkQ/
    3) systemd-private-608540e413214bbc8f3bbebb64ef9f85-chronyd.service-GsAJpu/
    4) systemd-private-608540e413214bbc8f3bbebb64ef9f85-colord.service-MPbzou/
    5) systemd-private-608540e413214bbc8f3bbebb64ef9f85-dbus-broker.service-0Mta8c/
  2. type in a choice (1-5) and hit ESC-\ again
  3. note that it does nothing.

Actual results: remains in vi command mode

Expected results: add the name of the selected item to the command line

Additional info:

krader1961 commented 5 years ago

I see the same behavior with ksh93u+ (i.e., the ksh provided by my platform) and ksh93v- (i.e., the ksh before we switched the build system to Meson). I don't know if this is a bug or not but my primary concern is whether this is behavior that has changed since the last stable release (i.e., ksh93u+).

sneyx1234 commented 5 years ago

The procedure to select a number out of the menu is:

ESC-= ESC-<number> ESC-= 

The first ESC-= shows the menu ... the second ESC-= substitutes the selection into the input edit buffer.

<number> can be a sequence of <digits>.

The behavoir of ESC-backslash is defined in the documentation ? And ESC-= is documented.

A nice user experience is to use the numeric keypad and define in your session management system that the "NUM-LOCK" key send a ESC-= ... ... then the interaction is:

<NUM-LOCK> <number> <NUM-LOCK> 
krader1961 commented 5 years ago

@sneyx1234 That's not how that feature works. And you didn't answer my question about whether this works in the ksh93u+ release. From the man page:

              [count]=  If count is not specified, it generates the list of matching  com-
                        mands or file names as described above.  Otherwise, the word under
                        the cursor is replaced by the count item from  the  most  recently
                        generated  command  or file list.  If the cursor is not on a word,
                        it is inserted instead.

That feature works for me using the ksh93u+ release and the current master branch when I invoke it as documented above. It does not work in either ksh version using your directions to reproduce the problem.

sneyx1234 commented 5 years ago

From the manual (M is Meta ... which is ESC):

       M-=       If not preceded by a numeric parameter, it generates the list
                 of matching commands or file names as described above.   Oth-
                 erwise,  the  word  under  the cursor is replaced by the item
                 corresponding to the value of the numeric parameter from  the
                 most  recently generated command or file list.  If the cursor
                 is not on a word, it is inserted instead.

...

       M-digits  (Escape) Define numeric parameter, the digits are taken as  a
                 parameter  to  the  next command.  The commands that accept a
                 parameter are ^F, ^B, erase, ^C, ^D, ^K, ^R, ^P, ^N, ^], M-.,
                 M-^], M-_, M-=, M-b, M-c, M-d, M-f, M-h, M-l and M-^H.

Your citate is related to the Vi mode for repeating operations not the the expansion of the shell against the filesystem ... ... there is no deviation from ksh93u+ to current ksh2020.

krader1961 commented 5 years ago

@jgtaylor Does this work for you using the ksh93u+ binary included in your distro?

Note that the rendered man page says

    \         Command or file name completion as described above.

But the man page source says

.TP 10
.B \e
Command or file name completion as described above.
.RE

Notice the \e. That does imply that a backslash after pressing escape should perform file name completion. But that doesn't work for me using the last official ksh93u+ release, let alone the current code.

krader1961 commented 5 years ago

@sneyx1234 M-digits is only applicable in emacs mode.

sneyx1234 commented 5 years ago

Ok in emacs mode its ESC-= ESC-digits ESC-= and in vi mode its just = digits =.

krader1961 commented 5 years ago

@sneyx1234 👍 That is what I see in the documentation and in practice. But AFAICT [esc]\ does not behave the same as [esc]= using ksh93u+ (which is now 12 years old). It's interesting that the former is in the man page section headed "Text Modification Edit Commands" while the latter is in section "Other Edit Commands".

So this does appear to be broken in the last stable release. At least in so much as I interpret the problem report and official ksh man page. But both are somewhat confusing as to exactly how ESC-\ is meant to be used and behave.

jgtaylor commented 5 years ago

This is good to know - I hadn't known about the ESC-=, I've always just used ESC-. It still works for a single file (e.g. no other files could match). I no longer have access to the old AIX systems I used ksh93 (which if I remember correctly, IBM only shipped ksh93t+), so I can't confirm any past behavior. I'm guessing nothing has changed and I'm probably mis-remembering it. Either way, I'll start using esc-=.

On Mon, May 27, 2019 at 6:40 AM Kurtis Rader notifications@github.com wrote:

@sneyx1234 https://github.com/sneyx1234 👍 That is what I see in the documentation and in practice. But AFAICT [esc]\ does not behave the same as [esc]= using ksh93u+ (which is now 12 years old). It's interesting that the former is in the man page section headed "Text Modification Edit Commands" while the latter is in section "Other Edit Commands".

So this does appear to be broken in the last stable release. At least in so much as I interpret the problem report and official ksh man page. But both are somewhat confusing as to exactly how ESC-\ is meant to be used and behave.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/att/ast/issues/1320?email_source=notifications&email_token=ADAQWMF2UKCPNLF5QXEDHM3PXNQ4PA5CNFSM4HPV7ZE2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWIYBHA#issuecomment-496074908, or mute the thread https://github.com/notifications/unsubscribe-auth/ADAQWMBJTFSVYGEUW3EJEDLPXNQ4PANCNFSM4HPV7ZEQ .

sneyx1234 commented 5 years ago

Also good to know: ESC- expands to all matching files. Matching for ESC-= and ESC- is the "word" left to the current cursor position.

sneyx1234 commented 5 years ago

Even more to know is: If the cursor is left to variable reference a ESC-* did not expand against the filesystem it expands against the variable namespace :-) Don't press <ENTER> ... press ESC-* here:

# cd $PWD

Assume the cursor is behind the D of $PWD the ESC-* expands to the value of $PWD ... e.g. /tmp ... Thats not the final word what different object types can be expanded by ESC-* ... e.g. autoload functions names.

sneyx1234 commented 5 years ago

More magic with a menu list with partial prefix named variable out of the defined namespace. Assume you have some variable beginning with $H... ... so enter $H followed by ÈSC-= this time:

# cd $H
1) HCOM
2) HISTCMD
3) HISTEDIT
4) HISTFILE
5) HISTFILE_EVAR
6) HISTSIZE
7) HISTSIZE_EVAR
8) HOME

Of course can you choose from the menu with ESC-<number> ESC-= ... ... the idea behind all these magics is to interactive navigate within a grammar tree of a parser .

krader1961 commented 5 years ago

I'm leaving the "needs-more-info" label because I still do not understand how ESC-\ is meant to differ from ESC-=. Which means I can't tell if there is an implementation bug or the documentation merely needs clarification.

jgtaylor commented 5 years ago

This just confirms to me that ksch has always been impressive. I’ll have to go back and read my old ksh book again.

On Tue, 28 May 2019 at 07:02, Kurtis Rader notifications@github.com wrote:

I'm leaving the "needs-more-info" label because I still do not understand how ESC-\ is meant to differ from ESC-=. Which means I can't tell if there is an implementation bug or the documentation merely needs clarification.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/att/ast/issues/1320?email_source=notifications&email_token=ADAQWMEUELSK55UOOQCKBTDPXS4G7A5CNFSM4HPV7ZE2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWK7CFA#issuecomment-496365844, or mute the thread https://github.com/notifications/unsubscribe-auth/ADAQWMDCBF4JLZJ46HOFIEDPXS4G7ANCNFSM4HPV7ZEQ .