From: Peter Stephenson <p.stephenson@samsung.com>
To: Zsh Hackers' List <zsh-workers@zsh.org>
Subject: PATCH: Make zcalc understand continuation lines
Date: Fri, 15 Mar 2013 14:18:40 +0000 [thread overview]
Message-ID: <20130315141840.2d8236d8@pwslap01u.europe.root.pri> (raw)
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
next reply other threads:[~2013-03-15 14:18 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-15 14:18 Peter Stephenson [this message]
2013-03-15 14:38 ` Peter Stephenson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130315141840.2d8236d8@pwslap01u.europe.root.pri \
--to=p.stephenson@samsung.com \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).