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

Re: Conditionally complete on space.

Grant Taylor wrote on Thu, 17 Aug 2017 16:34 -0600:
> Thus I want to conditionally complete if there is not a space proceeding 
> the cursor's current position.  If there is a space proceeding the 
> cursor, then put a space and not call expand-or-complete.

Define a custom widget:

    maybe-complete-on-space() {
      if [[ $LBUFFER[-1] == ' ' ]]; then
        zle self-insert
        zle expand-or-complete
    zle -N maybe-complete-on-space

and bind it:

    bindkey ' ' maybe-complete-on-space

This implements the behaviour you specified, but I suspect you meant the
'if' and the 'else' behaviours to be the other way around.

> I am guessing that I will need to modify expand-or-complete's behavior 
> via modifying _main_complete, or wrap _main_complete with something else 
> to do the conditional logic and then call _main_complete, and update zle 
> so that expand-or-complete calls the wrapper instead of _main_complete.

You aren't changing the behaviour of completion, you are just changing
the method of invoking it, so the solution was in zshzle(1)'s domain,
not in zshcompsys(1)'s.



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