zsh-users
 help / color / mirror / code / Atom feed
From: Adam Szkoda <adaszko@gmail.com>
To: Oliver Kiddle <opk@zsh.org>
Cc: zsh-users@zsh.org
Subject: Re: _arguments '(-o --option)'[...] functionality without calling _arguments
Date: Wed, 13 Sep 2023 16:52:15 +0200	[thread overview]
Message-ID: <CAEroKagj+Ccrs1psLaH+CsGcpSFB77FDSGgUv_nBJ0h4DvG=Xg@mail.gmail.com> (raw)
In-Reply-To: <25398-1694605307.153980@4IDq.Y-bs.Rupp>

On Wed, Sep 13, 2023 at 1:41 PM Oliver Kiddle <opk@zsh.org> wrote:
> _describe does the same thing for words that are not options. It's
> implementation is in C code that is shared with that used by
> comparguments. It doesn't have to be done in C, however - compadd's
> interface would allow you to achieve the same thing from shell code if
> you wanted but that is more involved so check whether _describe meets
> your needs first.

Great, here's what I found out.  What works with _arguments:

cmd.zsh:
    _cmd () {
        _arguments '(-p --package)'{-p+,--package=}'[specify package
to build]:package:_cargo_package_names'
        return 0
    }
    compdef _cmd cmd

% source cmd.zsh
% cmd <TAB> # does what I want

With _describe, the same effect is achieved with:

cmd.zsh:
    _cmd () {
        local -a args=("-p" "--package")
        local -a descrs=("-p:specify package to build"
"-package:specify package to build")
        _describe '' descrs args
        return 0
    }
    compdef _cmd cmd


% source cmd.zsh
% cmd <TAB> # also does what I want

So it works (provided list-grouped zstyle is set to true but that's totally
fine). I'd be curious however to know how to get the same effect with plain
compadd.

> If you're looking at other completion functions for inspiration, I would
> recommend looking at those that come with zsh rather than those other
> projects include. Cargo's is fairly good but external projects often
> include completions that are auto-generated, converted from bash or
> otherwise less well written.

Thanks, that's good to know!

> Oliver
Thank you for taking a look at this, Oliver!
— Adam


  reply	other threads:[~2023-09-13 14:54 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-13  9:06 Adam Szkoda
2023-09-13 11:41 ` Oliver Kiddle
2023-09-13 14:52   ` Adam Szkoda [this message]
2023-09-14 11:14     ` Adam Szkoda

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='CAEroKagj+Ccrs1psLaH+CsGcpSFB77FDSGgUv_nBJ0h4DvG=Xg@mail.gmail.com' \
    --to=adaszko@gmail.com \
    --cc=opk@zsh.org \
    --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).