Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm
Precedence: bulk
X-No-Archive: yes
List-Id: Zsh Workers List <zsh-workers.zsh.org>
List-Post: <mailto:zsh-workers@zsh.org>
List-Help: <mailto:zsh-workers-help@zsh.org>
X-Qmail-Scanner-Diagnostics: from mx0b-001b2d01.pphosted.com by f.primenet.com.au (envelope-from <hanpt@linux.vnet.ibm.com>, uid 7791) with qmail-scanner-2.11 
 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1.  
 Clear:RC:0(148.163.158.5):SA:0(0.0/5.0):. 
 Processed in 0.21375 secs); 12 Aug 2016 04:36:43 -0000
X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au
X-Spam-Level: 
X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=unavailable
	autolearn_force=no version=3.4.1
X-Envelope-From: hanpt@linux.vnet.ibm.com
X-Qmail-Scanner-Mime-Attachments: |
X-Qmail-Scanner-Zip-Files: |
Received-SPF: none (ns1.primenet.com.au: domain at linux.vnet.ibm.com does not designate permitted sender hosts)
X-IBM-Helo: d03dlp03.boulder.ibm.com
X-IBM-MailFrom: hanpt@linux.vnet.ibm.com
Date: Fri, 12 Aug 2016 10:54:02 +0800
From: Han Pingtian <hanpt@linux.vnet.ibm.com>
To: zsh-workers@zsh.org
Subject: Re: [PATCH] enable number argument for transpose-words
Mail-Followup-To: zsh-workers@zsh.org
References: <20160801103212.GA24067@localhost.localdomain>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <20160801103212.GA24067@localhost.localdomain>
User-Agent: Mutt/1.6.2 (2016-07-01)
X-TM-AS-GCONF: 00
X-Content-Scanned: Fidelis XPS MAILER
x-cbid: 16081202-0020-0000-0000-000009896F83
X-IBM-SpamModules-Scores: 
X-IBM-SpamModules-Versions: BY=3.00005580; HX=3.00000240; KW=3.00000007;
 PH=3.00000004; SC=3.00000181; SDB=6.00743454; UDB=6.00350086; IPR=6.00515992;
 BA=6.00004658; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000;
 ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00012320; XFM=3.00000011;
 UTC=2016-08-12 02:54:08
X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused
x-cbparentid: 16081202-0021-0000-0000-0000547F3FB8
Message-Id: <20160812025402.GA5319@localhost.localdomain>
X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2016-08-12_01:,,
 signatures=0
X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=1
 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam
 adjust=0 reason=mlx scancount=1 engine=8.0.1-1604210000
 definitions=main-1608120032
X-Seq: zsh-workers 39027

