From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27207 invoked by alias); 3 Jun 2012 22:43:58 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 17131 Received: (qmail 29669 invoked from network); 3 Jun 2012 22:43:56 -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: none (ns1.primenet.com.au: domain at k-bx.com does not designate permitted sender hosts) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding :x-gm-message-state; bh=KcSm2+pxr0G/soSRtgq0IApc7xR6lVRG6DLJMAiKtmM=; b=aQjlFd44fANMWsGuzctCshCRxHGk4bGOlj7mv0XriRvQptQcx4sf0y68tCUC5cUVHM kIPJ6YGDFQHg19lqCKB1AYMY+kSLd2rEQpZbKIQpkGu50KAx/msjbY7RXGOJAop4qp0P tuq96Cdeh6vGfwvb3+hqc43t+0INEEx0b/AzuyZgs9EFQ9/BLMP7+58Le2/rCTdcC5y/ KahjKQCPon9gdT1M2CPgYM8UtnnLmXRuAXPGvuqN4lIJ4wp2do4pns89u0/p0+tut0RG xNTnW0/tyt2jpBWhJtq6nEWLhPy13Glzy6kYIVa3OOpjfchbDhRCDpGKlxjjF4Vpvwpi IOpw== Message-ID: <4FCBE8A3.1050603@k-bx.com> Date: Mon, 04 Jun 2012 01:43:47 +0300 From: Konstantine Rybnikov User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20120430 Thunderbird/12.0.1 MIME-Version: 1.0 To: Peter Stephenson CC: zsh-users@zsh.org Subject: Re: Word-forward/word-backward as in bash / emacs References: <4FCBC8D3.3020905@k-bx.com> <20120603223629.31f92548@pws-pc.ntlworld.com> In-Reply-To: <20120603223629.31f92548@pws-pc.ntlworld.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Gm-Message-State: ALoCoQlUnbhiRJo1KDkubFl3j9uUvyVwTVuQxuhzgmD4sp/CQoaMEUX3ep9TBtD+1PoBOuvHNELr 06/04/2012 12:36 AM, Peter Stephenson написал: > On Sun, 03 Jun 2012 23:28:03 +0300 > Konstantine Rybnikov wrote: >> Only answer I got is to do "select-word-style bash", which is absolutely >> not the same as bash (I also provided an example there that explains "why"). > So, with "select-word-style bash" that forward-word thing is the only > difference, right? It seemed to be when I tried your example. > > I actually noted forward-word was a bit funny when I wrote the function > forward-word-match that implements it when you uses select-word-style. > See if this does the trick --- it patches the function forward-word-match > which will be installed in your $fpath. > > I've made the old behaviour a separate (non-default) option for the sake > of this, but if this is what's needed we probably need to think a bit > more about when it should apply. The original behaviour works better > with zsh's normal set up because then more characters are considered > part of a word, so skipping non-word-characters at the start is less > likely to have side effects. > > One possibility would be to reverse the sense of the option (to > skip-whitespace-first), but to set it to "true" from select word-style > if it's not explicitly set and the new style is "bash". That keeps > compatibility in both cases. However, there are other ways of doing it. > > (I also standardised the indentation while I was there, so there's more > changed than is really necessary.) > > Index: Functions/Zle/forward-word-match > =================================================================== > RCS file: /cvsroot/zsh/zsh/Functions/Zle/forward-word-match,v > retrieving revision 1.3 > diff -p -u -r1.3 forward-word-match > --- Functions/Zle/forward-word-match 28 Jul 2010 13:33:59 -0000 1.3 > +++ Functions/Zle/forward-word-match 3 Jun 2012 21:22:36 -0000 > @@ -8,32 +8,35 @@ local -a matched_words > integer count=${NUMERIC:-1} > > if (( count< 0 )); then > - (( NUMERIC = -count )) > - zle ${WIDGET/forward/backward} > - return > + (( NUMERIC = -count )) > + zle ${WIDGET/forward/backward} > + return > fi > > while (( count-- )); do > - > - match-words-by-style > - > + match-words-by-style > + > + if zstyle -t $curcontext skip-whitespace-last; then > # For some reason forward-word doesn't work like the other word > # commands; it skips whitespace only after any matched word > # characters. > - > if [[ -n $matched_words[4] ]]; then > - # just skip the whitespace > - word=$matched_words[4] > - else > - # skip the word and trailing whitespace > - word=$matched_words[5]$matched_words[6] > - fi > - > - if [[ -n $word ]]; then > - (( CURSOR += ${#word} )) > + # just skip the whitespace > + word=$matched_words[4] > else > - return 1 > + # skip the word and trailing whitespace > + word=$matched_words[5]$matched_words[6] > fi > + else > + # more standard behaviour: skip leading whitespace and the word. > + word=$matched_words[4]$matched_words[5] > + fi > + > + if [[ -n $word ]]; then > + (( CURSOR += ${#word} )) > + else > + return 1 > + fi > done > > return 0 Ok, it looks like Moritz Bunkus updated he's answer with working implementation of forward-word-match. You're right, the only difference if forward-word things. Just tried your patch -- yes, looks like it works as expected. Thanks!