zsh-workers
 help / color / mirror / code / Atom feed
* Bug in function in function
@ 2022-05-19 19:34 Klaus Ethgen
  2022-05-20 15:37 ` Bart Schaefer
  0 siblings, 1 reply; 9+ messages in thread
From: Klaus Ethgen @ 2022-05-19 19:34 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 2034 bytes --]

Hi,

I had the following definition in my zshrc:
   rpg()
   {
      if whence rpg-cli >&-
      then
	 if ! functions cd >&-
	 then
	    cd()
	    {
	       CLICOLOR_FORCE=1 rpg-cli cd "$@" | sed -e 's/â\x96¡/o/g' -e 's/â\x9c\x94/ø/g' -e 's/\xf0\x9f\x92\x80/:-(/g' -e 's/\xf0\x9f\x93\xa6/\xa4/g' -e 's/\xf0\x9f\xaa\xa6/\xab/g' -e 's/\xe2\x9c\xa8/*/g' -e 's/\xf0\x9f\x94\xa5/\xbb\xab/g' -e 's/\xe2\x98\xa0\xef\xb8\x8f/\xa7/g'
	       builtin cd "$(rpg-cli pwd)"
	    }
	    ls()
	    {
	       command ls "$@"
	       if [ $# -eq 0 ]
	       then
		  CLICOLOR_FORCE=1 rpg-cli cd -f . | sed -e 's/â\x96¡/o/g' -e 's/â\x9c\x94/ø/g' -e 's/\xf0\x9f\x92\x80/:-(/g' -e 's/\xf0\x9f\x93\xa6/\xa4/g' -e 's/\xf0\x9f\xaa\xa6/\xab/g' -e 's/\xe2\x9c\xa8/*/g' -e 's/\xf0\x9f\x94\xa5/\xbb\xab/g' -e 's/\xe2\x98\xa0\xef\xb8\x8f/\xa7/g'
		  CLICOLOR_FORCE=1 rpg-cli ls | sed -e 's/â\x96¡/o/g' -e 's/â\x9c\x94/ø/g' -e 's/\xf0\x9f\x92\x80/:-(/g' -e 's/\xf0\x9f\x93\xa6/\xa4/g' -e 's/\xf0\x9f\xaa\xa6/\xab/g' -e 's/\xe2\x9c\xa8/*/g' -e 's/\xf0\x9f\x94\xa5/\xbb\xab/g' -e 's/\xe2\x98\xa0\xef\xb8\x8f/\xa7/g'
	       fi
	    }
	 fi
	 CLICOLOR_FORCE=1 rpg-cli "$@" | sed -e 's/â\x96¡/o/g' -e 's/â\x9c\x94/ø/g' -e 's/\xf0\x9f\x92\x80/:-(/g' -e 's/\xf0\x9f\x93\xa6/\xa4/g' -e 's/\xf0\x9f\xaa\xa6/\xab/g' -e 's/\xe2\x9c\xa8/*/g' -e 's/\xf0\x9f\x94\xa5/\xbb\xab/g' -e 's/\xe2\x98\xa0\xef\xb8\x8f/\xa7/g'
	 builtin cd "$(rpg-cli pwd)"
      else
	 echo "No rpg-cli installed"
	 return 1
      fi
   }

This was working fine until recent.

Now I get an error in the `ls()` line. It is even more strange that I
don't get an error when compiling it as zwc file!

Is there any recent that has changed?

My zsh is Version 5.9.

Please keep me in Cc as I am not registered to the list...

Regards
   Klaus
-- 
Klaus Ethgen                                       http://www.ethgen.ch/
pub  4096R/4E20AF1C 2011-05-16            Klaus Ethgen <Klaus@Ethgen.ch>
Fingerprint: 85D4 CA42 952C 949B 1753  62B3 79D0 B06F 4E20 AF1C

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 688 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Bug in function in function
  2022-05-19 19:34 Bug in function in function Klaus Ethgen
@ 2022-05-20 15:37 ` Bart Schaefer
  2022-05-20 17:12   ` Klaus Ethgen
  0 siblings, 1 reply; 9+ messages in thread
From: Bart Schaefer @ 2022-05-20 15:37 UTC (permalink / raw)
  To: Klaus Ethgen; +Cc: Zsh hackers list

On Thu, May 19, 2022 at 12:34 PM Klaus Ethgen <Klaus@ethgen.ch> wrote:
>
> Now I get an error in the `ls()` line. It is even more strange that I
> don't get an error when compiling it as zwc file!

What's the error?

The most obvious thing would be that zcompile isn't necessarily seeing
all the other setup in your init files.

> Is there any recent that has changed?

Quite a number of things, but you haven't told us enough yet to narrow it down.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Bug in function in function
  2022-05-20 15:37 ` Bart Schaefer
@ 2022-05-20 17:12   ` Klaus Ethgen
  2022-05-20 17:16     ` Mikael Magnusson
  0 siblings, 1 reply; 9+ messages in thread
From: Klaus Ethgen @ 2022-05-20 17:12 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh hackers list

