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

Re: Lazy loading completions



On Apr 18,  7:53pm, Nicholas Riley wrote:
} 
} In article 
} <130418163739.ZM8718__6202.1464844749$1366328467$gmane$org@torch.brassla
} ntern.com>,
}  Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
} > In fact, someone should suggest to Doug Hellmann that he stop using
} > compctl commands in virtualenvwrapper.sh ... compctl won't work at all
} > for someone using compinit unless they've configured it to fall through
} > to old-style completions when no modern completion is found.
} 
} Huh, sounds like it's worth a bug report.  I don't have any mention of 
} compctl in my compinit but maybe I got lucky.

I forgot that it automatically kicks in if you have the zsh/compctl
module loaded, which has to autoload in order for the compctl command to
work, so by calling compctl Doug is setting up the necessary conditions.

However, someone could have
    zstyle ':completion:*' use-compctl no
in their startup, which would break things.  I guess actually that's
less likely to be present than compinit is to be missing, so if he's
going to have minimal dependencies he's made the best choice he could.

} > }     source /usr/local/bin/virtualenvwrapper_lazy.sh
} > }     _virtualenvwrapper_load_compctl() {
} > }       compctl + ${=_VIRTUALENVWRAPPER_API}
} > }       virtualenvwrapper_load
} > }       eval ${$(compctl | egrep '^'$_comp_command1' -K')[3]}
} > }     }
} > 
} > ??  Where is the value of $_comp_command1 coming from here?
} 
} It's being set by the completion system, I guess.

Indeed, it's "leaking" down from _normal.  If you try to make this work
you probably want $_comp_commmand here, in some cases $_comp_command1
will be a full path.

If you want to stick with Doug's approach and avoid reliance on compsys
entirely, use

  local command_name
  local -a command_args
  read -c command_name command_args

} Works great, thanks, though I now need to move the above to below where 
} I call compinit; that may break a lot of users of virtualenvwrapper.

There's no evaluable function that's equivalent to "compctl -D" and no
way to call one compctl from another (both of these are among reasons
that compsys was invented in the first place), so you're sort of stuck.
You might be able to fake it with:

  # Note, no leading underscore, so $1 and $2 will be set
  virtualenvwrapper_load_compctl() {
    local command_name
    local -a command_args
    read -c command_name command_args
    compctl + ${=_VIRTUALENVWRAPPER_API}
    virtualenvwrapper_load
    local loaded_compctl=${$(compctl | egrep '^'$command_name' -K')[3]}
    if [[ -n $loaded_compctl ]]
    then eval $loaded_compctl
    else reply=( $1*$2(N) ) # Pretend to do file completion
    fi
  }
  compctl -K virtualenvwrapper_load_compctl ${=_VIRTUALENVWRAPPER_API}



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