Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Adding the original string from completion

A good few completers can insert the original string as a match
allowing the user to easily get back to what they typed first. 
Typically, this is done with a line looking like this:

compadd "$expl[@]" -U -Q - "$PREFIX$SUFFIX"

When called from _prefix, the result is that the suffix is lost.

The fix is to change the line to:

compadd "$expl[@]" -i "$IPREFIX" -I "$ISUFFIX" -U -Q - "$PREFIX$SUFFIX"

Only problem is if _prefix's add-space style is set. It sticks an
additional space at the beginning of ISUFFIX. That space is then
inserted after the cursor. That's still better than loosing the suffix
so I will do this change as a minimum. Adding $words[CURRENT], which is
unchanged, as the match looses the cursor position so that isn't much

The hack round this is to use something like:
  local isuf=${words[CURRENT][1+${#:-$QIPREFIX$IPREFIX$PREFIX$SUFFIX},-1]}
  compadd "$expl[@]" -I "$isuf" -Q -U -S '' - "$IPREFIX$PREFIX$SUFFIX"

Though that needs a bit more tweaking to cope with all forms of

This amounts to trusting $words[CURRENT] to be unchanged instead of
$ISUFFIX. If we do this, I'm inclined to factor it out into an new
_original function though. Anyone got any better ideas? Does that hack
seem reasonable?

_ignored is actually not using -Q or -U so it can end up quoting the
original string too. So that needs fixing.

There is also the option of only adding original strings at the end from
_main_complete. Given certain styles and whether menu completion if
enabled that is.


Messages sorted by: Reverse Date, Date, Thread, Author