From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13192 invoked by alias); 15 Mar 2013 21:12:07 -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: 31155 Received: (qmail 3588 invoked from network); 15 Mar 2013 21:12:05 -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=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 Received-SPF: neutral (ns1.primenet.com.au: 209.85.212.176 is neither permitted nor denied by SPF record at ntlworld.com) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-proxyuser-ip:date:from:to:subject:message-id:x-mailer :mime-version:content-type:content-transfer-encoding :x-gm-message-state; bh=y07x3GWPFRkzGhrLLjdYxx8rt2wW4dO3R3FMDmiJtyU=; b=Nn7mQIJAtcooYtJTm2tDIhuGmU/p+moMby9YvkRlxBZztae1JE/i3BDzf6ZQA+4sMp coiQvIo4s1BLK+B80NQWfY06Pa+3kCslRZFnxYOe0Vmqd+u+qhK8m0XUYT0JkliK8gyU 9e7Vehtw3Rv+KCXzHJ4Sflm1rVyyaCKtM+9q3LVCb/b+ImfkMzG0jLe1XJBfEJVu4Fv+ 6Gkg+BX0L5vXXXrIfKp8oqLlwfQRhreQP+89JOc57shNR8hUYeSbmQ6+uLwKa80DABR8 KHahFdPRkVDRO3OkW/FD9/3aYkVITCJbiL0AZwQCCFt3C3mfMuPd07boGhTT2rTPd4c4 02PQ== X-Received: by 10.194.88.138 with SMTP id bg10mr13535036wjb.13.1363380079156; Fri, 15 Mar 2013 13:41:19 -0700 (PDT) X-ProxyUser-IP: 86.26.6.143 Date: Fri, 15 Mar 2013 20:41:15 +0000 From: Peter Stephenson To: Zsh Hackers' List Subject: PATCH: more zcalc featurettes Message-ID: <20130315204115.0c123676@pws-pc.ntlworld.com> X-Mailer: Claws Mail 3.8.0 (GTK+ 2.24.7; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Gm-Message-State: ALoCoQmJ7OKEbV+fVUW9yw151RFDJknhnol2Re08SanXCbhqxmXH1MayN+E1c9NUXFVTrwiXCcPq Hardly worth posting unless anyone can think of why it's a bad idea to assume an input line consisting of an arithmetic formula should contain at least as many close parentheses as open parentheses. - Display the current answer in the new base when changing the default output base. - Prompt for more input if uncompleted parenthesised expressions. - Allow :function to be abbreviated as :func or :f. Index: Doc/Zsh/contrib.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/contrib.yo,v retrieving revision 1.150 diff -p -u -r1.150 contrib.yo --- Doc/Zsh/contrib.yo 15 Mar 2013 20:15:10 -0000 1.150 +++ Doc/Zsh/contrib.yo 15 Mar 2013 20:39:31 -0000 @@ -3144,12 +3144,14 @@ line preceded by `tt(4> )' is available 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). A -line ending with a single backslash is treated in the same fashion +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. +result. In addition, if the input so far contains more open than +close parentheses tt(zcalc) will prompt for more input. 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 @@ -3219,11 +3221,13 @@ scope. ) item(tt(:function) var(name) [ var(body) ])( Define a mathematical function or (with no var(body)) delete it. +tt(:function) may be abbreviated to tt(:func) or simply tt(:f). +The var(name) may contain the same characters as a shell function name. The function is defined using tt(zmathfuncdef), see below. Note that tt(zcalc) takes care of all quoting. Hence for example: -example(function cube $1 * $1 * $1) +example(:f cube $1 * $1 * $1) defines a function to cube the sole argument. ) Index: Functions/Misc/zcalc =================================================================== RCS file: /cvsroot/zsh/zsh/Functions/Misc/zcalc,v retrieving revision 1.22 diff -p -u -r1.22 zcalc --- Functions/Misc/zcalc 15 Mar 2013 20:15:10 -0000 1.22 +++ Functions/Misc/zcalc 15 Mar 2013 20:39:31 -0000 @@ -166,6 +166,14 @@ while vared -cehp "${cont_prompt}${ZCALC line="$prev_line$line" prev_line= cont_prompt= + # Test whether there are as many open as close + # parentheses in the line so far. + if [[ ${#line//[^\(]} -gt ${#line//[^\)]} ]]; then + prev_line+=$line + cont_prompt="..." + line= + continue + fi [[ -z $line ]] && break # special cases # Set default base if `[#16]' or `[##16]' etc. on its own. @@ -178,6 +186,7 @@ while vared -cehp "${cont_prompt}${ZCALC defbase=$match[1] fi print -s -- $line + print -- $(( ${defbase} ans )) line= continue else @@ -233,7 +242,7 @@ while vared -cehp "${cont_prompt}${ZCALC continue ;; - ((:|)function[[:blank:]]##(#b)([^[:blank:]]##)(|[[:blank:]]##([^[:blank:]]*))) + ((function|:f(unc(tion|)|))[[:blank:]]##(#b)([^[:blank:]]##)(|[[:blank:]]##([^[:blank:]]*))) zmathfuncdef $match[1] $match[3] line= continue -- Peter Stephenson Web page now at http://homepage.ntlworld.com/p.w.stephenson/