[-- Attachment #1: Type: text/plain, Size: 975 bytes --]

Am Fr den 20. Mai 2022 um 16:37 schrieb Bart Schaefer:
> On Thu, May 19, 2022 at 12:34 PM Klaus Ethgen <Klaus@ethgen.ch> wrote:
> >
> > Now I get an error in the `ls()` line. It is even more strange that I
> > don't get an error when compiling it as zwc file!
> 
> What's the error?

/home/klaus/.zsh/zshrc/30_aliases:471: parse error near `()'

This is the line `ls()`. the first function definition (`cd()`) does
work. And when compiling, both work as expected.

I have an alias `alias ls="LC_COLLATE=POSIX ls $_ls_opts"` before this
line but that should not interfere the function definition.

> > Is there any recent that has changed?
> 
> Quite a number of things, but you haven't told us enough yet to narrow it down.

What do you need?

Regards
   Klaus
-- 
Klaus Ethgen                                       http://www.ethgen.ch/
pub  4096R/4E20AF1C 2011-05-16            Klaus Ethgen <Klaus@Ethgen.ch>
Fingerprint: 85D4 CA42 952C 949B 1753  62B3 79D0 B06F 4E20 AF1C

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 688 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Bug in function in function
  2022-05-20 17:12   ` Klaus Ethgen
@ 2022-05-20 17:16     ` Mikael Magnusson
  2022-05-20 17:25       ` Klaus Ethgen
  0 siblings, 1 reply; 9+ messages in thread
From: Mikael Magnusson @ 2022-05-20 17:16 UTC (permalink / raw)
  To: Klaus Ethgen; +Cc: Bart Schaefer, Zsh hackers list

On 5/20/22, Klaus Ethgen <Klaus@ethgen.ch> wrote:
> Am Fr den 20. Mai 2022 um 16:37 schrieb Bart Schaefer:
>> On Thu, May 19, 2022 at 12:34 PM Klaus Ethgen <Klaus@ethgen.ch> wrote:
>> >
>> > Now I get an error in the `ls()` line. It is even more strange that I
>> > don't get an error when compiling it as zwc file!
>>
>> What's the error?
>
> /home/klaus/.zsh/zshrc/30_aliases:471: parse error near `()'
>
> This is the line `ls()`. the first function definition (`cd()`) does
> work. And when compiling, both work as expected.
>
> I have an alias `alias ls="LC_COLLATE=POSIX ls $_ls_opts"` before this
> line but that should not interfere the function definition.

In fact it should, and it does. Change your function definition(s) to
the form "function ls".

-- 
Mikael Magnusson


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Bug in function in function
  2022-05-20 17:16     ` Mikael Magnusson
@ 2022-05-20 17:25       ` Klaus Ethgen
  2022-05-20 17:46         ` Peter Stephenson
  2022-05-20 17:47         ` Bart Schaefer
  0 siblings, 2 replies; 9+ messages in thread
From: Klaus Ethgen @ 2022-05-20 17:25 UTC (permalink / raw)
  To: Mikael Magnusson; +Cc: Bart Schaefer, Zsh hackers list

[-- Attachment #1: Type: text/plain, Size: 1206 bytes --]

Am Fr den 20. Mai 2022 um 18:16 schrieb Mikael Magnusson:
> On 5/20/22, Klaus Ethgen <Klaus@ethgen.ch> wrote:
> > Am Fr den 20. Mai 2022 um 16:37 schrieb Bart Schaefer:
> >> On Thu, May 19, 2022 at 12:34 PM Klaus Ethgen <Klaus@ethgen.ch> wrote:
> >> >
> >> > Now I get an error in the `ls()` line. It is even more strange that I
> >> > don't get an error when compiling it as zwc file!
> >>
> >> What's the error?
> >
> > /home/klaus/.zsh/zshrc/30_aliases:471: parse error near `()'
> >
> > This is the line `ls()`. the first function definition (`cd()`) does
> > work. And when compiling, both work as expected.
> >
> > I have an alias `alias ls="LC_COLLATE=POSIX ls $_ls_opts"` before this
> > line but that should not interfere the function definition.
> 
> In fact it should, and it does. Change your function definition(s) to
> the form "function ls".

Putting a `function` in front of `ls()` work.

However, I was thinking, `function` (in that context) is deprecated.

Regards
   Klaus
-- 
Klaus Ethgen                                       http://www.ethgen.ch/
pub  4096R/4E20AF1C 2011-05-16            Klaus Ethgen <Klaus@Ethgen.ch>
Fingerprint: 85D4 CA42 952C 949B 1753  62B3 79D0 B06F 4E20 AF1C

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 688 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Bug in function in function
  2022-05-20 17:25       ` Klaus Ethgen
@ 2022-05-20 17:46         ` Peter Stephenson
  2022-05-20 17:47         ` Bart Schaefer
  1 sibling, 0 replies; 9+ messages in thread
From: Peter Stephenson @ 2022-05-20 17:46 UTC (permalink / raw)
  To: zsh-workers

On Fri, 2022-05-20 at 18:25 +0100, Klaus Ethgen wrote:
> Am Fr den 20. Mai 2022 um 18:16 schrieb Mikael Magnusson:
> > On 5/20/22, Klaus Ethgen <Klaus@ethgen.ch> wrote:
> > > I have an alias `alias ls="LC_COLLATE=POSIX ls $_ls_opts"` before this
> > > line but that should not interfere the function definition.
> > 
> > In fact it should, and it does. Change your function definition(s) to
> > the form "function ls".
> 
> Putting a `function` in front of `ls()` work.
> 
> However, I was thinking, `function` (in that context) is deprecated.

No, it's valid syntax and will remain so --- just avoid using both
function in front AND () afterwards.  This is indeed the recommended fix
for this case.  The point, in case it isn't already obvious, is that
alias expands everything in command position before it's even been
parsed --- so your "ls" has turned into something else on input before
the shell has even swallowed the ().  With the function keyword, the
following word is no longer in command position.

pws



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Bug in function in function
  2022-05-20 17:25       ` Klaus Ethgen
  2022-05-20 17:46         ` Peter Stephenson
@ 2022-05-20 17:47         ` Bart Schaefer
  2022-05-20 18:14           ` Klaus Ethgen
  1 sibling, 1 reply; 9+ messages in thread
From: Bart Schaefer @ 2022-05-20 17:47 UTC (permalink / raw)
  To: Klaus Ethgen; +Cc: Mikael Magnusson, Zsh hackers list

On Fri, May 20, 2022 at 10:25 AM Klaus Ethgen <Klaus@ethgen.ch> wrote:
>
> Am Fr den 20. Mai 2022 um 18:16 schrieb Mikael Magnusson:
> > On 5/20/22, Klaus Ethgen <Klaus@ethgen.ch> wrote:
> > >
> > > I have an alias `alias ls="LC_COLLATE=POSIX ls $_ls_opts"` before this
> > > line but that should not interfere the function definition.
> >
> > In fact it should, and it does.

I'm now curious whether this "worked" in a prior version of zsh?  That
is, how long have you had both the alias and the function definition?

> Putting a `function` in front of `ls()` work.
>
> However, I was thinking, `function` (in that context) is deprecated.

No ... in fact, since the introduction of the NO_MULTI_FUNC_DEF
option, using "function" there is there recommended way to create
several functions with identical bodies.

However, you don't need both the "function" keyword and the empty parens.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Bug in function in function
  2022-05-20 17:47         ` Bart Schaefer
@ 2022-05-20 18:14           ` Klaus Ethgen
  2022-05-20 18:36             ` Peter Stephenson
  0 siblings, 1 reply; 9+ messages in thread
From: Klaus Ethgen @ 2022-05-20 18:14 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Mikael Magnusson, Zsh hackers list

[-- Attachment #1: Type: text/plain, Size: 632 bytes --]

Hi,

Am Fr den 20. Mai 2022 um 18:47 schrieb Bart Schaefer:
> I'm now curious whether this "worked" in a prior version of zsh?  That
> is, how long have you had both the alias and the function definition?

I looked at my history and seen that it was there for 1½ moths. It
worked well for around 2 or 3 weeks and then an update killed it.

I really thought I had have it longer. :-)

Regards
   Klaus
-- 
Klaus Ethgen                                       http://www.ethgen.ch/
pub  4096R/4E20AF1C 2011-05-16            Klaus Ethgen <Klaus@Ethgen.ch>
Fingerprint: 85D4 CA42 952C 949B 1753  62B3 79D0 B06F 4E20 AF1C

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 688 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Bug in function in function
  2022-05-20 18:14           ` Klaus Ethgen
@ 2022-05-20 18:36             ` Peter Stephenson
  0 siblings, 0 replies; 9+ messages in thread
From: Peter Stephenson @ 2022-05-20 18:36 UTC (permalink / raw)
  To: zsh-workers

On Fri, 2022-05-20 at 19:14 +0100, Klaus Ethgen wrote:
> Am Fr den 20. Mai 2022 um 18:47 schrieb Bart Schaefer:
> > I'm now curious whether this "worked" in a prior version of zsh?  That
> > is, how long have you had both the alias and the function definition?
> 
> I looked at my history and seen that it was there for 1½ moths. It
> worked well for around 2 or 3 weeks and then an update killed it.
> 
> I really thought I had have it longer. :-)

Hmm, I suspect the resolution to the problem might well be that's it's
been lying around ready to go off (in the sense of a bomb), but didn't do
so until it was perturbed somehow.  For example, it might always have
been run from a compiled file until it needed recompiling, and you
never tried running it uncompiled with the alias in place until that
happened.  Or something like that.

pws



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-05-20 18:37 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-19 19:34 Bug in function in function Klaus Ethgen
2022-05-20 15:37 ` Bart Schaefer
2022-05-20 17:12   ` Klaus Ethgen
2022-05-20 17:16     ` Mikael Magnusson
2022-05-20 17:25       ` Klaus Ethgen
2022-05-20 17:46         ` Peter Stephenson
2022-05-20 17:47         ` Bart Schaefer
2022-05-20 18:14           ` Klaus Ethgen
2022-05-20 18:36             ` Peter Stephenson

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).