From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24165 invoked by alias); 3 Jun 2012 21:59:12 -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: 17130 Received: (qmail 25427 invoked from network); 3 Jun 2012 21:59:10 -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: neutral (ns1.primenet.com.au: 74.125.82.43 is neither permitted nor denied by SPF record at ntlworld.com) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-proxyuser-ip:date:from:to:subject:message-id:in-reply-to :references:x-mailer:mime-version:content-type :content-transfer-encoding:x-gm-message-state; bh=pVtdv7rqwB/yLdnas8B1ehrGf0sQt474Nn5EntkNIX4=; b=XRV7UC2ay7eJAfq0x6t65xACpDWfutVTlB59qQnMq5Rolqcz7XDhs2aM4NrOG/3q2U K7QYsjOlz0YUEBNGudwxVSE0I2Wvj12bmItbR8gjmQo9Fc3vxIrXCPCc/f6pPX8I/D57 P/UFsl5Jr16Kq2XybD6avtg46pKq8kj3ijojf46o9jKpufsOFLQT/+aSSfdnC9jTsxjG 3mgH9RspEksi+vvrQ7v5UjAK+d+99BcO9jd2ve2KhRODm4qZ9Hg3VejZsACgM9Gmx6kw M3JkP9z3gDueJRnAb/PgLoh/MnHUvpuUKS75jUvFtusfIz89C8CGa1uQyiadTB/4luuu q3TQ== X-ProxyUser-IP: 86.6.29.42 Date: Sun, 3 Jun 2012 22:36:29 +0100 From: Peter Stephenson To: zsh-users@zsh.org Subject: Re: Word-forward/word-backward as in bash / emacs Message-ID: <20120603223629.31f92548@pws-pc.ntlworld.com> In-Reply-To: <4FCBC8D3.3020905@k-bx.com> References: <4FCBC8D3.3020905@k-bx.com> X-Mailer: Claws Mail 3.8.0 (GTK+ 2.24.7; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Gm-Message-State: ALoCoQmi0zAntcd/qDH/+AQVWsQ0xWeWLwkT2X/au7+a18bqXZczOb/tKltpShJ2OQ0iCIWiLQSi 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