Tab-completion (expansion) and edlin_expand:expand/1,2,3

Hi,

It’s inconvenient because if you type Hello or world: he or Hello or world: wo and press tab the tab-completion stops working. Also, the input string gets into the function expand_fun() as a reversed string.

It might be inconvenient in your usecase, but for the shell its great, because then you always have the latest word (before the cursor) in the beginning of the string: “ow olleh”.

  1. If you want to set it back to the default expand function again you can do it like this io:setopts([{expand_fun, fun edlin_expand:expand/2}]),

The list of possible expansions can be formatted in different ways to make more advanced expansion suggestions more readable to the user,

This is something documented in the later paragraphs of expand/2, and basically makes it possible to format your suggestions:

   {no, "", "#{title := "*** Suggestions ***", elems := ["hello", "world"]}}
hello or world: he<tab>
*** Suggestions ***
hello            world
  1. Your second function above already solves your usecase.
  2. Bef0 is a bit cryptic, but it stand for Before, The text before the cursor (in reverse).
  3. We needed edlin_expand:expand/3 in a test suite, to set a custom shell state. It being undocumented means that it should not be used outside OTP.

Hope that helps, let me know if you have more questions!

3 Likes