zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-workers@zsh.org
Subject: Re: bug in 'rm' completion
Date: Tue, 10 Nov 2009 07:52:21 -0800	[thread overview]
Message-ID: <091110075221.ZM27832@torch.brasslantern.com> (raw)
In-Reply-To: <m3639j4mcl.fsf@klanderman.net>
In-Reply-To: <m3iqdjmm31.fsf@klanderman.net>

On Nov 9, 12:52pm, Greg Klanderman wrote:
}
} Duh.. see below.  It's just not considering the last word from the
} line when generating the ignore pattern.  What I think is needed is to
} generally remove the current word from incorporation into the ignore
} pattern, but I don't know how to do that.  If I knew how to relate
} $CURRENT to an element of $line that would do it.

Amazingly there is a descriptive comment in Src/Zle/computil.c for the
behavior of comparguments.  It says:

case 'W':
    /* This gets two parameter names as arguments.  The first is set to
     * the current word sans any option prefixes handled by comparguments.
     * The second parameter is set to an array containing the options on
     * the line and their arguments.  I.e. the stuff _arguments returns
     * to its caller in the `line' and `opt_args' parameters. */

If that's accurate, $line should be a single word and $opt_args should
be an array.  However, the C code appears to be setting the first arg
as an array and the second as a hash, which agrees with the yodl doc
for the _arguments function:

     During the performance of the action the array `line' will be set
     to the command name and normal arguments from the command line,
     i.e. the words from the command line excluding all options and
     their arguments.  Options are stored in the associative array
     `opt_args' with option names as keys and their arguments as the
     values.  For options that have more than one argument these are
     given as one string, separated by colons.  All colons in the
     original arguments are preceded with backslashes.

Only Sven W. knows why the name "line" was chosen for this; forensics
might determine at what point the comment in computil.c corresponded
to reality, but it's probably not woth the effort.


On Nov 9,  4:20pm, Greg Klanderman wrote:
} Subject: Re: bug in 'rm' completion
}
} I think the patch below is the correct fix.  I'm still not sure
} whether it should be using $line or $words and I'm not certain on the
} difference between two and three colons in the _arguments definition
} ('*::files:->file' vs '*:::files:->file') but in both cases I suspect
} it doesn't actually matter.

Doc says:

      With two colons before the MESSAGE, the words special array
      and the CURRENT special parameter are modified to refer only
      to the normal arguments when the ACTION is executed or
      evaluated.  With three colons before the MESSAGE they are
      modified to refer only to the normal arguments covered by
      this description.

I believe this means that *:: and *::: are equivalent in this case
because there are no other descriptions to "cover" other arguments.

You're correct that using one of these forms will update CURRENT to
point into $line, which is what's needed for your solution.
 
} +    ignored=(${line[1,CURRENT-1]//(#m)[\[\]()\\*?#<>~\^]/\\$MATCH})
} +    ignored+=(${line[CURRENT+1,-1]//(#m)[\[\]()\\*?#<>~\^]/\\$MATCH})

I'd be inclined to wrap that in a check that ((CURRENT > 1)) just so
it's obvious that we don't ignore the only word on the line, rather
than rely on $line[1,0] to do the right thing, but otherwise this
seems right to me.


  reply	other threads:[~2009-11-10 15:52 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-09  5:29 Greg Klanderman
2009-11-09 16:17 ` Greg Klanderman
2009-11-09 17:29   ` Bart Schaefer
2009-11-09 17:52     ` Greg Klanderman
2009-11-09 21:20       ` Greg Klanderman
2009-11-10 15:52         ` Bart Schaefer [this message]
2009-11-12  2:48           ` Greg Klanderman
2009-11-12  4:21             ` Bart Schaefer
2009-11-12 17:22               ` Greg Klanderman
2009-11-09 16:29 ` 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=091110075221.ZM27832@torch.brasslantern.com \
    --to=schaefer@brasslantern.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).