zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-users@sunsite.dk
Subject: Re: localtraps
Date: Wed, 27 Apr 2005 05:59:07 +0000	[thread overview]
Message-ID: <1050427055907.ZM28766@candle.brasslantern.com> (raw)
In-Reply-To: <20050426221247.GA3964@quark.hightek.org>

On Apr 26,  5:12pm, Vincent Stemen wrote:
}
} One thing I tried was to set a flag indicating that the signal had
} already hit once so that when it re-calls the sig handler it would
} know it was the second time.  That did not work though for the same
} reason.  I cannot reset the flag before exiting the function because
} it always completes the function before processing the next signal and
} re-calling it.  So on the next signal, the flag is always back unset.

This should work with a sufficiently recent version of zsh to have the
"always" construct:

    inner () {
	if ((trips++))
	then
	  {
	    print "Do the multiple-trip thing ..."
	  } always {
	    ((--trips))
	  }
	fi
    }

    outer () {
      {
	setopt localoptions nolocaltraps
	integer -g trips=1
	trap inner INT
	print "Doing something useful now ..."
	sleep 2
      } always {
	unset trips
	trap outer INT
      }
    }
    trap outer INT

With that, even if I press ^C and hold it down, it alternates between
"Doing something useful now ..." and "Do the multiple-trip thing ..."
and ends up with "trips" unset.  Of course, this is on Linux; if you
are right about the NetBSD signal behavior, you'll need something more
subtle.


  reply	other threads:[~2005-04-27  5:59 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-04-25  6:35 localtraps Vincent Stemen
2005-04-25 16:32 ` localtraps Bart Schaefer
2005-04-26  0:50   ` localtraps Vincent Stemen
2005-04-26  3:03   ` localtraps Vincent Stemen
2005-04-26 18:34     ` localtraps Peter Stephenson
2005-04-26 22:12       ` localtraps Vincent Stemen
2005-04-27  5:59         ` Bart Schaefer [this message]
2005-04-28  1:00           ` localtraps Vincent Stemen
2005-04-28  8:20             ` localtraps Bart Schaefer
2005-04-27  5:36       ` localtraps Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1050427055907.ZM28766@candle.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-users@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).