From 26694406f22f0fe37d0b751066200bf0cfdec165 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Tue, 5 Mar 2013 20:06:59 +0000 Subject: users/17666: zcalc -f sets FORCE_FLOAT --- Functions/Misc/zcalc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'Functions/Misc/zcalc') diff --git a/Functions/Misc/zcalc b/Functions/Misc/zcalc index 2d0cf5d40..3d44f20db 100644 --- a/Functions/Misc/zcalc +++ b/Functions/Misc/zcalc @@ -114,7 +114,7 @@ float PI E (( PI = 4 * atan(1), E = exp(1) )) # Process command line -while [[ -n $1 && $1 = -(|[#-]*) ]]; do +while [[ -n $1 && $1 = -(|[#-]*|f) ]]; do optlist=${1[2,-1]} shift [[ $optlist = (|-) ]] && break @@ -139,6 +139,9 @@ while [[ -n $1 && $1 = -(|[#-]*) ]]; do fi defbase="[#${arg}]" ;; + (f) # Force floating point operation + setopt forcefloat + ;; esac done done -- cgit v1.2.3 From 136cc1e1b79ebc07f5deb630fea9d325276d077c Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Fri, 15 Mar 2013 20:15:10 +0000 Subject: 31154: make zcalc understand continuation lines with a backslash --- ChangeLog | 7 ++++++- Doc/Zsh/contrib.yo | 7 ++++++- Functions/Misc/zcalc | 12 +++++++++++- 3 files changed, 23 insertions(+), 3 deletions(-) (limited to 'Functions/Misc/zcalc') diff --git a/ChangeLog b/ChangeLog index 06751df8b..4a56f1503 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2013-03-15 Peter Stephenson + + * 31154: Doc/Zsh/contrib.yo, Functions/Misc/zcalc: make zcalc + understand continuation lines using backslash. + 2013-03-14 Peter Stephenson * 31151: Pavol Juhas: complete (C etc) tags better @@ -603,5 +608,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5821 $ +* $Revision: 1.5822 $ ***************************************************** diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index 227914105..f13aa79cf 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -3144,7 +3144,12 @@ 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). +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. 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 diff --git a/Functions/Misc/zcalc b/Functions/Misc/zcalc index 3d44f20db..d78c35ed2 100644 --- a/Functions/Misc/zcalc +++ b/Functions/Misc/zcalc @@ -155,7 +155,17 @@ for (( num = 1; num <= $#; num++ )); do done psvar[1]=$num -while vared -cehp "${ZCALCPROMPT}" line; do +local prev_line cont_prompt +while vared -cehp "${cont_prompt}${ZCALCPROMPT}" line; do + if [[ $line = (|*[^\\])('\\')#'\' ]]; then + prev_line+=$line[1,-2] + cont_prompt="..." + line= + continue + fi + line="$prev_line$line" + prev_line= + cont_prompt= [[ -z $line ]] && break # special cases # Set default base if `[#16]' or `[##16]' etc. on its own. -- cgit v1.2.3 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(-) (limited to 'Functions/Misc/zcalc') 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 v1.2.3