zsh-users
 help / color / mirror / code / Atom feed
From: "Nikolai Weibull" <now@bitwi.se>
To: "Peter Stephenson" <pws@csr.com>
Cc: "zsh-users@sunsite.dk" <zsh-users@sunsite.dk>
Subject: Re: Problem with _arguments
Date: Wed, 22 Nov 2006 22:31:25 +0100	[thread overview]
Message-ID: <dbfc82860611221331kfdb1ca9w4317fd401b05f718@mail.gmail.com> (raw)
In-Reply-To: <200611221039.kAMAdpal021905@news01.csr.com>

On 11/22/06, Peter Stephenson <pws@csr.com> wrote:

> > Actually, would there be a good way of tricking _arguments into only
> > seeing what you want it to see?  In this case, it would work fine if
> > one could trick it into only seeing the stuff after src, so that it
> > would continue completing options.
>
> There are certainly ways of updating the line, but the trouble is to
> find out what you need to do either you're going to be doing some
> parsing yourself or running _arguments twice.  You can edit words (the
> command line) and CURRENT (the index into it), plus it's also possible
> in some contexts to tell _arguments to limit the words visible in the
> completion that it's calling by the use of enough colons.  I find
> directly manipulating words and CURRENT less infuriating.

This worked out quite well actually.  Find is actually incredibly
complicated and has a rather horrible interface.  Anyway, here's my
solution:

    integer i
    (( i = index_of_find + 1 ))
    while [[ $words[i] == -([HLP]|-(help|version)) ]]; do
      (( i++ ))
    done
    while [[ -d $words[i] ]]; do
      (( i++ ))
    done
    words=($words[1,index_of_find] $words[i,-1])
    (( CURRENT -= i - index_of_find - 1 ))
    integer old_words_length
    (( old_words_length = $#words ))
    words=(${words:#\\[()\!]})
    (( CURRENT -= old_words_length - $#words ))

Index_of_find keeps track of the index of -find in the words array.
Here's the algorithm:

1.  The option -find can be followed by the options -H, -L, or -P to
specify how symbolic links are to be dealt with, along with -help or
-version, so skip those. [1]

2.  After that, any number of directories may follow. [2]

3.  Now we know what slice to remove from the words array and we do so.

4.  Next we need to remove any \!, any \(, and any \) that may appear
in the $words array, as these are used to negate and group expressions
and also mess up the command-line processing of _arguments. [3]

/Now/ we can call _arguments.

This can actually be used in _find as well, and I might submit a patch
once I'm done with this completion definition (for mkisofs if that was
unclear).

Super-happy-fun-thank-yous to Peter and Bart for your suggestions on
how to solve this.  Your answers are always helpful, insightful, and
to the point.  Seriously, you guys rock.  But it's also a bit sad that
you seem to be the only two that posses the necessary knowledge of Zsh
to answer these questions (and are active on these two mailing lists).
 I hope my shell-skills will reach your level some day.

  super-happy-fun-time-nikolai

[1]  Of course, if -help or -version is in the command line,
completion has ended already (they're defined as '(- *)-help...' and
'(- *)-version...'), so this is superfluous, but at least it's
complete.

[2]  Checking that they're directories is also a bit stupid, and
should perhaps only check that they don't match an option, for
example, [^-]*, but I figured this was a bit more expressive.

[3]  This could technically be limited to only the slice [i,-1], but I
wanted to keep things simple.


      parent reply	other threads:[~2006-11-22 21:31 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <now@bitwi.se>
2006-08-10 20:17 ` Completing a unique prefix of "script" completes "script" Nikolai Weibull
2006-08-10 21:41   ` Peter Stephenson
2006-08-13 14:49     ` Nikolai Weibull
2006-08-14 12:12       ` Peter Stephenson
2006-08-14 22:36         ` Nikolai Weibull
2006-08-13 14:59     ` Nikolai Weibull
2006-08-13 16:34       ` Peter Stephenson
2006-08-13 17:01         ` Nikolai Weibull
2006-11-21 22:57 ` Problem with _arguments Nikolai Weibull
2006-11-21 23:42   ` Peter Stephenson
2006-11-22  8:35     ` Nikolai Weibull
2006-11-22 10:39       ` Peter Stephenson
2006-11-22 15:55         ` Bart Schaefer
2006-11-22 22:22           ` Nikolai Weibull
2006-11-24 20:56             ` Bart Schaefer
2006-11-22 21:31         ` Nikolai Weibull [this message]

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=dbfc82860611221331kfdb1ca9w4317fd401b05f718@mail.gmail.com \
    --to=now@bitwi.se \
    --cc=pws@csr.com \
    --cc=zsh-users@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).