mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-10-23 04:30:24 +02:00
* 16310: Functions/Misc/zcalc, Doc/Zsh/contrib.yo: separate zcalc
history, handle errors in expression, document -#base option.
This commit is contained in:
parent
960a7e5347
commit
64b4bfe6fc
3 changed files with 32 additions and 2 deletions
|
@ -1,5 +1,8 @@
|
||||||
2001-12-07 Peter Stephenson <pws@csr.com>
|
2001-12-07 Peter Stephenson <pws@csr.com>
|
||||||
|
|
||||||
|
* 16310: Functions/Misc/zcalc, Doc/Zsh/contrib.yo: separate zcalc
|
||||||
|
history, handle errors in expression, document -#base option.
|
||||||
|
|
||||||
* users/4503: Completion/Unix/Command/_gcc: don't complete source
|
* users/4503: Completion/Unix/Command/_gcc: don't complete source
|
||||||
or header files after -o.
|
or header files after -o.
|
||||||
|
|
||||||
|
|
|
@ -828,8 +828,9 @@ Each line typed is evaluated as an expression. The prompt shows a number,
|
||||||
which corresponds to a positional parameter where the result of that
|
which corresponds to a positional parameter where the result of that
|
||||||
calculation is stored. For example, the result of the calculation on the
|
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
|
line preceeded by `tt(4> )' is available as tt($4). Full command line
|
||||||
editing, including the history of previous calculations, is available.
|
editing, including the history of previous calculations, is available; the
|
||||||
To exit, enter a blank line or type `tt(q)' on its own.
|
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
|
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
|
first few positional parameters. A visual indication of this is given when
|
||||||
|
@ -845,6 +846,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.
|
the given base. Bases themselves are always specified in decimal.
|
||||||
`tt([#])' restores the normal output format.
|
`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
|
The prompt is configurable via the parameter tt(ZCALCPROMPT), which
|
||||||
undergoes standard prompt expansion. The index of the current entry is
|
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
|
stored locally in the first element of the array tt(psvar), which can be
|
||||||
|
|
|
@ -88,6 +88,25 @@
|
||||||
emulate -L zsh
|
emulate -L zsh
|
||||||
setopt extendedglob
|
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
|
local line latest base defbase match mbegin mend psvar optlist opt arg
|
||||||
integer num
|
integer num
|
||||||
|
|
||||||
|
@ -172,7 +191,10 @@ while vared -cehp "${(%)ZCALCPROMPT}" line; do
|
||||||
#
|
#
|
||||||
# Since it's a string, we'd better make sure we know which
|
# 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.
|
# base it's in, so don't change that until we actually print it.
|
||||||
|
latest=
|
||||||
eval "latest=\$(( $line ))"
|
eval "latest=\$(( $line ))"
|
||||||
|
# on error $latest is not set; let user re-edit line
|
||||||
|
[[ -n $latest ]] || continue
|
||||||
argv[num++]=$latest
|
argv[num++]=$latest
|
||||||
psvar[1]=$num
|
psvar[1]=$num
|
||||||
if [[ -z $base ]]; then
|
if [[ -z $base ]]; then
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue