about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2013-03-15 20:15:10 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2013-03-15 20:15:10 +0000
commit136cc1e1b79ebc07f5deb630fea9d325276d077c (patch)
treeee76079e38ef997ad9dfb3d5d71b3faac25f36ba
parenta69f05b4cecb800c8d09c9ab94ef18d11ef275e8 (diff)
downloadzsh-136cc1e1b79ebc07f5deb630fea9d325276d077c.tar.gz
zsh-136cc1e1b79ebc07f5deb630fea9d325276d077c.tar.xz
zsh-136cc1e1b79ebc07f5deb630fea9d325276d077c.zip
31154: make zcalc understand continuation lines with a backslash
-rw-r--r--ChangeLog7
-rw-r--r--Doc/Zsh/contrib.yo7
-rw-r--r--Functions/Misc/zcalc12
3 files changed, 23 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 06751df8b..4a56f1503 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2013-03-15  Peter Stephenson  <p.w.stephenson@ntlworld.com>
+
+	* 31154: Doc/Zsh/contrib.yo, Functions/Misc/zcalc: make zcalc
+	understand continuation lines using backslash.
+
 2013-03-14  Peter Stephenson  <p.w.stephenson@ntlworld.com>
 
 	* 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.