From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6611 invoked from network); 11 Mar 2007 10:05:08 -0000 X-Spam-Checker-Version: SpamAssassin 3.1.8 (2007-02-13) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,FORGED_RCVD_HELO autolearn=ham version=3.1.8 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 11 Mar 2007 10:05:08 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 51895 invoked from network); 11 Mar 2007 10:05:02 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 11 Mar 2007 10:05:01 -0000 Received: (qmail 28703 invoked by alias); 11 Mar 2007 10:04:58 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 23212 Received: (qmail 28694 invoked from network); 11 Mar 2007 10:04:58 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 11 Mar 2007 10:04:58 -0000 Received: (qmail 51498 invoked from network); 11 Mar 2007 10:04:58 -0000 Received: from smtp2-g19.free.fr (212.27.42.28) by a.mx.sunsite.dk with SMTP; 11 Mar 2007 10:04:51 -0000 Received: from localhost (evr91-1-82-227-12-160.fbx.proxad.net [82.227.12.160]) by smtp2-g19.free.fr (Postfix) with ESMTP id 8DD6B8BCE3 for ; Sun, 11 Mar 2007 11:04:51 +0100 (CET) Date: Sun, 11 Mar 2007 11:04:51 +0100 From: "arno." To: zsh-workers@sunsite.dk Subject: Re: PATCH: vi-add-numeric Message-ID: <20070311100451.GA6315@localhost.localdomain> Mail-Followup-To: zsh-workers@sunsite.dk References: <20070310230618.GA7124@localhost.localdomain> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="huq684BweRXVnRxX" Content-Disposition: inline In-Reply-To: <20070310230618.GA7124@localhost.localdomain> User-Agent: Mutt/1.5.13 (2006-08-11) --huq684BweRXVnRxX Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Le dimanche 11 mars 2007, =E0 00:06:18 +0100, arno. a =E9crit :=20 > Hi, here are two zle widgets >=20 Oups, negative number management was quite messy. Here is a better version arno Index: Functions/Zle/vi-add-numeric --- /dev/null +++ Functions/Zle/vi-add-numeric @@ -0,0 +1,74 @@ +# This function acts like add command in vim (^A in command mode) +# Only works now for decimal numbers +# +# If cursor is on any digit of a number, increment that number. +# If cursor is not on a number, find the next number on the right and incr= ement +# it. +# Cursor is then placed on the last digit of that number. +# +# If a numeric argument is given, increment the number by that argument. +# Otherwise, increment by shell parameter incarg (it can be useful to set = that +# parameter if you plan to do a lot with a particular number). Otherwise, +# increment by 1. +# +# examples: +# echo 41 43 +# ^^^^^^^ cursor anywhere here +# -> +# echo 42 43 +# ^ cursor here now +# +# +# echo 41 43 +# ^^^ cursor anywhere here +# -> +# echo 42 43 +# ^ cursor here now +# + +emulate -L zsh +setopt extendedglob + +local pos num newnu sign buf + +if [[ $BUFFER[$((CURSOR + 1))] =3D [0-9] ]]; then + + # cursor is on a number; search its beginning to the left + pos=3D$((${#LBUFFER%%[0-9]##} + 1)) + +else + + # cursor is not on a number; search a number to the right + pos=3D$(($CURSOR + ${#RBUFFER%%[0-9]*} + 1)) + +fi + +# no number found in BUFFER +(($pos <=3D ${#BUFFER})) || return + + +# ok, get the number now +num=3D${${BUFFER[$pos,-1]}%%[^0-9]*} + +# checks if number is negative +if ((pos > 0)) && [ $BUFFER[$((pos - 1))] =3D '-' ]; then + num=3D$((0 - num)) + ((pos--)) +fi + +# computes result +newnum=3D$((num + ${NUMERIC:-${incarg:-1}})) + + +# replaces old number by result +if ((pos > 1)); then + buf=3D${BUFFER[0,$((pos - 1))]}${BUFFER[$pos,-1]/$num/$newnum} +else + buf=3D${BUFFER/$num/$newnum} +fi + +# assign computed string to buffer +BUFFER=3D$buf + +# places cursor on last digit of number +CURSOR=3D$((pos + $#newnum - 2)) Index: Functions/Zle/vi-substract-numeric --- /dev/null +++ Functions/Zle/vi-substract-numeric @@ -0,0 +1,4 @@ +emulate -L zsh +autoload -U vi-add-numeric +NUMERIC=3D$((0 - ${NUMERIC:-${incarg:-1}})) +vi-add-numeric --huq684BweRXVnRxX Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFF89RDiH9aBScBsrMRAkxjAJ9krKYIzqNJahuyDqES+LcUZ8wONQCcD0ib 8aEg9OKnjZCRe+iw2Tny5Fs= =1kDw -----END PGP SIGNATURE----- --huq684BweRXVnRxX--