* PATCH: Make zcalc understand continuation lines
@ 2013-03-15 14:18 Peter Stephenson
2013-03-15 14:38 ` Peter Stephenson
0 siblings, 1 reply; 2+ messages in thread
From: Peter Stephenson @ 2013-03-15 14:18 UTC (permalink / raw)
To: Zsh Hackers' List
diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo
index 14886d6..22202b0 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..2eeb498 100644
--- a/Functions/Misc/zcalc
+++ b/Functions/Misc/zcalc
@@ -155,7 +155,16 @@ 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"
+ cont_prompt=
[[ -z $line ]] && break
# special cases
# Set default base if `[#16]' or `[##16]' etc. on its own.
--
Peter Stephenson <p.stephenson@samsung.com> Consultant, Software
Tel: +44 (0)1223 434724 Samsung Cambridge Solution Centre
St John's House, St John's Innovation Park,
Cowley Road, Cambridge, CB4 0DS, UK
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: PATCH: Make zcalc understand continuation lines
2013-03-15 14:18 PATCH: Make zcalc understand continuation lines Peter Stephenson
@ 2013-03-15 14:38 ` Peter Stephenson
0 siblings, 0 replies; 2+ messages in thread
From: Peter Stephenson @ 2013-03-15 14:38 UTC (permalink / raw)
To: Zsh Hackers' List
On Fri, 15 Mar 2013 14:18:40 +0000
Peter Stephenson <p.stephenson@samsung.com> 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.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-03-15 14:48 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-15 14:18 PATCH: Make zcalc understand continuation lines Peter Stephenson
2013-03-15 14:38 ` Peter Stephenson
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).