On Mon, Aug 01, 2016 at 06:32:12PM +0800, Han Pingtian wrote:
> Looks like number argument doesn't work for transpose-words widget: if
> the number is even, there is no words transposed; if the number is odd,
> the behavior is the same of no number argument given.
> 
> With this patch, current word will be transposed with the preious nth
> word if number argument n given.
> 
> Signed-off-by: Han Pingtian <hanpt@linux.vnet.ibm.com>
> ---
>  Src/Zle/zle_word.c | 90 +++++++++++++++++++++++++++++++-----------------------
>  1 file changed, 51 insertions(+), 39 deletions(-)
> 
> diff --git a/Src/Zle/zle_word.c b/Src/Zle/zle_word.c
> index 3c1f26c..2a15171 100644
> --- a/Src/Zle/zle_word.c
> +++ b/Src/Zle/zle_word.c
> @@ -678,46 +678,54 @@ killword(char **args)
>  int
>  transposewords(UNUSED(char **args))
>  {
> -    int p1, p2, p3, p4, len, x = zlecs, pos;
> +    int p1, p2, p3, p4, pt, len, x = zlecs, pos;
>      ZLE_STRING_T temp, pp;
>      int n = zmult;
>      int neg = n < 0, ocs = zlecs;
> 
>      if (neg)
>  	n = -n;
> -    while (n--) {
> -	while (x != zlell && zleline[x] != ZWC('\n') && !ZC_iword(zleline[x]))
> -	    INCPOS(x);
> -	if (x == zlell || zleline[x] == ZWC('\n')) {
> -	    x = zlecs;
> -	    while (x) {
> -		if (ZC_iword(zleline[x]))
> -		    break;
> -		pos = x;
> -		DECPOS(pos);
> -		if (zleline[pos] == ZWC('\n'))
> -		    break;
> -		x = pos;
> -	    }
> -	    if (!x)
> -		return 1;
> +
> +    while (x != zlell && zleline[x] != ZWC('\n') && !ZC_iword(zleline[x]))
> +	INCPOS(x);
> +
> +    if (x == zlell || zleline[x] == ZWC('\n')) {
> +	x = zlecs;
> +	while (x) {
> +	    if (ZC_iword(zleline[x]))
> +		break;
>  	    pos = x;
>  	    DECPOS(pos);
>  	    if (zleline[pos] == ZWC('\n'))
> -		return 1;
> -	}
> -	for (p4 = x; p4 != zlell && ZC_iword(zleline[p4]); INCPOS(p4))
> -	    ;
> -	for (p3 = p4; p3; ) {
> -	    pos = p3;
> -	    DECPOS(pos);
> -	    if (!ZC_iword(zleline[pos]))
>  		break;
> -	    p3 = pos;
> +	    x = pos;
>  	}
> -	if (!p3)
> +	if (!x)
>  	    return 1;
> -	for (p2 = p3; p2; ) {
> +	pos = x;
> +	DECPOS(pos);
> +	if (zleline[pos] == ZWC('\n'))
> +	    return 1;
> +    }
> +
> +    for (p4 = x; p4 != zlell && ZC_iword(zleline[p4]); INCPOS(p4))
> +	;
> +
> +    for (p3 = p4; p3; ) {
> +	pos = p3;
> +	DECPOS(pos);
> +	if (!ZC_iword(zleline[pos]))
> +	    break;
> +	p3 = pos;
> +    }
> +
> +    if (!p3)
> +	return 1;
> +
> +    pt = p3;
> +
> +    while (n--) {
> +	for (p2 = pt; p2; ) {
>  	    pos = p2;
>  	    DECPOS(pos);
>  	    if (ZC_iword(zleline[pos]))
> @@ -733,20 +741,24 @@ transposewords(UNUSED(char **args))
>  		break;
>  	    p1 = pos;
>  	}
> -	pp = temp = (ZLE_STRING_T)zhalloc((p4 - p1)*ZLE_CHAR_SIZE);
> -	len = p4 - p3;
> -	ZS_memcpy(pp, zleline + p3, len);
> -	pp += len;
> -	len = p3 - p2;
> -	ZS_memcpy(pp, zleline + p2, len);
> -	pp += len;
> -	ZS_memcpy(pp, zleline + p1, p2 - p1);
> +	pt = p1;
> +    }
> 
> -	ZS_memcpy(zleline + p1, temp, p4 - p1);
> +    pp = temp = (ZLE_STRING_T)zhalloc((p4 - p1)*ZLE_CHAR_SIZE);
> +    len = p4 - p3;
> +    ZS_memcpy(pp, zleline + p3, len);
> +    pp += len;
> +    len = p3 - p2;
> +    ZS_memcpy(pp, zleline + p2, len);
> +    pp += len;
> +    ZS_memcpy(pp, zleline + p1, p2 - p1);
> +
> +    ZS_memcpy(zleline + p1, temp, p4 - p1);
> 
> -	zlecs = p4;
> -    }
>      if (neg)
>  	zlecs = ocs;
> +    else
> +	zlecs = p4;
> +
>      return 0;
>  }
> -- 
> 2.5.5

Any suggestions to this one, please? Thanks in advance.

