* Zsh will not parse an autoload function when it has short loops
@ 2015-08-28 6:39 Sebastian Gniazdowski
2015-08-28 6:43 ` Mikael Magnusson
0 siblings, 1 reply; 3+ messages in thread
From: Sebastian Gniazdowski @ 2015-08-28 6:39 UTC (permalink / raw)
To: zsh-workers
[-- Attachment #1: Type: text/plain, Size: 718 bytes --]
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Zsh will not parse an autoload function when it has short loops
2015-08-28 6:39 Zsh will not parse an autoload function when it has short loops Sebastian Gniazdowski
@ 2015-08-28 6:43 ` Mikael Magnusson
2015-08-28 16:29 ` Bart Schaefer
0 siblings, 1 reply; 3+ messages in thread
From: Mikael Magnusson @ 2015-08-28 6:43 UTC (permalink / raw)
To: Sebastian Gniazdowski; +Cc: zsh workers
On Fri, Aug 28, 2015 at 8:39 AM, Sebastian Gniazdowski
<sgniazdowski@gmail.com> 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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Zsh will not parse an autoload function when it has short loops
2015-08-28 6:43 ` Mikael Magnusson
@ 2015-08-28 16:29 ` Bart Schaefer
0 siblings, 0 replies; 3+ messages in thread
From: Bart Schaefer @ 2015-08-28 16:29 UTC (permalink / raw)
To: zsh workers; +Cc: Mikael Magnusson, Sebastian Gniazdowski
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@gmail.com> 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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-08-28 16:29 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-28 6:39 Zsh will not parse an autoload function when it has short loops Sebastian Gniazdowski
2015-08-28 6:43 ` Mikael Magnusson
2015-08-28 16:29 ` Bart Schaefer
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).