From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29100 invoked from network); 7 Dec 2001 12:52:57 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 7 Dec 2001 12:52:57 -0000 Received: (qmail 13452 invoked by alias); 7 Dec 2001 12:52:51 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 16310 Received: (qmail 13437 invoked from network); 7 Dec 2001 12:52:50 -0000 To: zsh-workers@sunsite.dk (Zsh hackers list) Subject: PATCH: zcalc update Date: Fri, 07 Dec 2001 12:52:17 +0000 Message-ID: <20032.1007729537@csr.com> From: Peter Stephenson Bits I've had lying around: implement the history as suggested by Bart, fix a problem that an error in the evaluation would abort the function (and possibly leave you with ~/.zcalc_history as the history file), and document the -#base option. Index: Doc/Zsh/contrib.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/contrib.yo,v retrieving revision 1.16 diff -u -r1.16 contrib.yo --- Doc/Zsh/contrib.yo 2001/09/21 02:40:38 1.16 +++ Doc/Zsh/contrib.yo 2001/12/07 12:49:39 @@ -828,8 +828,9 @@ which corresponds to a positional parameter where the result of that calculation is stored. For example, the result of the calculation on the line preceeded by `tt(4> )' is available as tt($4). Full command line -editing, including the history of previous calculations, is available. -To exit, enter a blank line or type `tt(q)' on its own. +editing, including the history of previous calculations, is available; the +history is saved in the file tt(~/.zcalc_history). To exit, enter a blank +line or type `tt(q)' on its own. If arguments are given to tt(zcalc) on start up, they are used to prime the first few positional parameters. A visual indication of this is given when @@ -844,6 +845,10 @@ indication of the base, or `tt([##16])' just to display the raw number in the given base. Bases themselves are always specified in decimal. `tt([#])' restores the normal output format. + +The output base can be initialised by passing the option `tt(-#)var(base)', +for example `tt(zcalc -#16)' (the `tt(#)' may have to be quoted, depending +on the globbing options set). The prompt is configurable via the parameter tt(ZCALCPROMPT), which undergoes standard prompt expansion. The index of the current entry is Index: Functions/Misc/zcalc =================================================================== RCS file: /cvsroot/zsh/zsh/Functions/Misc/zcalc,v retrieving revision 1.5 diff -u -r1.5 zcalc --- Functions/Misc/zcalc 2001/11/15 18:42:33 1.5 +++ Functions/Misc/zcalc 2001/12/07 12:49:39 @@ -88,6 +88,25 @@ emulate -L zsh setopt extendedglob +# can't be local since required in EXIT trap +zcalc_orighist=$HISTFILE +local temphist=${TMPPREFIX}hist SAVEHIST=$HISTSIZE +HISTFILE=$temphist +fc -W + +local HISTSIZE=0 +HISTSIZE=$SAVEHIST +HISTFILE=~/.zcalc_history +[[ -f $HISTFILE ]] && fc -R + +zcalc_restore() { + unfunction zcalc_restore + fc -W + HISTFILE=$zcalc_orighist + fc -R +} +trap zcalc_restore HUP INT QUIT EXIT + local line latest base defbase match mbegin mend psvar optlist opt arg integer num @@ -172,7 +191,10 @@ # # Since it's a string, we'd better make sure we know which # base it's in, so don't change that until we actually print it. + latest= eval "latest=\$(( $line ))" + # on error $latest is not set; let user re-edit line + [[ -n $latest ]] || continue argv[num++]=$latest psvar[1]=$num if [[ -z $base ]]; then -- Peter Stephenson Software Engineer CSR Ltd., Science Park, Milton Road, Cambridge, CB4 0WH, UK Tel: +44 (0)1223 392070 ********************************************************************** The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer. **********************************************************************