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

Re: "{ } always { }" construct and return in called functions



On Wed, May 13, 2015 at 4:59 PM, Peter Stephenson
<p.stephenson@xxxxxxxxxxx> wrote:
> On Wed, 13 May 2015 14:31:41 +0200
> ia0 <zsh@xxxxxx> wrote:
>> There is something I don't understand with the "{ } always { }" construct.
>> What is the difference between the two following runs? I would expect the
>> last run to behave as the first one. What am I missing here?
>>
>> *% zsh --version*
>> zsh 5.0.2 (x86_64-pc-linux-gnu)
>> *% cat test*
>> #!/bin/zsh
>>
>> mytrue() { return 0 }
>> mywrap() { echo BEGIN; $1; echo END }
>> mytest() { { exit 1 } always { mywrap $1 } }
>>
>> mytest $1
>> *% ./test true*
>> BEGIN
>> END
>> *1% ./test mytrue*
>> BEGIN
>> *1% *
>
> Nested functions in always blocks with an exit pending are a corner case
> that needs fixing.  I'm not sure if this affects exit traps for
> functions, but possibly only in even weirder cases.
>
> Follow-ups can go to zsh-workers --- there are no user-serviceable
> parts inside.

This patch breaks my setup.

# Some hooks into accept-line
if [[ -n "$ZSHRUN" ]]; then
  unsetopt correct
  function _accept_and_quit() {
  local -a buf
  buf=(${(z)BUFFER})
  if which $buf[1] >& /dev/null; then
    zsh -c "${BUFFER}" &|
    exit
  else
    zle -M "Command $buf[1] not found"
  fi
  }
  zle -N _accept_and_quit
  bindkey "^M" _accept_and_quit
fi

With the patch, commands are randomly ran two or three times instead
of just once in the background. AFAIK there are no always blocks
involved in this part of my rc.

-- 
Mikael Magnusson



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