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

PATCH: _insert_all_matches bindable command



[Moved to zsh-workers]

> }
> } Well, in fact, I never do this with rmdir. [...]
> } I really use this with cvs add and cvs rm where it is great.
>
> So you have it restricted by style to :completion::complete:cvs* or
> something like that?  I could see where that would be useful, but I
> wouldn't want it in context :completion:* ...
>

Yes, exactly. It is very unlikely that somebody would like to *always* insert
all matches even for any particular command. For this reason I also never used
_expand *completer*. Trying expansion on every completion just seems too
general. (There is one more reason - IMHO expansion is context-independent
operation while normal completion is highly context-dependent. You just cannot
mix both).

For this reason here the proposed patch, that adds _insert_all_matches widget
bound to ^Xi. It can be used after any completion and standalone. It will
reuse existing list if available (controlled by old-list style, like in
_oldlist completer). Called standalone it will call normal completion and
insert all generated matches.

Some comments:

- it will reuse any exisitng list even if it's not appropriate. E.g. in case
of correction original word is listed as possible match, so ^Xi will insert it
as well. Another similar case is _expand. But in case of _expand you already
have the choice to insert all expansions.

- I could not find a way to supress suffix addition. It is weird as it is
added only to the last match anyway. Sven?

- it does not work inside of menu selection, because it accepts selected match
and clears list even before calling any widget. It does work in menu
completion. Sven will have the final word, but, may be, menu selection should
not accept the match and clear list at least for completion widgets. Also,
there is subtle difference between menu completion and menu selection - menu
selection adds space where menu completion does not. E.g.:

bor@itsrm2% l f*
fOo   foO   foo

(selection)

bor@itsrm2% l fOo
Completing file
fOo   foO   foo
(press `i')
bor@itsrm2% l fOo i
Completing file
fOo   foO   foo

(completion)

bor@itsrm2% ls fOo
Completing file
fOo   foO   foo
(press `i')
bor@itsrm2% ls fOoi
Completing file
fOo   foO   foo

I would really prefer the same behaviour in both cases.

Jay, would it be useful to you?

-andrej

sourceforge CVS server is down, so I just send the function itself (without
manual update). Coments?

====== cut here ======
#compdef -K _insert_all_matches complete-word \C-xi

setopt localoptions nullglob rcexpandparam extendedglob noshglob
unsetopt markdirs globsubst shwordsplit nounset ksharrays

local oldcurcontext="$curcontext" list ret

if [[ -z "$oldcurcontext" ]]; then
  curcontext="insert-all-matches:::"
else
  curcontext="insert-all-matches:${oldcurcontext#*:}"
fi

zstyle -s ":completion:${curcontext}:" old-list list

# If there is already an old list,
# and either the style :insert-all-matches:old-list is `always',
# or it is not `never', then insert the existing list
# (even if it was generated by another widget).
# Else just call completion and insert whatever matches it generated
# TODO: does not work in menu selection


if [[ -n $compstate[old_list] && $list != never &&
      $LASTWIDGET != _complete_help && $WIDGET != _complete_help ]]; then
    compstate[old_list]=keep
    compstate[insert]=all
    return 0
else
    curcontext="$oldcurcontext"
    _main_complete
    ret=$?
    compstate[insert]=all
    return $ret
fi



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