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

Re: Zsh will not parse an autoload function when it has short loops



On Fri, Aug 28, 2015 at 8:39 AM, Sebastian Gniazdowski
<sgniazdowski@xxxxxxxxx> wrote:
> Hello
>
> I've created autoload function "bug" in /usr/share/zsh/.../functions, and
> when run, it gives:
>
> bug:9: parse error near `list[$i]'
>
> Adding echo's to the file and changing various things revealed no reaction.
> This means that the file isn't actually run by zsh - apparently the message
> comes from some initial parsing stage.
>
> Here is the file:
>
> emulate -L zsh
>
> setopt localoptions typesetsilent localtraps extendedglob shortloops
>
> while (( 1 )); do
>     # No influence, the code isn't run at all
>     # typeset -a VLIST_NONSELECTABLE_ELEMENTS
>     if [ ! -z "$VLIST_SEARCH_BUFFER" ]; then
>         [ "$#VLIST_NONSELECTABLE_ELEMENTS" -gt 0 ] && for i
> ("${(nO)VLIST_NONSELECTABLE_ELEMENTS[@]}") list[$i]=()
>     fi
>
> done

This is expected, the shortloops option affects parsing of files. As
you noticed the code is not run, only parsed, so therefore the setopt
shortloops inside the function has no effect, but you use shortloops
syntax which means it has to be on when you parse it. Long story
short: don't use shortloops syntax in portable code.

-- 
Mikael Magnusson



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