From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13415 invoked from network); 27 Jul 2001 22:14:09 -0000 Received: from sunsite.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 27 Jul 2001 22:14:09 -0000 Received: (qmail 18817 invoked by alias); 27 Jul 2001 22:14:02 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 15511 Received: (qmail 18797 invoked from network); 27 Jul 2001 22:14:01 -0000 To: zsh-workers@sunsite.auc.dk (Zsh hackers list) Subject: Re: Calculator function In-reply-to: ""Bart Schaefer""'s message of "Fri, 27 Jul 2001 12:10:30 PDT." <010727121030.ZM24973@candle.brasslantern.com> Date: Sat, 28 Jul 2001 00:17:17 +0100 From: Peter Stephenson Message-Id: <20010727231722.0CCAA14291@pwstephenson.fsnet.co.uk> "Bart Schaefer" wrote: > > +Each line typed is evaluated as an expression. The prompt shows a number, > > +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). > > Why not have the prompt look like `$4= ' instead of `4> '? Probably not having thought of it. But possibly because I wanted it to look a prompt, since it prefixes the formula rather than the result. It can be made configurable with some psvar trickery. See patch. (This should really be expanded so that the same prompt is used to show parameters passed on the command line, which I haven't done yet.) > > +# Line editing and history are available. A blank line or `q' quits. > > Hrm, I'd rather that blank lines were just ignored ... I think ... I didn't like the idea that `q' didn't just show the variable $q, however (despite the double negative). It's a good idea to make ^D end of file --- the option -e to vared handles this properly, so I've added that. Maybe I can delete both the q and the empty line thing. > > +# To do: > > +# - separate zcalc history from shell history using arrays --- or allow > > +# zsh to switch internally to and from array-based history. > > I posted a function some while back that switches history contexts by > dumping the history to a file, then zeroing and restoring HISTSIZE. I > can't seem to track it down just now ... there's something sort of like > it in zsh-users/3506. > > What were you thinking of, here? That function would probably be exactly what was needed. The other proposal was that instead of using an invisible internal list manipulated by the history code, the shell code would use an array variable containing the lines and perhaps an index variable. Zle would manipulate the index to reflect the history setting, (or we could find another way of doing this) but the function would be responsible for any changes to the array and all the household management done in the usual case by the history options Index: Functions/Misc/zcalc =================================================================== RCS file: /cvsroot/zsh/zsh/Functions/Misc/zcalc,v retrieving revision 1.1 diff -u -r1.1 zcalc --- Functions/Misc/zcalc 2001/07/27 11:34:46 1.1 +++ Functions/Misc/zcalc 2001/07/27 22:10:18 @@ -84,11 +84,13 @@ emulate -L zsh setopt extendedglob -local line latest base defbase match mbegin mend +local line latest base defbase match mbegin mend psvar integer num zmodload -i zsh/mathfunc 2>/dev/null +: ${ZCALCPROMPT="%1v> "} + # Supply some constants. float PI E (( PI = 4 * atan(1), E = exp(1) )) @@ -101,7 +103,8 @@ print "$num> $argv[$num]" done -while vared -chp "$num> " line; do +psvar[1]=$num +while vared -cehp "${(%)ZCALCPROMPT}" line; do [[ -z $line ]] && break # special cases # Set default base if `[#16]' or `[##16]' etc. on its own. @@ -134,6 +137,7 @@ # arrays always store scalars anyway. eval "latest=\$(( $base $line ))" argv[num++]=$latest + psvar[1]=$num print -- $latest fi line= Index: Doc/Zsh/contrib.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/contrib.yo,v retrieving revision 1.13 diff -u -r1.13 contrib.yo --- Doc/Zsh/contrib.yo 2001/07/27 11:34:46 1.13 +++ Doc/Zsh/contrib.yo 2001/07/27 22:10:23 @@ -820,6 +820,12 @@ the given base. Bases themselves are always specified in decimal. `tt([#])' restores the normal output format. +The prompt is configurable via the parameter tt(ZCALCPROMPT), which +undergoes standard prompt expansion. The index of the current entry is +stored locally in the first element of the array tt(psvar), which can be +referred to in tt(ZCALCPROMPT) as `tt(%1v)'. The default prompt is +`tt(%1v> )'. + See the comments in the function for a few extra tips. ) findex(zed) -- Peter Stephenson Work: pws@csr.com Web: http://www.pwstephenson.fsnet.co.uk