zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: zsh-workers@sunsite.dk
Subject: Re: zcalc bug
Date: Tue, 18 May 2004 12:28:46 +0100	[thread overview]
Message-ID: <8428.1084879726@csr.com> (raw)
In-Reply-To: "Wayne Davison"'s message of "Fri, 14 May 2004 17:22:17 PDT." <20040515002217.GE22331@blorf.net>

Wayne Davison wrote:
> OK, I created an initial implementation of this today (it was pretty
> easy, as I expected).  See if you like it.  It works in my limited
> testing (i.e. a modified zcalc works quite nicely), but I may have
> missed something.

Thanks.  Just got a chance to try this.  Seems fine, so far.

> > Do you think it's easy to keep the state of external files consistent
> > while you do that?
> 
> I'm not sure what you mean by this.  My code isn't doing anything with
> files, so the modified zcalc function still loads the .zcalc_history
> file with "fc -R" and its restore function writes it out with "fc -W".
> However, no fc calls are needed to save and restore the current history.

Well, it does seem to get the history numbers right when reading the
file back.

> It would be possible to change my current, very simple pushhist/pophist
> syntax to have pushhist optionally take some parameters to setup the new
> history environment, for instance:
> 
> pushhist 200 100 ~/.zcalc_history
> 
> would be just like this shell code:
> 
> pushhist
> HISTSIZE=200
> SAVEHIST=100
> HISTFILE=~/.zcalc_history
> [[ -f $HISTFILE ]] && fc -R
> 
> And the pophist function could likewise be changed to work like this:
> 
> [[ ! -z $HISTFILE && $SAVEHIST > 0 ]] && fc -W
> pophist

You're proposing that you would *only* need the pushhist and pophist
functions to manipulate the history?  That sounds a good thing to me.

Something else that occurs to me is that it would be useful to have the
history automatically popped when you leave the function scope.  That
saves a lot of messing on with traps, which will never be completely
safe.  However, there may be uses where you want to stay in an
alternative history between functions, though I can't think of any off
the top of my head, so I don't know if that's the right thing to do in
general.  It would certainly make zcalc simpler and more reliable.
(There are various mechanisms associated with function scoping, without
looking I'm not sure which would be the best here.)

I'm not sure a separate command is necessary; it could be a new
option to history (or both history and fc).

We could get essentially all the above with:

  history -p 200 100 ~/.zcalc_history

push the history as you suggested

  history -P

pop the history, saving the temporary $HISTFILE first and restoring
the original one

history -Lp 200 100 ~/.zcalc_history

  push the history for the current local scope, restoring it automatically
  when the function exits.

I could be persuaded to the view that the local behaviour is the right
one, so you never need an explicit pop, and the syntax becomes even
simpler.  That significantly reduces the likelihood of people getting
their history screwed up.

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 692070


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************


  reply	other threads:[~2004-05-18 11:29 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-05-11 12:17 Matthias Kopfermann
2004-05-13 14:04 ` Thomas Köhler
2004-05-13 14:57   ` Peter Stephenson
2004-05-13 15:19     ` Matthias Kopfermann
2004-05-13 15:58       ` Peter Stephenson
2004-05-13 17:29         ` Matthias Kopfermann
2004-05-13 17:47           ` Peter Stephenson
2004-05-13 18:06             ` Matthias Kopfermann
2004-05-13 20:05               ` Peter Stephenson
2004-05-13 20:03     ` Wayne Davison
2004-05-14  9:23       ` Peter Stephenson
2004-05-15  0:22         ` Wayne Davison
2004-05-18 11:28           ` Peter Stephenson [this message]
2004-05-18 19:50             ` [PATCH] local history support, take 2 Wayne Davison
2004-05-18 21:32               ` Wayne Davison
2004-05-19  9:40               ` Peter Stephenson
2004-05-19 16:58                 ` Wayne Davison
2004-05-19 21:37                   ` Peter Stephenson
2004-05-21  1:37                     ` Wayne Davison
2004-05-21  1:44                       ` Wayne Davison
2004-05-21  9:15                       ` Peter Stephenson
2004-05-21 20:06                         ` Wayne Davison

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=8428.1084879726@csr.com \
    --to=pws@csr.com \
    --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).