From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 2943 invoked from network); 2 Apr 2021 23:58:46 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 2 Apr 2021 23:58:46 -0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20200801; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Message-ID:Date: Content-Transfer-Encoding:Content-ID:Content-Type:MIME-Version:Subject:To: References:From:In-reply-to:Reply-To:Cc:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=v7W1KYU1j4jXE/OKyHMQJTSpKhuqzSXeBNH3zOk0o1I=; b=K18NJPjmWllzs5P51igB26L71C FrCEbRqaqo9LP0QZU0/fco+rtsYPmjLAcEaEfOymvCNAGYqMrT4jtuFFIYfTtgu2kiKLUyC0AiwXA FHBH5ieTM74SjphZr4ikl8gh4vZjf/leaGZTIrSszOy/ll15msC97WqJ6uFcPthELaQuFBriOUI0E ppDP6oNVWfH/2emhjzC6eviDBh0kzNkyjojK+Ee2ekQYiahraUMzo8FnKimQQH26Eefaz1ifNYIre 1eitoLoyAKJVU8JkyitXNI2bRMsafF/s4sZRGdCzuCfBLE1luXDQCXQ/fVt53rJrdk3F+yauZqlbx 2+Puopjw==; Received: from authenticated user by zero.zsh.org with local id 1lSTga-000Hm1-AC; Fri, 02 Apr 2021 23:58:44 +0000 Received: from authenticated user by zero.zsh.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1lSTgH-000HcZ-4G; Fri, 02 Apr 2021 23:58:25 +0000 Received: from [192.168.178.21] (helo=hydra) by mail.kiddle.eu with esmtp(Exim 4.93.0.4) (envelope-from ) id 1lSTgD-00048c-Rd for zsh-workers@zsh.org; Sat, 03 Apr 2021 01:58:23 +0200 In-reply-to: <20210401173305.GB11180@tarpaulin.shahaf.local2> From: Oliver Kiddle References: <20210401000026.23570-1-danielsh@tarpaulin.shahaf.local2> <96182-1617281582.024669@4LIl.h-KW.lXZv> <20210401173305.GB11180@tarpaulin.shahaf.local2> To: Zsh workers Subject: Re: [PATCH 1/2] __arguments: New completion function for _arguments. MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <15908.1617407901.1@hydra> Content-Transfer-Encoding: 8bit Date: Sat, 03 Apr 2021 01:58:21 +0200 Message-ID: <15909-1617407901.853986@YG9A.ovow.2A9B> X-Seq: 48378 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: Archived-At: Daniel Shahaf wrote: > > _compadd could define a pattern to complete compadd options for > > all commands named _*. I've attached a patch to do this. It is a post pattern and I don't have any real commands named with an initial _ on my system. Perhaps it should also call _default for non-option arguments? It also checks $service and handles a few functions specially. I couldn't be bothered to make this more extensive because, well, it is all a bit meta and of questionable value. And, no I don't think these need separating into __ functions. > > > + _arguments -A '-*' : \ > Hmm. How about «-A '-*|:|(!|)\(*'»? I'd have expected it to be the same as the pattern used at the top of _arguments - '-([AMO]*|[0CRSWnsw])' but that doesn't seem to work. I wonder if some bug means it only works with -* > > > + "-C[modify \$curcontext for \`->action' (requires \`local curcontext')]" \ > > > > This is instead of the $context array. > > Should only be used where multiple valid states is not a possibility. > > There isn't room to say all this inside the brackets. > > > I fear that the note in parentheses implies just `local curcontext' and > > not local curcontext="$curcontext" is needed. > > Good point. How about deleting the parenthetical? Or replacing it by > "(see manual)"? I'd remove it. There's room in the square brackets for one of the points. - "instead of $context". Descriptions are truncated if needed so less important information coming at the end doesn't do much harm. > > > > + "-R[when \`->action' matches, return 300]" \ > > > > I don't think that really gets used much [[ -n $state ]] is more > > readable. > > How does this affect the patch? Are you suggesting to hide (with «!») > this too? Not really, it was just an aside. Oliver diff --git a/Completion/Zsh/Command/_compadd b/Completion/Zsh/Command/_compadd index 781fa2af8..9c92cda76 100644 --- a/Completion/Zsh/Command/_compadd +++ b/Completion/Zsh/Command/_compadd @@ -1,47 +1,94 @@ -#compdef compadd +#compdef compadd -P _* -local curcontext="$curcontext" state line ret=1 +local curcontext="$curcontext" ret=1 +local -a state line args typeset -A opt_args -_arguments -C -s -S -A "-*" \ - '-P+[specify prefix]:prefix' \ - '-S+[specify suffix]:suffix' \ - '-p+[specify hidden prefix]:hidden prefix' \ - '-s+[specify hidden suffix]:hidden suffix' \ - '-i+[specify ignored prefix]:ignored prefix' \ - '-I+[specify ignored suffix]:ignored suffix' \ - '(-k)-a[matches are elements of specified arrays]' \ - '(-a)-k[matches are keys of specified associative arrays]' \ - '-d+[specify display strings]:array:_parameters -g "*array*"' \ - '-l[list display strings one per line, not in columns]' \ +args=( + '-P+[specify prefix]:prefix' + '-S+[specify suffix]:suffix' + '-p+[specify hidden prefix]:hidden prefix' + '-s+[specify hidden suffix]:hidden suffix' + '-i+[specify ignored prefix]:ignored prefix' + '-I+[specify ignored suffix]:ignored suffix' '-o[specify order for matches by match string not by display string]:: : _values -s , order "match[order by match not by display string]" "nosort[matches are pre-ordered]" "numeric[order numerically]" - "reverse[order backwards]"' \ - '(-1 -E)-J+[specify match group]:group' \ - '!-V+:group' \ - '(-J -E)-1[remove only consecutive duplicates from group]' \ - '-2[preserve all duplicates]' \ - '(-x)-X[specify explanation]:explanation' \ - '(-X)-x[specify unconditional explanation]:explanation' \ - '-q[make suffix autoremovable]' \ - '-r+[specify character class for suffix autoremoval]:character class' \ - '-R+[specify function for suffix autoremoval]:function:_functions' \ - '-f[mark matches as being files]' \ - '-e[mark matches as being parameters]' \ - '-W[specify location for matches marked as files]' \ - '-F+[specify array of ignore patterns]:array:_parameters -g "*array*"' \ - '-Q[disable quoting of possible completions]' \ - '*-M[specify matching specifications]' \ - '-n[hide matches in completion listing]' \ - '-U[disable internal matching of completion candidates]' \ - '-O+[populate array with matches instead of adding them]:array:_parameters -g "*array*"' \ - '-A+[populate array with expanded matches instead of adding them]:array:_parameters -g "*array*"' \ - '-D+[delete elements from array corresponding to non-matching candidates]:array:_parameters -g "*array*"' \ - '-C[add special match that expands to all other matches]' \ - '(-1 -J)-E+[add specified number of display only matches]:number' \ - '*:candidate:->candidates' && ret=0 + "reverse[order backwards]"' + '(-1 -E)-J+[specify match group]:group' + '!-V+:group' + '(-J -E)-1[remove only consecutive duplicates from group]' + '-2[preserve all duplicates]' + '(-x)-X[specify explanation]:explanation' + '(-X)-x[specify unconditional explanation]:explanation' + '-q[make suffix autoremovable]' + '-r+[specify character class for suffix autoremoval]:character class' + '-R+[specify function for suffix autoremoval]:function:_functions' + '-F+[specify array of ignore patterns]:array:_parameters -g "*array*"' + '-Q[disable quoting of possible completions]' + '*-M[specify matching specifications]' + '-n[hide matches in completion listing]' + '-O+[populate array with matches instead of adding them]:array:_parameters -g "*array*"' + '-A+[populate array with expanded matches instead of adding them]:array:_parameters -g "*array*"' + '-D+[delete elements from array corresponding to non-matching candidates]:array:_parameters -g "*array*"' +) + +case $service in + compadd|_(path_|)files) + args+=( + '-W[specify location for matches marked as files]' + ) + ;| + compadd) + args+=( + '(-k)-a[matches are elements of specified arrays]' + '(-a)-k[matches are keys of specified associative arrays]' + '-d+[specify display strings]:array:_parameters -g "*array*"' + '-l[list display strings one per line, not in columns]' + '-f[mark matches as being files]' + '-e[mark matches as being parameters]' + '-C[add special match that expands to all other matches]' + '(-1 -J)-E+[add specified number of display only matches]:number' + '-U[disable internal matching of completion candidates]' + '*:candidate:->candidates' + ) + ;; + _dates) + args=( ${args:#([(][^)]##\)|)-[12noOAD]*} + '-f[specify format for matches]:format:_date_formats' + '-F[select a future rather than past date]' + ) + ;; + _(path_|)files) + args=( ${args:#([(][^)]##\)|)-[OAD]*} + '-g+[specify file glob pattern]:glob pattern' + '-/[complete only directories]' + ) + ;; + _parameters) + args+=( + '-g+[specify pattern to filter parameter type by]:pattern' + ) + ;; + _pids) + args+=( '-m+[pattern to filter process command line by]:pattern' ) + ;; + _process_names) + args+=( + '-a[include all processes]' + '-t[use truncated process names]' + ) + ;; + _sys_calls) + args+=( + '-a[add "all" as an additional match]' + '-n[add "none" as an additional match]' + ) + ;; +esac + +_arguments -C -s -S -A "-*" $args && ret=0 if [[ -n $state ]]; then if (( $+opt_args[-a] )); then