From ab8fe84a8c179f5990c4fd7cd7e2cfa82ed03cc3 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Sun, 17 Mar 2013 20:52:55 +0000 Subject: 31155: minor extra zcalc features and documentation --- ChangeLog | 7 ++++++- Doc/Zsh/contrib.yo | 12 ++++++++---- Functions/Misc/zcalc | 11 ++++++++++- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4a56f1503..8302b27cc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2013-03-17 Peter Stephenson + + * 31155: Doc/Zsh/contrib.yo, Functions/Misc/zcalc: minor + extra zcalc features and documentation. + 2013-03-15 Peter Stephenson * 31154: Doc/Zsh/contrib.yo, Functions/Misc/zcalc: make zcalc @@ -608,5 +613,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5822 $ +* $Revision: 1.5823 $ ***************************************************** diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index f13aa79cf..b191e10d9 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -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 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 (`tt(q)' is allowed for historical compatibility). A -line ending with a single backslash is treated in the same fashion +on its own (`tt(q)' is allowed for historical compatibility). + +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 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 -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 first few positional parameters. A visual indication of this is given when @@ -3219,11 +3221,13 @@ scope. ) item(tt(:function) var(name) [ var(body) ])( 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. 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. ) diff --git a/Functions/Misc/zcalc b/Functions/Misc/zcalc index d78c35ed2..e9dcc78b9 100644 --- a/Functions/Misc/zcalc +++ b/Functions/Misc/zcalc @@ -166,6 +166,14 @@ while vared -cehp "${cont_prompt}${ZCALCPROMPT}" line; do line="$prev_line$line" prev_line= 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 # special cases # 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] fi print -s -- $line + print -- $(( ${defbase} ans )) line= continue else @@ -233,7 +242,7 @@ while vared -cehp "${cont_prompt}${ZCALCPROMPT}" line; do continue ;; - ((:|)function[[:blank:]]##(#b)([^[:blank:]]##)(|[[:blank:]]##([^[:blank:]]*))) + ((function|:f(unc(tion|)|))[[:blank:]]##(#b)([^[:blank:]]##)(|[[:blank:]]##([^[:blank:]]*))) zmathfuncdef $match[1] $match[3] line= continue -- cgit 1.4.1