From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23441 invoked by alias); 4 Apr 2014 14:19:11 -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: 32527 Received: (qmail 12198 invoked from network); 4 Apr 2014 14:19:04 -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 X-AuditID: cbfec7f4-b7f796d000005a13-1b-533ebcfa952f Date: Fri, 04 Apr 2014 15:08:57 +0100 From: Peter Stephenson To: Zsh Hackers' List Subject: PATCH: zcalc-auto-insert Message-id: <20140404150857.668be2ad@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+NgFvrEJMWRmVeSWpSXmKPExsVy+t/xy7q/9tgFG7Sd47M42PyQyYHRY9XB D0wBjFFcNimpOZllqUX6dglcGd/fT2UueCVY8fKQawPjTb4uRk4OCQETiXVzJ7FD2GISF+6t ZwOxhQSWMkr0r6nsYuQCspczSTyb9J4VJMEioCrRvmETE4jNJmAoMXXTbMYuRg4OEQFtifaP YiBhYQFFiacnboOV8wrYS5ztbAGbzy+gL3H17ycmiF32EjOvnGGEqBGU+DH5HguIzSygJbF5 WxMrhC0vsXnNW+YJjHyzkJTNQlI2C0nZAkbmVYyiqaXJBcVJ6bmGesWJucWleel6yfm5mxgh 4fRlB+PiY1aHGAU4GJV4eBMybYOFWBPLiitzDzFKcDArifDWTbALFuJNSaysSi3Kjy8qzUkt PsTIxMEp1cC4mm/Dh8zrV0V0uMRarHSS1QQj5pVXNodervCNZ9L+/Mtjxy72ksA1ocktDLr+ UdXsbM+vs96estLuJ8cX0xCBbBHdpRFv5y858uHBwSVLelae1ZSxXDwxLPhKVeV1bh5J3zKV 7adfXbE7b+GSG7b148zD9U67n6Ucvhn2Im1OlWrHyajnq2SUWIozEg21mIuKEwHZjTHiBQIA AA== I came up with this, but I'm not sure how useful it actually is. diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index c446471..9eadc35 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -2449,6 +2449,25 @@ The style tt(whence) is available in the context tt(:zle:$WIDGET); this may be set to an array to give the command and options that will be used to investigate the command word found. The default is tt(whence -c). ) +tindex(zcalc-auto-insert) +item(tt(zcalc-auto-insert))( +This function is useful together with the tt(zcalc) function described in +ifzman(the section Mathematical Functions)\ +ifnzman(noderef(Mathematical Functions)). +It should be bound to a key representing a binary operator such +as `tt(PLUS())', `tt(-)', `tt(*)' or `tt(/)'. When running in zcalc, +if the key occurs at the start of the line or immediately following +an open parenthesis, the text tt("ans ") is inserted before the +representation of the key itself. This allows easy use of the +answer from the previous calculation in the current line. The +text to be inserted before the symbol typed can be modified by setting +the variable tt(ZCALC_AUTO_INSERT_PREFIX). + +Hence, for example, typing `tt(PLUS()12)' followed by return adds 12 +to the previous result. + +When not in zcalc, the key simply inserts the symbol itself. +) enditem() subsect(Utility Functions) diff --git a/Functions/Misc/zcalc b/Functions/Misc/zcalc index b796446..63f67ad 100644 --- a/Functions/Misc/zcalc +++ b/Functions/Misc/zcalc @@ -96,6 +96,9 @@ emulate -L zsh setopt extendedglob +# For testing in ZLE functions. +local ZCALC_ACTIVE=1 + # TODO: make local variables that shouldn't be visible in expressions # begin with _. local line ans base defbase forms match mbegin mend psvar optlist opt arg diff --git a/Functions/Zle/zcalc-auto-insert b/Functions/Zle/zcalc-auto-insert new file mode 100644 index 0000000..c9a5c88 --- /dev/null +++ b/Functions/Zle/zcalc-auto-insert @@ -0,0 +1,8 @@ +# Bind to a binary operator keystroke for use with zcalc + +if [[ -n $ZCALC_ACTIVE ]]; then + if [[ $CURSOR -eq 0 || $LBUFFER[-1] = "(" ]]; then + LBUFFER+=${ZCALC_AUTO_INSERT_PREFIX:-"ans "} + fi +fi +zle .self-insert pws