Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH 2/5] _hg: declare appropriate local parameters for ->string form
- X-seq: zsh-workers 43241
- From: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
- To: Anton Shestakov <av6@xxxxxxxxxxxx>
- Subject: Re: [PATCH 2/5] _hg: declare appropriate local parameters for ->string form
- Date: Mon, 6 Aug 2018 09:20:32 +0000
- Cc: zsh-workers@xxxxxxx
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= daniel.shahaf.name; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=yfu4ZRw/f+jjzrHEzDoeDlty5++9r /POIX9wM+qeakI=; b=dhxxD7z8vFERQLasQmpGLAWpKJVhZ6t0RpQtUHEtYD0Y5 qgGz/ka8GxcmRzi0KF0j41YzRn/bWX1hfzhWyYnZbLHWa4aRb/ciCJkYJOSsJweL Z5FaruoKx8iCh4ClHdKpTtXNSn/3+XRkynprisfieFTfOCOWsxZHOdeIqVWxgPPw Yz2f/Qh6+t5X/GvFNppycYZZCe/Y60FGpZqe8AWj5DxHvpf2XzZl6CeJzYjQz950 QNDm9SovtFIwbrB72F4k4I0POWDmuGWC0/HobEFA+X6zQfO5qdQYKjm7hSOJhH86 /Z0eXXJHsmvkUsTVy6fL5MyW5lzIN/MG2I6uZHcCw==
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; bh=yfu4ZRw/f+jjzrHEzDoeDlty5++9r /POIX9wM+qeakI=; b=C70T8P9wafnP9j9CXxhIpMkwTdkitS1kNmxSW7Lra0aSP Fo4Cjn8TYfA5AAVbCdkpANyJR1dKJyU3SPrqIV5n/iy0E3pnHbwCdFrmq9bERZx1 93sOvw76QymLSkWAZ3mN/p5uS+br4x4vQ9J4knZaFEywilmMwyA/oEQ5SmLiHetA x4Bzehn/hwyDAEGYZD+1R4OuXTng93wnUW3rB8PllX6meEdiKnzWqzBcq/D+6K2M V18zyKklTuv+rbveJ2Z23XLwQEf9HCDLjVxER3rhOERJ/RrK/ZMyofE+OaP2UzvH K0NxeXjEV5YzUmoo05fyiswn8v/OVpXOqXAYMhkhA==
- In-reply-to: <20180806072813.5051-3-av6@dwimlabs.net>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <20180806072813.5051-1-av6@dwimlabs.net> <20180806072813.5051-3-av6@dwimlabs.net>
Anton Shestakov wrote on Mon, Aug 06, 2018 at 15:28:10 +0800:
> && ret=0 is also needed (not sure why, the help page doesn't explain
> it), otherwise completing `hg diff -<TAB>` doesn't look right.
Completion functions are supposed to return 0 if they added at least one match
and non-zero otherwise. It's common for completion functions to have the
following form:
local ret=1
_foo && ret=0
return ret
(usually with some code before/after the call to _foo)
Simply adding '&&ret=0' without declaring 'ret' local is a bug: it sets the
variable in the caller's scope. Furthermore, if 'ret' were declared local,
setting it to 0 without using it afterwards would naturally have no effect.
I'm not sure what the correct fix is.
>
To -workers, couldn't we write a wrapper such as the following:
_added_matches_p() {
local nmatches=$compstate[nmatches]
"$@"
(( nmatches < $compstate[nmatches] ))
}
to reduce the need to manage $ret in every single layer of the callstack?
>
Cheers,
Daniel
> @@ -715,14 +717,14 @@ _hg_cmd_resolve() {
> }
>
> _hg_cmd_revert() {
> - local context state line
> + local context state state_descr line
> typeset -A opt_args
>
> _arguments -s : $_hg_global_opts $_hg_pat_opts $_hg_dryrun_opts \
> '(--all -a :)'{-a,--all}'[revert all changes when no arguments given]' \
> '(--rev -r)'{-r+,--rev=}'[revision to revert to]:revision:_hg_tags' \
> '--no-backup[do not save backup copies of files]' \
> - '*:file:->diff_files'
> + '*:file:->diff_files' && ret=0
>
> if [[ $state == 'diff_files' ]]
> then
Messages sorted by:
Reverse Date,
Date,
Thread,
Author