zsh-workers
 help / color / mirror / code / Atom feed
From: Rocky Bernstein <rocky@gnu.org>
To: Peter Stephenson <Peter.Stephenson@csr.com>
Cc: zsh-workers@zsh.org
Subject: Re: bash compgen -W compatibility patch
Date: Tue, 3 May 2011 14:27:07 -0400	[thread overview]
Message-ID: <BANLkTi=ytsCu3oXLR9jZA5xhBjyUn6uUPg@mail.gmail.com> (raw)
In-Reply-To: <20110503154550.04b3fcef@pwslap01u.europe.root.pri>

[-- Attachment #1: Type: text/plain, Size: 2170 bytes --]

On Tue, May 3, 2011 at 10:45 AM, Peter Stephenson
<Peter.Stephenson@csr.com>wrote:

> On Tue, 3 May 2011 08:25:50 -0400
> Rocky Bernstein <rocky@gnu.org> wrote:
> > For example simplicity, to match the beginning of a word, I used
> >     [[ $try =~ "^$find" ]]
> > matching using == and substrings might be faster, not that I think
> > speed is all that important here. Ditt ofo inlining a newly added
> > _compgen_opt_words function; but I think that makes things uglier and
> > harder to test.
> >
> >...
> >
> > +_compgen_opt_words() {
> > +    typeset -a words
> > +    eval "words=( $1 )"
> > +    local find
> > +    find=$2
> > +    local try
> > +    find=${@[-1]}
> > +    for try in ${words[@]} ; do
> > +     if [[ $try =~ "^$find" ]] ; then
> > +         results+=( $try )
> > +     fi
> > +    done
> > +    results=( "${(k)results[@]}" )
> > +}
>
> Thanks.  It's actually possible to abbreviate this quite a lot, in ways
> which are used widely in the completion code.  Also, the eval looks a
> bit hairy because $1 can contain anything, and I think it's good enough
> to ensure that $1 is split into words and any pattern characters are
> active, which can be done without an eval.
>
> _compgen_opt_words() {
>  typeset -a words
>  words=( ${~=1} )
>  local find try
>  find=${@[-1]}
>

Probably simpler would be to use $2, i.e find=$2 I mistakenly had set find
twice in the patch.

 results=(${(M)words[@]:#$find*})
> }
>
> seems to work, unless I'm missing some basic ingredient.  If I'm not,
> I'll commit this.
>

I've replaced my code in zshdb with the above and the  tests run.

No doubt if there's a problem there's a test file which can be expanded.

Thanks for looking over and fixing.



>
> --
> Peter Stephenson <pws@csr.com>            Software Engineer
> Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
> Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ,
> UK
>
>
> Member of the CSR plc group of companies. CSR plc registered in England and
> Wales, registered number 4187346, registered office Churchill House,
> Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom
>

  reply	other threads:[~2011-05-03 18:27 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-03 12:25 Rocky Bernstein
2011-05-03 14:45 ` Peter Stephenson
2011-05-03 18:27   ` Rocky Bernstein [this message]
2011-05-04  8:55     ` 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='BANLkTi=ytsCu3oXLR9jZA5xhBjyUn6uUPg@mail.gmail.com' \
    --to=rocky@gnu.org \
    --cc=Peter.Stephenson@csr.com \
    --cc=zsh-workers@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).