From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21344 invoked by alias); 15 Mar 2013 14:48:12 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 31154 Received: (qmail 4292 invoked from network); 15 Mar 2013 14:48:10 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_PASS autolearn=ham version=3.3.2 Received-SPF: softfail (ns1.primenet.com.au: transitioning SPF record at amazonses.com does not designate 210.118.77.13 as permitted sender) X-AuditID: cbfec7f4-b7f4c6d0000018de-b0-51433249d8bf Date: Fri, 15 Mar 2013 14:38:01 +0000 From: Peter Stephenson To: Zsh Hackers' List Subject: Re: PATCH: Make zcalc understand continuation lines Message-id: <20130315143801.32f820e1@pwslap01u.europe.root.pri> In-reply-to: <20130315141840.2d8236d8@pwslap01u.europe.root.pri> References: <20130315141840.2d8236d8@pwslap01u.europe.root.pri> Organization: Samsung Cambridge Solution Centre X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFuphluLIzCtJLcpLzFFi42I5/e/4FV1PI+dAg3/7rSwONj9kcmD0WHXw A1MAYxSXTUpqTmZZapG+XQJXxrGnLWwFdwUqbu67x9LAuI23i5GTQ0LAROLsmQ/sELaYxIV7 69m6GLk4hASWMkocnnqXBcJZziSxacFZRpAqFgFVie87HjCB2GwChhJTN80GinNwiAhoS7R/ FAMJCwvYSGw5dwGshFfAXuJvy20WEJtTwEHiyNtGMFsIKD5n7zFmEJtfQF/i6t9PTBBH2EvM vHKGEaJXUOLH5Htg9cwCWhKbtzWxQtjyEpvXvGWewCgwC0nZLCRls5CULWBkXsUomlqaXFCc lJ5rqFecmFtcmpeul5yfu4kREoJfdjAuPmZ1iFGAg1GJh9fhoWOgEGtiWXFl7iFGCQ5mJRHe d/rOgUK8KYmVValF+fFFpTmpxYcYmTg4pRoYRScqqAvsfymx2rE/Z4fHVVU7y+b1h3Lm6fKf r/v5dzrHxZ+dBsbrpp4RfqEfL7NE9Ipg0NH2WytEeVV/7gmu152T1tcx81OdcWtKGjNXZfDa ec0vT8z5f+1+bHy/yPvdKfaXtjTH7ArvnX3w4hq3go93PYrkuoOnbVu6P12jz2a+oVHNRIZQ JZbijERDLeai4kQAbXE/vR8CAAA= On Fri, 15 Mar 2013 14:18:40 +0000 Peter Stephenson 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.