zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@pwstephenson.fsnet.co.uk>
To: zsh-workers@sunsite.auc.dk (Zsh hackers list)
Subject: Re: Calculator function
Date: Sat, 28 Jul 2001 00:17:17 +0100	[thread overview]
Message-ID: <20010727231722.0CCAA14291@pwstephenson.fsnet.co.uk> (raw)
In-Reply-To: ""Bart Schaefer""'s message of "Fri, 27 Jul 2001 12:10:30 PDT." <010727121030.ZM24973@candle.brasslantern.com>

"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 <pws@pwstephenson.fsnet.co.uk>
Work: pws@csr.com
Web: http://www.pwstephenson.fsnet.co.uk


  reply	other threads:[~2001-07-27 22:14 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-07-27 10:59 Peter Stephenson
2001-07-27 19:10 ` Bart Schaefer
2001-07-27 23:17   ` Peter Stephenson [this message]
2001-07-27 23:26     ` Bart Schaefer
2001-07-29 21:52       ` Peter Stephenson
2001-07-30  0:58         ` Bart Schaefer
2001-07-30  9:47           ` 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=20010727231722.0CCAA14291@pwstephenson.fsnet.co.uk \
    --to=pws@pwstephenson.fsnet.co.uk \
    --cc=zsh-workers@sunsite.auc.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).