zsh-workers
 help / color / mirror / code / Atom feed
From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: Anton Shestakov <av6@dwimlabs.net>
Cc: zsh-workers@zsh.org
Subject: Re: [PATCH 2/5] _hg: declare appropriate local parameters for ->string form
Date: Mon, 6 Aug 2018 09:20:32 +0000	[thread overview]
Message-ID: <20180806092032.uizmxvlc2oku2ik6@tarpaulin.shahaf.local2> (raw)
In-Reply-To: <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


  reply	other threads:[~2018-08-06  9:20 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-06  7:28 [PATCH 0/5] An update for Completion/Unix/Command/_hg Anton Shestakov
2018-08-06  7:28 ` [PATCH 1/5] _hg: rename _hg_style_opts to _hg_template_opts Anton Shestakov
2018-08-06  7:28 ` [PATCH 2/5] _hg: declare appropriate local parameters for ->string form Anton Shestakov
2018-08-06  9:20   ` Daniel Shahaf [this message]
2018-08-06  9:29     ` Peter Stephenson
2018-08-06 11:09       ` Anton Shestakov
2018-08-06 11:14         ` Peter Stephenson
2018-08-06 12:04         ` Daniel Shahaf
2018-08-06 15:31           ` Anton Shestakov
2018-08-06 15:38             ` Peter Stephenson
2018-08-07  6:15               ` Anton Shestakov
2018-08-06 12:06       ` Daniel Shahaf
2018-08-06 14:00         ` Bart Schaefer
2018-08-06  7:28 ` [PATCH 3/5] _hg: add forget, phase, summary Anton Shestakov
2018-08-06  7:28 ` [PATCH 4/5] _hg: update all options Anton Shestakov
2018-08-06  7:28 ` [PATCH 5/5] _hg: drop -w, add -S to _arguments Anton Shestakov

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=20180806092032.uizmxvlc2oku2ik6@tarpaulin.shahaf.local2 \
    --to=d.s@daniel.shahaf.name \
    --cc=av6@dwimlabs.net \
    --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).