zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: zsh-workers <zsh-workers@sunsite.dk>
Subject: Re: setopt globcomplete and () broken
Date: Tue, 10 Mar 2009 13:51:46 +0000	[thread overview]
Message-ID: <20090310135146.30c0c794@news01> (raw)
In-Reply-To: <237967ef0903100625s7e8e5908t7852ade0c1d6d8d3@mail.gmail.com>

On Tue, 10 Mar 2009 14:25:16 +0100
Mikael Magnusson <mikachu@gmail.com> wrote:
> This is something that has been broken forever, but I never bothered
> to look into exactly what broke it in my config. Today I got annoyed
> enough though.
> 
> zsh -f
> % autoload compinit; compinit
> % mkdir newdir; cd newdir
> % touch '()' '().'
> % touch <tab>
> % touch \(\)<tab>
> \(\)   \(\).
> % setopt globcomplete
> % touch <tab>
> % touch \(\)<tab>
> # nothing appears
> 
> I can only reproduce it with a pair of parentheses, just ( or )
> doesn't trigger it, but text can appear between them and still trigger
> it. The oldest version I tried was 4.2.5 and the newest some days old
> cvs.

The following chunk of code in guess-where around line 201 is triggering:
it's looking for glob qualifiers.  We need a test that the parentheses
aren't quoted; we could have '()' or "()" or $'()' or \(\), or some
mixture, possibly with text in between.  There is a slightly better test
higher up, around line 17 (which correctly didn't trigger): that's newer
code that I added when completing glob qualifiers.  (The chunk of code
below isn't completing them, it's trying to ensure they get applied.)
Possibly copying the newer test here or putting it into a separate function
would help, but I will wait for any cries of enlightenment before I do
anything.

It would be quite nice to have a test for the shell to decide "is character
N in this command line argument a token or a metacharacter?" which isn't so
much more than the context lex horrors already do...  I suppose
parse-partial-sexp is out of the question.

if [[ -n "$compstate[pattern_match]" &&
      ( ( -z "$SUFFIX" && "$PREFIX" = (|*[^\$])\([^\|\~]##\) ) ||
        "$SUFFIX" =  (|*[^\$])\([^\|\~]##\) ) ]]; then
  # Copy all glob qualifiers from the line to
  # the patterns used when generating matches
  if [[ "$SUFFIX" = *\([^\|\~]##\) ]]; then
    tmp3="${${(M)SUFFIX%\([^\|\~]##\)}[2,-2]}"
    SUFFIX="${SUFFIX%\($tmp3\)}"
  else
    tmp3="${${(M)PREFIX%\([^\|\~]##\)}[2,-2]}"
    PREFIX="${PREFIX%\($tmp3\)}"
  fi
  tmp2=()
  for tmp1 in "$pats[@]"; do
    if [[ "$tmp1" = (#b)(*[^\$])"(#q"(*)")" ]]; then
      tmp2=( "$tmp2[@]" "${match[1]}(#q${tmp3}${match[2]})" )
    elif [[ "$tmp1" = (#b)(*[^\$])(\(\([^\|~]##\)\)) ]]; then
      tmp2=( "$tmp2[@]" "${match[1]}((${tmp3}${match[2][3,-1]}" )
    elif [[ "$tmp1" = (#b)(*[^\$])(\([^\|~]##\)) ]]; then
      tmp2=( "$tmp2[@]" "${match[1]}(${tmp3}${match[2][2,-1]}" )
    else
      tmp2=( "$tmp2[@]" "${tmp1}(${tmp3})" )
    fi
  done
  pats=( "$tmp2[@]" )
fi

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


  reply	other threads:[~2009-03-10 13:53 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-10 13:25 Mikael Magnusson
2009-03-10 13:51 ` Peter Stephenson [this message]
2009-03-10 17:34   ` Peter Stephenson
2009-03-10 18:04     ` Mikael Magnusson
2009-03-10 18:18       ` Peter Stephenson
2009-03-10 18:30         ` Mikael Magnusson
2009-03-11  4:22           ` Bart Schaefer
2009-03-13  9:56         ` Peter Stephenson
2009-03-13 15:08           ` Bart Schaefer

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=20090310135146.30c0c794@news01 \
    --to=pws@csr.com \
    --cc=zsh-workers@sunsite.dk \
    /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).