Skip to content

Programmable readline integration? #269

@jpco

Description

@jpco

Now that es script can be run while reading shell input, we should actually do that in $&readline.

The obvious candidates are programmable tab completion and arbitrary key bindings.

I played around with a simple version of tab completion in https://github.com/jpco/es-shell/blob/palloc/ (see completion.es and the completions directory). It's just a demo really, and doesn't have some nice features like good handling for GNU-style --foo=bar long opts, but at least one nice quality of it is that it really only has one hook function, %complete (or two, if you include %completion-to-file). This makes it so that completion functions can call each other, and can call the "root" %complete hook function, recursively, which is all pretty useful in a language like es where commands are often arguments to other commands.

For programmable tab completion in particular, it would be very good to make the es-written parts of tab completion suitable for use with different line editing libraries. I know that a lot of people are, reasonably, not fond of readline, but it's entire heap of work to create a tab-completion "library", so designing tab-completion to work with readline alternatives would be a virtue.

One of the big pitfalls of the tab-completion demo above is that it's not really syntax-aware. For example, suppose you have a function in which takes a directory and a command and cds to that directory just for the duration of executing the command. The following should all have the same completion behavior:

; in ~ ls .[TAB]
; in ~ (ls .[TAB]
; in ~ {ls .[TAB]
; in ~ { ls .[TAB]

Resolving that shortcoming "completely" would probably be hard, requiring a new, incremental parser and some kind of good user-facing design for iterating through a half-written command. I'm not convinced that a syntactically-aware solution should be a requirement to design and implement before getting, say, the ability to tab-complete words in first-position.

If anybody has more ideas for programmable interactive integration, I'm all ears. I'm going to play around with this for a while before proposing anything in particular.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions