Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: PATCH: Make zcalc understand continuation lines
On Fri, 15 Mar 2013 14:18:40 +0000
Peter Stephenson <p.stephenson@xxxxxxxxxxx> wrote:
> +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"
> + cont_prompt=
Err... (for me to commit when I get home...)
diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo
index 2279141..f13aa79 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 3d44f20..d78c35e 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.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author