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 Aug 28,  8:43am, Mikael Magnusson wrote:
} Subject: Re: Zsh will not parse an autoload function when it has short loo
}
} 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]'
} 
} This is expected, the shortloops option affects parsing of files.

There's a straightforward workaround for this:  Instead of

    autoload shortloopfn

use

    emulate zsh -c 'autoload shortloopfn'

then zsh emulation scope will be in effect when the function is called,
and everything will parse as expected during loading.

However, it appears "autoload +X" does not respect the emulation options
put into effect at the time the function was originally marked for
autoloading.  I can't decide whether that is a bug.  The reason that the
"autoload -c" trick works is because the function ends up being defined
approximately as

    shortloopfn() {
       emulate zsh	# "sticky emulation"
       autoload -X shortloopfn
    }

so the emulation is restored before the load, and obviously this is not
equivalent to "autoload +X" run explicitly.

-- 
Barton E. Schaefer



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