zsh-workers
 help / color / mirror / code / Atom feed
From: Oliver Kiddle <okiddle@yahoo.co.uk>
To: zsh-workers@sunsite.dk (Zsh hackers list)
Subject: Re: PATCH: `try' syntax
Date: Mon, 14 Jun 2004 14:58:17 +0200	[thread overview]
Message-ID: <5284.1087217897@trentino.logica.co.uk> (raw)
In-Reply-To: <200406141123.i5EBNdoM012078@news01.csr.com>

Peter wrote:

> The basic idea is:
> 
>   :try
>      # Code here runs normally
>   :always
>      # Code here always gets run, even if there is a fatal
>      # error (unless it crashes the shell), or a return, break,
>      # or continue in the :try block.

What exactly do break, continue and return do here? Are they unchanged,
expecting an enclosing loop or function. It'd be really useful to have
a way to skip over the rest of the try block, going straight to the
always code. The best way to handle that would be to use break with the
try block appearing to be a loop. But we probably don't want break and
continue numbers to be out of sync so perhaps both should have that
effect.

Is it possible to put the command after try and always. e.g:
  :try do-stuff; :always rm $tempfile; :tried

>      #
>      # Optionally:
>      unset -e
>      # removes any error condition.  Apart from that, after exiting
>      # the always block, the logic is as if it hadn't been present.

What sort of things does an "error condition" encompass? Is it just
exit signals? It isn't clear without an example. It could be useful to
have something like the errexit and errreturn options apply within the
try block.

`unset -e' seems a bit obscure. Would an option to exit or return make
it clearer what is happening. Or how about using special variable which
indicates what the "error condition" is and have that be unset.

> The trickiest bit is the naming.  I wanted something reasonably
> memorable, but without polluting the name space, hence the names
> with the colons in front.  Note that `disable -r :try :always :tried'
> works.

The colons make them look like labels. You could avoid `tried' by using
`done' or, being consistent with esac and fi, use `yrt'. Another option
could be to use uppercase. Or could it go in a module?

We ought to fix completion to do something about colons in
command-names in the current context. What you see with:
: <Ctrl-x><h>
is not ideal.

Does this actually do anything which traps can't do? Can we perhaps
change something about traps to make them simpler to use. It doesn't
look quite as versatile, for example you can't setup timeout delays.

Oliver


  reply	other threads:[~2004-06-14 13:00 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-14 11:23 Peter Stephenson
2004-06-14 12:58 ` Oliver Kiddle [this message]
2004-06-14 13:52   ` Peter Stephenson
2004-06-14 16:55     ` Oliver Kiddle
2004-06-14 17:27       ` Peter Stephenson
2004-06-14 18:14       ` Bart Schaefer
2004-06-15 10:31         ` Oliver Kiddle
2004-06-15 10:51         ` DervishD
2004-06-15 13:33         ` Peter Stephenson
2004-06-15 20:21           ` Bart Schaefer
2004-06-16 14:33             ` Oliver Kiddle
2004-06-16 17:21               ` Bart Schaefer
2004-06-18 11:05                 ` PATCH: second go at `always' blocks Peter Stephenson

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=5284.1087217897@trentino.logica.co.uk \
    --to=okiddle@yahoo.co.uk \
    --cc=zsh-workers@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).