mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-09-21 16:21:37 +02:00
31155: minor extra zcalc features and documentation
This commit is contained in:
parent
136cc1e1b7
commit
ab8fe84a8c
3 changed files with 24 additions and 6 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
2013-03-17 Peter Stephenson <p.w.stephenson@ntlworld.com>
|
||||||
|
|
||||||
|
* 31155: Doc/Zsh/contrib.yo, Functions/Misc/zcalc: minor
|
||||||
|
extra zcalc features and documentation.
|
||||||
|
|
||||||
2013-03-15 Peter Stephenson <p.w.stephenson@ntlworld.com>
|
2013-03-15 Peter Stephenson <p.w.stephenson@ntlworld.com>
|
||||||
|
|
||||||
* 31154: Doc/Zsh/contrib.yo, Functions/Misc/zcalc: make zcalc
|
* 31154: Doc/Zsh/contrib.yo, Functions/Misc/zcalc: make zcalc
|
||||||
|
@ -608,5 +613,5 @@
|
||||||
|
|
||||||
*****************************************************
|
*****************************************************
|
||||||
* This is used by the shell to define $ZSH_PATCHLEVEL
|
* This is used by the shell to define $ZSH_PATCHLEVEL
|
||||||
* $Revision: 1.5822 $
|
* $Revision: 1.5823 $
|
||||||
*****************************************************
|
*****************************************************
|
||||||
|
|
|
@ -3144,12 +3144,14 @@ line preceded by `tt(4> )' is available as tt($4). The last value
|
||||||
calculated is available as tt(ans). Full command line editing, including
|
calculated is available as tt(ans). Full command line editing, including
|
||||||
the history of previous calculations, is available; the history is saved in
|
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)'
|
the file tt(~/.zcalc_history). To exit, enter a blank line or type `tt(:q)'
|
||||||
on its own (`tt(q)' is allowed for historical compatibility). A
|
on its own (`tt(q)' is allowed for historical compatibility).
|
||||||
line ending with a single backslash is treated in the same fashion
|
|
||||||
|
A line ending with a single backslash is treated in the same fashion
|
||||||
as it is in command line editing: the backslash is removed, the
|
as it is in command line editing: the backslash is removed, the
|
||||||
function prompts for more input (the prompt is preceded by `tt(...)'
|
function prompts for more input (the prompt is preceded by `tt(...)'
|
||||||
to indicate this), and the lines are combined into one to get the final
|
to indicate this), and the lines are combined into one to get the final
|
||||||
result.
|
result. In addition, if the input so far contains more open than
|
||||||
|
close parentheses tt(zcalc) will prompt for more input.
|
||||||
|
|
||||||
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
|
||||||
|
@ -3219,11 +3221,13 @@ scope.
|
||||||
)
|
)
|
||||||
item(tt(:function) var(name) [ var(body) ])(
|
item(tt(:function) var(name) [ var(body) ])(
|
||||||
Define a mathematical function or (with no var(body)) delete it.
|
Define a mathematical function or (with no var(body)) delete it.
|
||||||
|
tt(:function) may be abbreviated to tt(:func) or simply tt(:f).
|
||||||
|
The var(name) may contain the same characters as a shell function name.
|
||||||
The function is defined using tt(zmathfuncdef), see below.
|
The function is defined using tt(zmathfuncdef), see below.
|
||||||
|
|
||||||
Note that tt(zcalc) takes care of all quoting. Hence for example:
|
Note that tt(zcalc) takes care of all quoting. Hence for example:
|
||||||
|
|
||||||
example(function cube $1 * $1 * $1)
|
example(:f cube $1 * $1 * $1)
|
||||||
|
|
||||||
defines a function to cube the sole argument.
|
defines a function to cube the sole argument.
|
||||||
)
|
)
|
||||||
|
|
|
@ -166,6 +166,14 @@ while vared -cehp "${cont_prompt}${ZCALCPROMPT}" line; do
|
||||||
line="$prev_line$line"
|
line="$prev_line$line"
|
||||||
prev_line=
|
prev_line=
|
||||||
cont_prompt=
|
cont_prompt=
|
||||||
|
# Test whether there are as many open as close
|
||||||
|
# parentheses in the line so far.
|
||||||
|
if [[ ${#line//[^\(]} -gt ${#line//[^\)]} ]]; then
|
||||||
|
prev_line+=$line
|
||||||
|
cont_prompt="..."
|
||||||
|
line=
|
||||||
|
continue
|
||||||
|
fi
|
||||||
[[ -z $line ]] && break
|
[[ -z $line ]] && break
|
||||||
# special cases
|
# special cases
|
||||||
# Set default base if `[#16]' or `[##16]' etc. on its own.
|
# Set default base if `[#16]' or `[##16]' etc. on its own.
|
||||||
|
@ -178,6 +186,7 @@ while vared -cehp "${cont_prompt}${ZCALCPROMPT}" line; do
|
||||||
defbase=$match[1]
|
defbase=$match[1]
|
||||||
fi
|
fi
|
||||||
print -s -- $line
|
print -s -- $line
|
||||||
|
print -- $(( ${defbase} ans ))
|
||||||
line=
|
line=
|
||||||
continue
|
continue
|
||||||
else
|
else
|
||||||
|
@ -233,7 +242,7 @@ while vared -cehp "${cont_prompt}${ZCALCPROMPT}" line; do
|
||||||
continue
|
continue
|
||||||
;;
|
;;
|
||||||
|
|
||||||
((:|)function[[:blank:]]##(#b)([^[:blank:]]##)(|[[:blank:]]##([^[:blank:]]*)))
|
((function|:f(unc(tion|)|))[[:blank:]]##(#b)([^[:blank:]]##)(|[[:blank:]]##([^[:blank:]]*)))
|
||||||
zmathfuncdef $match[1] $match[3]
|
zmathfuncdef $match[1] $match[3]
|
||||||
line=
|
line=
|
||||||
continue
|
continue
|
||||||
|
|
Loading…
Reference in a new issue