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 mailout2.w1.samsung.com by f.primenet.com.au (envelope-from <p.stephenson@samsung.com>, uid 7791) with qmail-scanner-2.11 
 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1.  
 Clear:RC:0(210.118.77.12):SA:0(-0.5/5.0):. 
 Processed in 0.189744 secs); 15 Aug 2016 08:39:55 -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.5 required=5.0 tests=RP_MATCHES_RCVD
	autolearn=unavailable autolearn_force=no version=3.4.1
X-Envelope-From: p.stephenson@samsung.com
X-Qmail-Scanner-Mime-Attachments: |
X-Qmail-Scanner-Zip-Files: |
Received-SPF: none (ns1.primenet.com.au: domain at samsung.com does not designate permitted sender hosts)
X-AuditID: cbfec7f5-f792a6d000001302-e1-57b17fd31267
Date: Mon, 15 Aug 2016 09:39:47 +0100
From: Peter Stephenson <p.stephenson@samsung.com>
To: zsh-workers@zsh.org
Subject: Re: [PATCH] enable number argument for transpose-words
Message-id: <20160815093947.3e591f1d@pwslap01u.europe.root.pri>
In-reply-to: <20160815022250.GA3748@localhost.localdomain>
References: <20160801103212.GA24067@localhost.localdomain>
 <20160812025402.GA5319@localhost.localdomain>
 <20160812102918.5ad0f649@pwslap01u.europe.root.pri>
 <20160815022250.GA3748@localhost.localdomain>
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+NgFrrILMWRmVeSWpSXmKPExsVy+t/xy7qX6zeGG2w/JmJxsPkhkwOjx6qD
	H5gCGKO4bFJSczLLUov07RK4MtZ/2MRasFOs4u7RVSwNjOuFuhg5OSQETCTeb/3MBmGLSVy4
	tx7I5uIQEljKKPH19iQoZwaTxJHNFxkhnHOMEr/PtbKCtAgJnGWUOPIrGMRmEVCVeDWtlRHE
	ZhMwlJi6aTaYLSIgLnF27XkWEFtYwF5i6+M3YL28QPbrrYfZQWxOASuJiat2s0IsuMAoseXV
	bbBmfgF9iat/PzFB3GcvMfPKGUaIZkGJH5PvgQ1lFtCS2LytiRXClpfYvOYtM8Rx6hI37u5m
	n8AoPAtJyywkLbOQtCxgZF7FKJpamlxQnJSea6RXnJhbXJqXrpecn7uJERLQX3cwLj1mdYhR
	gINRiYdXoG5DuBBrYllxZe4hRgkOZiUR3l/VG8OFeFMSK6tSi/Lji0pzUosPMUpzsCiJ887c
	9T5ESCA9sSQ1OzW1ILUIJsvEwSnVwHgjdP7jAsdbwdWtLH69HPfmvpgSt0Wr9dCS9ctfbdyn
	NFGYfccyndzcZwWpZg4SX80cYhQ4muJeBf6d0ft57WLPiantb7f5W63e/FgjcbVQZoWrrtTE
	B5/ebbGb+MVXbc/rja6X4i6Fu1w99cP0m/VCT/9Fu2Xk1Llu5/bnuaWazzorej2v9qESS3FG
	oqEWc1FxIgCW138uZAIAAA==
X-Seq: zsh-workers 39038

On Mon, 15 Aug 2016 10:22:50 +0800
Han Pingtian <hanpt@linux.vnet.ibm.com> wrote:
> > diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo
> > index eaca1b3..aa219dc 100644
> > --- a/Doc/Zsh/zle.yo
> > +++ b/Doc/Zsh/zle.yo
> > @@ -1948,6 +1948,12 @@ to the left.
> >  tindex(transpose-words)
> >  item(tt(transpose-words) (tt(ESC-T ESC-t)) (unbound) (unbound))(
> >  Exchange the current word with the one before it.
> > +
> > +With a positive numeric argument em(N), the word before the cursor is
> > +transposed with the following em(N) words.
> > +
> > +With a negative numeric argument em(-N), the word after the cursor
> > +is transposed with the preceding em(N) words.
> >  )
> >  tindex(vi-unindent)
> >  item(tt(vi-unindent) (unbound) (tt(<)) (unbound))(
> Thanks. But both positive and negative numeric argument would transpose
> current word with preceding N/-N word. The negative argument only make
> cursor doesn't change its position after the transpostion.

Ah, I had the key bound as

zle -N transpose-words-between transpose-words-about-point-match
bindkey '\et' transpose-words-between

with the following function (there are lots of different possible
behaviours in this case).

I'll find a form of words for the new standard behaviour.

pws


# Transpose words, matching the words using match-words-by-style, q.v.
# The group of word characters preceeding the cursor (not necessarily
# immediately) are transposed with the group of word characters following
# the cursor (again, not necessarily immediately).
#
# Note the style skip-chars, used in the context of the current widget.
# This gives a number of character starting from the cursor position
# which are never considered part of a word and hence are always left
# alone.  The default is 0 and typically the only useful alternative
# is one.  This would have the effect that `fooXbar' with the cursor
# on X would be turned into `barXfoo' with the cursor still on the X,
# regardless of what the character X is.

autoload match-words-by-style

local curcontext=":zle:$WIDGET" skip
local -a matched_words
integer count=${NUMERIC:-1} neg

(( count < 0 )) && (( count = -count, neg = 1 ))

while (( count-- > 0 )); do
    match-words-by-style

    [[ -z "$matched_words[2]$matched_words[5]" ]] && return 1

    if (( !${NUMERIC:-0} )); then
	# No prefix, don't advance cursor.
	LBUFFER="$matched_words[1]$matched_words[5]$matched_words[3]"
	RBUFFER="$matched_words[4]$matched_words[2]${(j..)matched_words[6,7]}"
    elif (( neg )); then
	LBUFFER="$matched_words[1]"
	RBUFFER="$matched_words[5]${(j..)matched_words[3,4]}\
$matched_words[2]${(j..)matched_words[6,7]}"
    else
	LBUFFER="$matched_words[1]$matched_words[5]${(j..)matched_words[3,4]}\
$matched_words[2]"
	RBUFFER="${(j..)matched_words[6,7]}"
    fi

done

return 0

