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

Re: zcalc bug



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@xxxxxxx>                  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
**********************************************************************



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