From: Konstantine Rybnikov <k-bx@k-bx.com>
To: Peter Stephenson <p.w.stephenson@ntlworld.com>
Cc: zsh-users@zsh.org
Subject: Re: Word-forward/word-backward as in bash / emacs
Date: Mon, 04 Jun 2012 01:43:47 +0300 [thread overview]
Message-ID: <4FCBE8A3.1050603@k-bx.com> (raw)
In-Reply-To: <20120603223629.31f92548@pws-pc.ntlworld.com>
06/04/2012 12:36 AM, Peter Stephenson написал:
> On Sun, 03 Jun 2012 23:28:03 +0300
> Konstantine Rybnikov<k-bx@k-bx.com> 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!
next prev parent reply other threads:[~2012-06-03 22:43 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-03 20:28 Konstantine Rybnikov
2012-06-03 21:36 ` Peter Stephenson
2012-06-03 22:43 ` Konstantine Rybnikov [this message]
2012-06-03 23:45 ` Peter Stephenson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4FCBE8A3.1050603@k-bx.com \
--to=k-bx@k-bx.com \
--cc=p.w.stephenson@ntlworld.com \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).